From 70b201b75509f70006b7daaedf7afa3bce8ccc1a Mon Sep 17 00:00:00 2001 From: Arshia Ghafoori Date: Tue, 4 Aug 2026 13:28:50 +0000 Subject: [PATCH] fix(c-api): handle newer Cargo build-script directory layout in shared_object_dir shared_object_dir() assumed OUT_DIR always nests as build/-/out (package name and hash in one hyphenated directory). Newer Cargo/nightly toolchains instead lay it out as build///out (package name and hash as separate nested directories), which broke the hardcoded assertion and failed the build script outright. Detect which layout is in play by checking whether the directory popped after "out" already starts with "wasmer-c-api"; if not, pop once more to reach it. Verified against both layouts: the default toolchain (old layout) and a newer nightly (new layout) both build wasmer-c-api successfully now. --- lib/c-api/build.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index 3499fa001fec..9cb07daae221 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -349,6 +349,22 @@ fn shared_object_dir() -> PathBuf { assert_eq!(shared_object_dir.file_name(), Some(OsStr::new("out"))); shared_object_dir.pop(); + // Depending on the Cargo/toolchain version, the build script's + // fingerprint directory is laid out either as `build/-/out` + // (older Cargo, package name and hash in one hyphenated directory) or + // `build///out` (newer Cargo, package name and hash split + // into separate nested directories). If this component isn't the + // package directory itself, assume it's the hash-only directory from + // the newer layout and pop once more to reach it. + if !shared_object_dir + .file_name() + .unwrap() + .to_string_lossy() + .starts_with("wasmer-c-api") + { + shared_object_dir.pop(); + } + assert!( shared_object_dir .file_name() @@ -356,7 +372,9 @@ fn shared_object_dir() -> PathBuf { .unwrap() .to_string_lossy() .to_string() - .starts_with("wasmer-c-api") + .starts_with("wasmer-c-api"), + "unexpected OUT_DIR layout, could not locate the wasmer-c-api build directory: {:?}", + env::var("OUT_DIR") ); shared_object_dir.pop();