From 05c4eb74ac1a0dd08819f111e738980d37f33db0 Mon Sep 17 00:00:00 2001 From: Jan Noha Date: Sat, 13 Jun 2026 21:55:10 +0200 Subject: [PATCH] init_blob: fix build from crates.io by making the crate self-contained When importing libkrun from crates.io, each crate is compiled separately in a way that relative paths within the git repository but pointing outside the crate root are not valid. Fixes: #727 Signed-off-by: Jan Noha --- Makefile | 2 +- README.md | 8 ++++---- src/init_blob/build.rs | 12 ++++++------ {init => src/init_blob/init}/dhcp.c | 0 {init => src/init_blob/init}/dhcp.h | 0 {init => src/init_blob/init}/init.c | 0 {init => src/init_blob/init}/jsmn.h | 0 7 files changed, 11 insertions(+), 11 deletions(-) rename {init => src/init_blob/init}/dhcp.c (100%) rename {init => src/init_blob/init}/dhcp.h (100%) rename {init => src/init_blob/init}/init.c (100%) rename {init => src/init_blob/init}/jsmn.h (100%) diff --git a/Makefile b/Makefile index e5333fd..afef6d2 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ AWS_NITRO_INIT_SRC = \ AWS_NITRO_INIT_LD_FLAGS = -larchive -lnsm -INIT_SRC = init/init.c +INIT_SRC = src/init_blob/init/init.c ifeq ($(SEV),1) VARIANT = -sev diff --git a/README.md b/README.md index d7e065f..085bb35 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ When TSI is enabled, the VMM acts as a proxy for AF_INET, AF_INET6 and AF_UNIX s * [libkrunfw](https://github.com/containers/libkrunfw) * A working [Rust](https://www.rust-lang.org/) toolchain -* C Library static libraries, as the [init](init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) +* C Library static libraries, as the [init](src/init_blob/init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) * patchelf #### Optional features @@ -140,7 +140,7 @@ sudo make [FEATURE_OPTIONS] install * The SEV variant of [libkrunfw](https://github.com/containers/libkrunfw), which provides a ```libkrunfw-sev.so``` library. * A working [Rust](https://www.rust-lang.org/) toolchain -* C Library static libraries, as the [init](init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) +* C Library static libraries, as the [init](src/init_blob/init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) * patchelf * OpenSSL headers and libraries (package ```openssl-devel``` in Fedora). @@ -162,7 +162,7 @@ sudo make SEV=1 install * The TDX variant of [libkrunfw](https://github.com/containers/libkrunfw), which provides a ```libkrunfw-tdx.so``` library. * A working [Rust](https://www.rust-lang.org/) toolchain -* C Library static libraries, as the [init](init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) +* C Library static libraries, as the [init](src/init_blob/init/init.c) binary is statically linked (package ```glibc-static``` in Fedora) * patchelf * OpenSSL headers and libraries (package ```openssl-devel``` in Fedora). @@ -216,7 +216,7 @@ sudo make EFI=1 install make [FEATURE_OPTIONS] ``` -The [init](init/init.c) binary is cross-compiled using clang and lld. +The [init](src/init_blob/init/init.c) binary is cross-compiled using clang and lld. A suitable sysroot is automatically generated by the Makefile from Debian repository. #### Installing diff --git a/src/init_blob/build.rs b/src/init_blob/build.rs index 49a4346..abb4694 100644 --- a/src/init_blob/build.rs +++ b/src/init_blob/build.rs @@ -4,9 +4,9 @@ use std::process::Command; fn build_default_init() -> PathBuf { let manifest_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); - let libkrun_root = manifest_dir.join("../.."); - let init_src = libkrun_root.join("init/init.c"); - let dhcp_src = libkrun_root.join("init/dhcp.c"); + let init_dir = manifest_dir.join("init"); + let init_src = init_dir.join("init.c"); + let dhcp_src = init_dir.join("dhcp.c"); let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); let init_bin = out_dir.join("init"); @@ -18,11 +18,11 @@ fn build_default_init() -> PathBuf { println!("cargo:rerun-if-changed={}", dhcp_src.display()); println!( "cargo:rerun-if-changed={}", - libkrun_root.join("init/jsmn.h").display() + init_dir.join("jsmn.h").display() ); println!( "cargo:rerun-if-changed={}", - libkrun_root.join("init/dhcp.h").display() + init_dir.join("dhcp.h").display() ); let mut init_cc_flags = vec!["-O2", "-static", "-Wall"]; @@ -46,7 +46,7 @@ fn build_default_init() -> PathBuf { .unwrap_or_else(|e| panic!("failed to execute {cc}: {e}")); if !status.success() { - panic!("failed to compile init/init.c: {status}"); + panic!("failed to compile {}: {status}", init_src.display()); } init_bin } diff --git a/init/dhcp.c b/src/init_blob/init/dhcp.c similarity index 100% rename from init/dhcp.c rename to src/init_blob/init/dhcp.c diff --git a/init/dhcp.h b/src/init_blob/init/dhcp.h similarity index 100% rename from init/dhcp.h rename to src/init_blob/init/dhcp.h diff --git a/init/init.c b/src/init_blob/init/init.c similarity index 100% rename from init/init.c rename to src/init_blob/init/init.c diff --git a/init/jsmn.h b/src/init_blob/init/jsmn.h similarity index 100% rename from init/jsmn.h rename to src/init_blob/init/jsmn.h -- 2.51.2