Skip to content

Commit dd1a77e

Browse files
committed
Revert default behavior of cargo build
My PR #3213 carelessly changed the default behavior of cargo build. This commit restored the old behavior while still fixing cross-compilation. For this, instead of relying on the default target matching the compilation host, we instead explicitly read the host target from the HOST variable that cargo sets for build scripts. Signed-off-by: Patrick Roy <[email protected]>
1 parent 9ba0862 commit dd1a77e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[build]
22
target-dir = "build/cargo_target"
3+
target = "x86_64-unknown-linux-musl"
34

45
[net]
56
git-fetch-with-cli = true

src/vmm/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ fn main() {
5151

5252
// Run seccompiler with the given arguments.
5353
fn run_seccompiler_bin(json_path: &str, out_path: &str) {
54+
// We have a global `target` directive in our .cargo/config file specifying x86_64 architecture.
55+
// However, seccompiler-bin has to be compiled for the host architecture. Without this, cargo
56+
// would produce a x86_64 binary on aarch64 host, causing this compilation step to fail as such
57+
// a binary would not be executable.
58+
let host_arch = env::var("HOST").expect("Could not determine compilation host");
5459
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Missing target arch.");
5560

5661
// Command for running seccompiler-bin
@@ -60,6 +65,8 @@ fn run_seccompiler_bin(json_path: &str, out_path: &str) {
6065
"-p",
6166
"seccompiler",
6267
"--verbose",
68+
"--target",
69+
&host_arch,
6370
// We need to specify a separate build directory for seccompiler-bin. Otherwise, cargo will
6471
// deadlock waiting to acquire a lock on the build folder that the parent cargo process is
6572
// holding.

0 commit comments

Comments
 (0)