Skip to content

Commit f340fb5

Browse files
kesmit13claude
andauthored
Recognize .abi3.so native extensions in linker scanner (#208)
* Recognize .abi3.so native extensions in linker scanner The directory scanner in prelink.rs only matched native WASM extensions ending in .cpython-314-wasm32-wasi.so, ignoring stable-ABI extensions (.abi3.so) even though CPython's EXTENSION_SUFFIXES includes them. This adds .abi3.so to the set of recognized suffixes and validates candidates with a WASM magic byte check to avoid accidentally treating native (ELF) .abi3.so files as WASM modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Run cargo fmt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 89af297 commit f340fb5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/prelink.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ use zstd::Decoder;
1616

1717
use crate::{ComponentizePyConfig, ConfigContext, Library, RawComponentizePyConfig};
1818

19-
static NATIVE_EXTENSION_SUFFIX: &str = ".cpython-314-wasm32-wasi.so";
19+
static NATIVE_EXTENSION_SUFFIXES: &[&str] = &[".cpython-314-wasm32-wasi.so", ".abi3.so"];
20+
21+
/// Check if a file starts with the WASM magic bytes (`\0asm`).
22+
fn is_wasm_file(path: &Path) -> bool {
23+
fs::read(path)
24+
.map(|bytes| bytes.starts_with(b"\0asm"))
25+
.unwrap_or(false)
26+
}
2027

2128
type ConfigsMatchedWorlds<'a> =
2229
IndexMap<String, (ConfigContext<ComponentizePyConfig>, Option<&'a str>)>;
@@ -235,7 +242,11 @@ fn search_directory(
235242
search_directory(root, &entry?.path(), libraries, configs, modules_seen)?;
236243
}
237244
} else if let Some(name) = path.file_name().and_then(|name| name.to_str()) {
238-
if name.ends_with(NATIVE_EXTENSION_SUFFIX) {
245+
if NATIVE_EXTENSION_SUFFIXES
246+
.iter()
247+
.any(|suffix| name.ends_with(suffix))
248+
&& is_wasm_file(path)
249+
{
239250
libraries.push(path.to_owned());
240251
} else if name == "componentize-py.toml" {
241252
let root = root

0 commit comments

Comments
 (0)