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..3d2e049 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ OS = $(shell uname -s) KRUNKIT_RELEASE = target/release/krunkit KRUNKIT_DEBUG = target/debug/krunkit +LIBKRUN = libkrun.1.dylib -ifeq ($(PREFIX),) - PREFIX := /usr/local -endif +PREFIX ?= /usr/local +export PREFIX .PHONY: install clean $(KRUNKIT_RELEASE) $(KRUNKIT_DEBUG) @@ -15,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 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..73247a9 100644 --- a/build.rs +++ b/build.rs @@ -3,9 +3,12 @@ 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"); + + println!("cargo:rerun-if-env-changed=PREFIX"); } }