Skip to content

Commit c590134

Browse files
committed
test(ffi): build the cdylib in c_smoke instead of linking a stale one
The C smoke test linked whatever libsandlock_ffi.so already existed in target/, but Cargo does not treat the cdylib as a build prerequisite of an integration test (tests link the rlib). So `cargo test` never (re)builds the .so, and CI linked a stale artifact missing newer symbols (undefined reference to sandlock_action_set_inject_bytes). Build the cdylib from within the test via `cargo build -p sandlock-ffi --lib` before locating and linking it, so the C test always links the current artifact. The recursive cargo invocation is safe — the outer build lock is released before tests run. Verified by deleting the .so and re-running: the test rebuilds it and passes. Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 05958fd commit c590134

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

crates/sandlock-ffi/tests/c_smoke.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ fn c_smoke_compiles_and_runs() {
1212
} else {
1313
"release"
1414
};
15+
16+
// Cargo links integration tests against the crate's *rlib*, and does not
17+
// treat the *cdylib* as a build prerequisite — so `cargo test` never
18+
// (re)builds `libsandlock_ffi.so`. Build it ourselves so we always link the
19+
// current artifact instead of a stale one left in `target/` (which fails
20+
// with "undefined reference" when the symbol set has changed). `--lib`
21+
// builds the cdylib/staticlib/rlib; the recursive `cargo` is safe because
22+
// the outer build lock is released before tests run.
23+
let mut build = Command::new(env!("CARGO"));
24+
build.args(["build", "-p", "sandlock-ffi", "--lib"]);
25+
if profile == "release" {
26+
build.arg("--release");
27+
}
28+
let build_status = build.status().expect("invoke cargo build for cdylib");
29+
assert!(build_status.success(), "failed to build sandlock-ffi cdylib");
30+
1531
let target_dir = std::env::var_os("CARGO_TARGET_DIR")
1632
.map(PathBuf::from)
1733
.unwrap_or_else(|| {

0 commit comments

Comments
 (0)