From ef74acf431859c9115e4e2c789252135ccc27fd5 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 21 Feb 2026 04:00:13 +0200 Subject: [PATCH 1/3] Use PREFIX for library search path Replace the ad-hoc LIBKRUN_EFI environment variable with the standard PREFIX, aligning build.rs with the Makefile default (/usr/local). Homebrew and MacPorts builds set PREFIX explicitly. Before this change, the Makefile defaulted to /usr/local while build.rs defaulted to /opt/homebrew/lib, so builds without an explicit PREFIX could link against a different library than expected. Co-authored-by: Cursor Signed-off-by: Nir Soffer --- .github/workflows/unit_tests-aarch64-darwin.yaml | 2 ++ Makefile | 5 ++--- README.md | 15 ++++++++++----- build.rs | 9 +++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/unit_tests-aarch64-darwin.yaml b/.github/workflows/unit_tests-aarch64-darwin.yaml index 892292c..4f37359 100644 --- a/.github/workflows/unit_tests-aarch64-darwin.yaml +++ b/.github/workflows/unit_tests-aarch64-darwin.yaml @@ -6,6 +6,8 @@ jobs: if: github.event_name == 'pull_request' name: Build & Test runs-on: macos-latest + env: + PREFIX: /opt/homebrew steps: - name: Code checkout uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index 6bcd65d..95928bd 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,8 @@ OS = $(shell uname -s) KRUNKIT_RELEASE = target/release/krunkit KRUNKIT_DEBUG = target/debug/krunkit -ifeq ($(PREFIX),) - PREFIX := /usr/local -endif +PREFIX ?= /usr/local +export PREFIX .PHONY: install clean $(KRUNKIT_RELEASE) $(KRUNKIT_DEBUG) diff --git a/README.md b/README.md index 002c072..4b3a36d 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,18 @@ $ brew install krunkit As noted above, `krunkit` relies on the `efi` flavor of `libkrun`. Ensure that is installed on your system. +Build and install using default `PREFIX` (`/usr/local`): + +``` +make +sudo make install ``` -# If libkrun-efi.dylib is not located at /opt/homebrew/opt/libkrun-efi/lib/ -# provide the path at which it's located using the LIBKRUN_EFI variable. Otherwise, -# the Makefile will default to using the /opt/homebrew/... path. -$ make LIBKRUN_EFI= -$ sudo make install +To build with `libkrun-efi` from *Homebrew* or *MacPorts* use the appropriate `PREFIX`: + +``` +make PREFIX=/opt/homebrew +sudo make install PREFIX=/opt/homebrew ``` ## Usage diff --git a/build.rs b/build.rs index 82f5b90..d8a5888 100644 --- a/build.rs +++ b/build.rs @@ -3,9 +3,10 @@ fn main() { #[cfg(target_os = "macos")] { - match std::env::var_os("LIBKRUN_EFI") { - Some(path) => println!("cargo:rustc-link-search={}", path.into_string().unwrap()), - None => println!("cargo:rustc-link-search=/opt/homebrew/lib"), - } + // Must match the default PREFIX in the Makefile. + const DEFAULT_PREFIX: &str = "/usr/local"; + + let prefix = std::env::var("PREFIX").unwrap_or(DEFAULT_PREFIX.to_string()); + println!("cargo:rustc-link-search={prefix}/lib"); } } From d8b08784ab9f5727a312bd9ef2fc5151ffd44d72 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 21 Feb 2026 04:05:11 +0200 Subject: [PATCH 2/3] Fix libkrun runtime library path Use install_name_tool to set the full library path for libkrun, so the binary finds it at PREFIX/lib at runtime. Before this change the install name was `libkrun.1.dylib` and the library was not found during runtime: % otool -L target/release/krunkit % target/release/krunkit -h % make ... codesign --entitlements krunkit.entitlements --force -s - target/release/krunkit target/release/krunkit: replacing existing signature % otool -L target/release/krunkit target/release/krunkit: libkrun.1.dylib (compatibility version 1.0.0, current version 1.17.0) ... % target/release/krunkit -h dyld[5927]: Library not loaded: libkrun.1.dylib Referenced from: <3FF89D22-C5F2-3D78-AC12-1339959A0EC5> /Users/nir/src/krunkit/target/release/krunkit Reason: tried: 'libkrun.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibkrun.1.dylib' (no such file), 'libkrun.1.dylib' (no such file), '/Users/nir/src/krunkit/libkrun.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/nir/src/krunkit/libkrun.1.dylib' (no such file), '/Users/nir/src/krunkit/libkrun.1.dylib' (no such file) zsh: abort target/release/krunkit -h Co-authored-by: Cursor Signed-off-by: Nir Soffer --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 95928bd..3d2e049 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ OS = $(shell uname -s) KRUNKIT_RELEASE = target/release/krunkit KRUNKIT_DEBUG = target/debug/krunkit +LIBKRUN = libkrun.1.dylib PREFIX ?= /usr/local export PREFIX @@ -14,6 +15,7 @@ debug: $(KRUNKIT_DEBUG) $(KRUNKIT_RELEASE): cargo build --release ifeq ($(OS),Darwin) + install_name_tool -change $(LIBKRUN) $(PREFIX)/lib/$(LIBKRUN) $@ codesign --entitlements krunkit.entitlements --force -s - $@ endif From 5067d58c1a8ec31b05897a2ee92683e29295273e Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 21 Feb 2026 04:08:34 +0200 Subject: [PATCH 3/3] Rebuild when PREFIX changes Without rerun-if-env-changed, cargo may serve a cached build when PREFIX changes, linking against the wrong library path. Co-authored-by: Cursor Signed-off-by: Nir Soffer --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index d8a5888..73247a9 100644 --- a/build.rs +++ b/build.rs @@ -8,5 +8,7 @@ fn main() { let prefix = std::env::var("PREFIX").unwrap_or(DEFAULT_PREFIX.to_string()); println!("cargo:rustc-link-search={prefix}/lib"); + + println!("cargo:rerun-if-env-changed=PREFIX"); } }