-
Notifications
You must be signed in to change notification settings - Fork 159
Add GitHub workflow for cross-compilation and fix build issues for macOS and FreeBSD #636
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
base: main
Are you sure you want to change the base?
Changes from all commits
4f8adc4
39e063a
9e9c626
15c0c08
45659e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [target.aarch64-apple-darwin] | ||
| runner = ".cargo/macos-test-runner.sh" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/sh | ||
| # Cargo target runner for macOS (aarch64-apple-darwin). | ||
| # Codesigns the test/run binary with the Hypervisor.framework entitlement | ||
| # before executing it, so that HVF-based tests can run without a developer | ||
| # certificate. | ||
|
mtjhrc marked this conversation as resolved.
|
||
| set -eu | ||
|
|
||
| BINARY="$1" | ||
| shift | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| codesign --entitlements "$REPO_ROOT/hvf-entitlements.plist" --force -s - "$BINARY" | ||
| exec "$BINARY" "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Cross-compilation | ||
| on: [pull_request] | ||
|
|
||
| jobs: | ||
| cross-compile-macos: | ||
| name: Cross-compilation (macOS) | ||
| runs-on: macos-latest | ||
| env: | ||
| DYLD_LIBRARY_PATH: /Library/Developer/CommandLineTools/usr/lib/ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @slp I had issues building the macOS version which looked like this: Setting |
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup build environment | ||
| uses: ./.github/actions/setup-build-env | ||
|
|
||
| - name: Install cross-compilation dependencies | ||
| run: | | ||
| brew install lld xz | ||
|
|
||
| - name: Build libkrun on macOS (with Linux init) | ||
| run: make | ||
|
|
||
| - name: Build FreeBSD init on macOS | ||
| run: make BUILD_BSD_INIT=1 -- init/init-freebsd | ||
|
|
||
| cross-compile-linux: | ||
| name: Cross-compilation (Linux x86_64 -> FreeBSD) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup build environment | ||
| uses: ./.github/actions/setup-build-env | ||
|
|
||
| - name: Install cross-compilation dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y --no-install-recommends lld | ||
|
|
||
| - name: Build FreeBSD init on Linux | ||
| run: make BUILD_BSD_INIT=1 -- init/init-freebsd | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ AWS_NITRO_INIT_SRC = \ | |
|
|
||
| AWS_NITRO_INIT_LD_FLAGS = -larchive -lnsm | ||
|
|
||
| INIT_SRC = init/init.c | ||
|
|
||
| ifeq ($(SEV),1) | ||
| VARIANT = -sev | ||
| FEATURE_FLAGS := --features amd-sev | ||
|
|
@@ -120,7 +122,7 @@ $(AWS_NITRO_INIT_BINARY): $(AWS_NITRO_INIT_SRC) | |
| $(CC) -O2 -static -s -Wall $(AWS_NITRO_INIT_LD_FLAGS) -o $@ $(AWS_NITRO_INIT_SRC) $(AWS_NITRO_INIT_LD_FLAGS) | ||
|
|
||
| ifeq ($(OS),Darwin) | ||
| # If SYSROOT_BSD is not set and we're on macOS, generate sysroot automatically | ||
| # macOS -> FreeBSD cross-compilation | ||
| ifeq ($(SYSROOT_BSD),) | ||
| SYSROOT_BSD = $(FREEBSD_ROOTFS_DIR) | ||
| SYSROOT_BSD_TARGET = $(FREEBSD_ROOTFS_DIR)/.sysroot_ready | ||
|
|
@@ -129,6 +131,16 @@ else | |
| endif | ||
| # Cross-compile on macOS with the LLVM linker (brew install lld) | ||
| CC_BSD=$(CLANG) -target $(ARCH)-unknown-freebsd -fuse-ld=lld -stdlib=libc++ -Wl,-strip-debug --sysroot $(SYSROOT_BSD) | ||
| else ifeq ($(OS),Linux) | ||
| # Linux -> FreeBSD cross-compilation | ||
| ifeq ($(SYSROOT_BSD),) | ||
| SYSROOT_BSD = $(FREEBSD_ROOTFS_DIR) | ||
| SYSROOT_BSD_TARGET = $(FREEBSD_ROOTFS_DIR)/.sysroot_ready | ||
| else | ||
| SYSROOT_BSD_TARGET = | ||
| endif | ||
| # Cross-compile on Linux with clang | ||
| CC_BSD=$(CLANG) -target $(ARCH)-unknown-freebsd -fuse-ld=lld -Wl,-strip-debug --sysroot $(SYSROOT_BSD) | ||
| else | ||
| # Build on FreeBSD host | ||
| CC_BSD=$(CC) | ||
|
|
@@ -138,7 +150,7 @@ endif | |
| ifeq ($(BUILD_BSD_INIT),1) | ||
| INIT_BINARY_BSD = init/init-freebsd | ||
| $(INIT_BINARY_BSD): $(INIT_SRC) $(SYSROOT_BSD_TARGET) | ||
| $(CC_BSD) -std=c23 -O2 -static -Wall $(INIT_DEFS) -lutil -o $@ $(INIT_SRC) $(INIT_DEFS) | ||
| $(CC_BSD) -std=c23 -O2 -static -Wall -lutil -o $@ $(INIT_SRC) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| endif | ||
|
|
||
| # Sysroot preparation rules for cross-compilation on macOS | ||
|
|
@@ -179,10 +191,12 @@ $(FREEBSD_ROOTFS_DIR)/.sysroot_ready: $(FREEBSD_BASE_TXZ) | |
| @cd $(FREEBSD_ROOTFS_DIR) && tar xJf base.txz 2>/dev/null || true | ||
| @touch $@ | ||
|
|
||
| BSD_ARCH=$(subst x86_64,amd64,$(ARCH)) | ||
|
|
||
| $(FREEBSD_BASE_TXZ): | ||
| @echo "Downloading FreeBSD $(FREEBSD_VERSION) base for $(ARCH)..." | ||
| @echo "Downloading FreeBSD $(FREEBSD_VERSION) base for $(BSD_ARCH)..." | ||
| @mkdir -p $(FREEBSD_ROOTFS_DIR) | ||
| @curl -fL -o $@ https://download.freebsd.org/releases/$(ARCH)/$(FREEBSD_VERSION)/base.txz | ||
| @curl -fL -o $@ https://download.freebsd.org/releases/$(BSD_ARCH)/$(FREEBSD_VERSION)/base.txz | ||
|
|
||
| clean-sysroot: | ||
| rm -rf $(ROOTFS_DIR) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>com.apple.security.hypervisor</key> | ||
| <true/> | ||
| </dict> | ||
| </plist> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,8 @@ fn main() { | |
| println!("cargo:rustc-env=KRUN_EDK2_BINARY_PATH={edk2_binary_path}"); | ||
| println!("cargo:rerun-if-env-changed=KRUN_EDK2_BINARY_PATH"); | ||
| } | ||
|
|
||
| if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") { | ||
| println!("cargo:rustc-link-lib=framework=Hypervisor"); | ||
| } | ||
|
Comment on lines
+13
to
+15
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I will test this. I had the linker error when trying to run cargo test on the vmm crate so you're probably right.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still works after removing from libkrun crate. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
runnerconfiguration lets me run unit tests from VS Code editor.