Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: add native build support for arm64 MacOS #2258

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

f1ko
Copy link
Contributor

@f1ko f1ko commented Mar 25, 2024

On MacOS uname -m returns arm64 whereas on Linux it returns aarch64.

Fixes #2257

On MacOS `uname -m` returns `arm64` whereas on Linux it returns `aarch64`.

Fixes cilium#2257

Signed-off-by: Filip Nikolic <oss.filipn@gmail.com>
@f1ko f1ko requested a review from a team as a code owner March 25, 2024 17:04
@f1ko f1ko requested a review from kevsecurity March 25, 2024 17:04
Copy link

netlify bot commented Mar 25, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit dd06d8a
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/6601ae92f90bf500080725e9
😎 Deploy Preview https://deploy-preview-2258--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mtardy
Copy link
Member

mtardy commented Mar 25, 2024

hey, I see that but I don't think you can build tetragon on macOS (because some pkg don't build on darwin) and we want to do that? Are you trying to cross build Linux Tetragon on macOS? If yes why don't you build on Linux directly?

@f1ko
Copy link
Contributor Author

f1ko commented Mar 25, 2024

Essentially what is happening is that the Makefile is being evaluated on MacOS but the build itself can then happen elsewhere.
That is, for example, the case when using the make images target.
A Linux machine is required for using docker, so the actual build is happening on Linux anyways.
However, the target platform is being evaluated beforehand already while being on MacOS as make images is "natively" executed on the host.
By not being able to evaluate the target correctly on MacOS it falls back to creating an amd64 image which is later on not usable in kind running on the same arm64 machine.

Now an alternative may be to do everything on Linux immediately so that the target is rightfully evaluated when executing make images, however, it is a pain to do this setup for every repository that comes along.
For people working with the same small number of repositories all the time this is a one-time configuration that doesn't take too much effort to setup and doesn't need a lot of maintenance.
However, for someone that is constantly working with new repositories this is a pain to setup and to maintain in case of full disaster recovery automation.
One has to have enough space on the Linux VM, need to synchronise files back and forth between MacOS or maintain mounts, etc.

Therefore a common pattern on MacOS is to have a local lightweight Linux VM and exposing the docker socket to MacOS host so that one can "natively" use docker commands on MacOS.
Doing so results in a one-time setup that scales well regardless of projects that are being worked on and is therefore easier to automate and backup as well.

The proposed change does not break anything for existing users.
All it does is add support for a common workflow for MacOS development.

Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep okay why not! I'm thinking by the way that it would be a good change to write it with if/else statements:

ifeq ($(UNAME_M),x86_64)
	TARGET_ARCH ?= amd64
else ifeq ($(UNAME_M),aarch64)
	TARGET_ARCH ?= arm64
else ifeq ($(UNAME_M),arm64)
	TARGET_ARCH ?= arm64
else
	TARGET_ARCH ?= amd64
endif

@mtardy mtardy added the release-note/misc This PR makes changes that have no direct user impact. label Mar 25, 2024
@mtardy
Copy link
Member

mtardy commented Apr 2, 2024

If that can help you, let's merge this!

@mtardy mtardy merged commit c104f63 into cilium:main Apr 2, 2024
34 of 36 checks passed
@f1ko f1ko deleted the pr/macos-arm64 branch April 8, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Local built image does not work as expected on MacOS arm64
2 participants