Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/setup-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ runs:
rustup update stable
rustup default stable
rustup component add rustfmt clippy
rustup target add x86_64-unknown-freebsd
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
- name: Cache Cargo dependencies
uses: actions/cache@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cross-compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install cross-compilation dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends lld
sudo apt-get install -y --no-install-recommends clang lld

- name: Build FreeBSD init on Linux
run: make BUILD_BSD_INIT=1 -- init/init-freebsd
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Install cross-compilation dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends lld
sudo apt-get install -y --no-install-recommends clang lld

- name: Build FreeBSD init on Linux aarch64
run: make BUILD_BSD_INIT=1 -- init/init-freebsd
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"init",
"src/libkrun",
"src/input",
"src/display",
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ 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
Expand Down Expand Up @@ -130,6 +128,7 @@ 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)
CARGO_BSD_RUSTFLAGS = -C linker=$(CLANG) -C link-arg=-target -C link-arg=$(ARCH)-unknown-freebsd -C link-arg=-fuse-ld=lld -C link-arg=-stdlib=libc++ -C link-arg=--sysroot=$(abspath $(SYSROOT_BSD))
else ifeq ($(OS),Linux)
# Linux -> FreeBSD cross-compilation
ifeq ($(SYSROOT_BSD),)
Expand All @@ -140,16 +139,34 @@ else
endif
# Cross-compile on Linux with clang
CC_BSD=$(CLANG) -target $(ARCH)-unknown-freebsd -fuse-ld=lld -Wl,-strip-debug --sysroot $(SYSROOT_BSD)
CARGO_BSD_RUSTFLAGS = -C linker=$(CLANG) -C link-arg=-target -C link-arg=$(ARCH)-unknown-freebsd -C link-arg=-fuse-ld=lld -C link-arg=--sysroot=$(abspath $(SYSROOT_BSD))
else
# Build on FreeBSD host
CC_BSD=$(CC)
SYSROOT_BSD_TARGET =
CARGO_BSD_RUSTFLAGS =
endif

FREEBSD_RUST_TARGET = $(subst arm64,aarch64,$(ARCH))-unknown-freebsd

# aarch64-unknown-freebsd is Tier 3: no prebuilt std, requires nightly + build-std.
ifeq ($(FREEBSD_RUST_TARGET),aarch64-unknown-freebsd)
CARGO_BSD_TOOLCHAIN = +nightly
CARGO_BSD_EXTRA_FLAGS = -Z build-std
else
CARGO_BSD_TOOLCHAIN =
CARGO_BSD_EXTRA_FLAGS =
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 -o $@ $(INIT_SRC) -lutil
$(INIT_BINARY_BSD): $(shell find init/src -name '*.rs') init/Cargo.toml $(SYSROOT_BSD_TARGET)
RUSTFLAGS="$(CARGO_BSD_RUSTFLAGS)" \
cargo $(CARGO_BSD_TOOLCHAIN) build --release \
$(CARGO_BSD_EXTRA_FLAGS) \
--manifest-path init/Cargo.toml \
--target $(FREEBSD_RUST_TARGET)
cp target/$(FREEBSD_RUST_TARGET)/release/krun-init $@
endif

# Sysroot preparation rules for cross-compilation on macOS
Expand Down
23 changes: 23 additions & 0 deletions init/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "krun-init"
version = "0.1.0-1.18.0"
edition = "2021"
description = "PID-1 init binary for libkrun guest VMs"
license = "Apache-2.0"
repository = "https://github.com/containers/libkrun"

[[bin]]
name = "krun-init"
path = "src/main.rs"

[features]
amd-sev = []
tdx = []
timesync = []

[dependencies]
anyhow = "1"
libc = "0.2"
nix = { version = "0.30", features = ["fs", "hostname", "ioctl", "mount", "process", "reboot", "resource", "signal", "socket", "term", "uio"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Loading
Loading