Skip to content

Commit 436d321

Browse files
committed
build: consolidate NBD server build, move binary out of source tree
- Replace nbd-server-aarch64/nbd-server-x86_64 with single nbd-server target, auto-detecting host arch via rustc host triple. No-op on Linux (ifneq Linux) so macOS and future Windows both cross-compile. - Output to target/nbd-server/ instead of source tree; build.rs copies into OUT_DIR for include_bytes! - Justfile build: make nbd-server + make bin - macOS CI simplified to just build Assisted-by: Antigravity (Claude Opus 4.6) Signed-off-by: Shion Tanaka <shtanaka@redhat.com>
1 parent 4bc9624 commit 436d321

5 files changed

Lines changed: 37 additions & 22 deletions

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
with:
2929
targets: aarch64-unknown-linux-gnu
3030

31-
- name: Install zig and cargo-zigbuild
31+
- name: Install zig, cargo-zigbuild, and just
3232
run: |
33-
brew install zig
33+
brew install zig just
3434
cargo install cargo-zigbuild
3535
36-
- name: Build NBD server binary
37-
run: make nbd-server-aarch64
36+
- name: Build
37+
run: just build
3838

39-
- name: Check build
39+
- name: Check all targets
4040
run: cargo check --all-targets
4141

4242
- name: Run unit tests

Justfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ PRIMARY_IMAGE := "quay.io/centos-bootc/centos-bootc:stream10"
33
# <https://github.com/bootc-dev/bcvk/issues/153>
44
ALL_BASE_IMAGES := "quay.io/fedora/fedora-bootc:43 quay.io/fedora/fedora-bootc:44 quay.io/centos-bootc/centos-bootc:stream9 quay.io/centos-bootc/centos-bootc:stream10 quay.io/almalinuxorg/almalinux-bootc:10.0"
55

6-
# Build the native binary
6+
# Build the native binary (cross-compiles NBD server on non-Linux hosts)
77
build:
8-
make
8+
make nbd-server
9+
make bin
910

1011
# Static checks
1112
validate:

Makefile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ all: bin manpages
88

99
.PHONY: bin
1010
bin:
11-
cargo check --workspace
1211
cargo build --release
1312

1413
# Generate man pages from markdown sources
@@ -67,18 +66,17 @@ update-manpages:
6766

6867
update-generated: sync-manpages manpages
6968

70-
.PHONY: all bin install manpages update-generated makesudoinstall sync-manpages update-manpages sync-cli-options nbd-server-aarch64 nbd-server-x86_64
69+
.PHONY: all bin install manpages update-generated makesudoinstall sync-manpages update-manpages sync-cli-options nbd-server
7170

72-
.PHONY: nbd-server-aarch64
73-
nbd-server-aarch64:
74-
PATH="$(HOME)/.rustup/toolchains/stable-$(shell rustc -vV | awk '/^host:/ {print $$2}')/bin:$(HOME)/.cargo/bin:$(PATH)" \
75-
cargo zigbuild --target aarch64-unknown-linux-gnu --release -p bcvk-nbd
76-
cp target/aarch64-unknown-linux-gnu/release/bcvk-nbd \
77-
crates/kit/bcvk-nbd-aarch64
71+
# Cross-compile NBD server for podman machine (needed on macOS/Windows, no-op on Linux)
72+
NBD_ARCH := $(shell rustc -vV | awk '/^host:/ {split($$2, a, "-"); print a[1]}')
73+
NBD_TARGET := $(NBD_ARCH)-unknown-linux-gnu
7874

79-
.PHONY: nbd-server-x86_64
80-
nbd-server-x86_64:
75+
.PHONY: nbd-server
76+
nbd-server:
77+
ifneq ($(shell uname -s),Linux)
8178
PATH="$(HOME)/.rustup/toolchains/stable-$(shell rustc -vV | awk '/^host:/ {print $$2}')/bin:$(HOME)/.cargo/bin:$(PATH)" \
82-
cargo zigbuild --target x86_64-unknown-linux-gnu --release -p bcvk-nbd
83-
cp target/x86_64-unknown-linux-gnu/release/bcvk-nbd \
84-
crates/kit/bcvk-nbd-x86_64
79+
cargo zigbuild --target $(NBD_TARGET) --release -p bcvk-nbd
80+
mkdir -p target/nbd-server
81+
cp target/$(NBD_TARGET)/release/bcvk-nbd target/nbd-server/bcvk-nbd
82+
endif

crates/kit/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Build script: copy cross-compiled NBD server binary into OUT_DIR for include_bytes!.
2+
3+
fn main() {
4+
// NBD server binary is needed on non-Linux hosts (macOS/Windows) where
5+
// bcvk cross-compiles it for the podman machine. On Linux, the file
6+
// won't exist and that's OK — nbd_macos.rs is cfg-gated.
7+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
8+
let workspace_root = std::path::Path::new(&manifest_dir).join("../..");
9+
let nbd_src = workspace_root.join("target/nbd-server/bcvk-nbd");
10+
println!("cargo:rerun-if-changed={}", nbd_src.display());
11+
if nbd_src.exists() {
12+
let out_dir = std::env::var("OUT_DIR").unwrap();
13+
let dest = std::path::Path::new(&out_dir).join("bcvk-nbd");
14+
std::fs::copy(&nbd_src, &dest).expect("failed to copy bcvk-nbd to OUT_DIR");
15+
}
16+
}

crates/kit/src/nbd_macos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use tracing::info;
1111
use crate::utils::wait_for_readiness;
1212
use crate::vm_helpers;
1313

14-
/// NBD server binary (aarch64 ELF), embedded at compile time.
15-
const NBD_SERVER: &[u8] = include_bytes!("../bcvk-nbd-aarch64");
14+
/// NBD server binary (Linux ELF for host arch), embedded at compile time.
15+
const NBD_SERVER: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/bcvk-nbd"));
1616

1717
/// Deploy the NBD server binary to the podman machine.
1818
pub(crate) fn deploy_nbd_server(machine: &str) -> Result<()> {

0 commit comments

Comments
 (0)