Skip to content

Truly independent web browser

LibWasm: Build the engine's C ABI only for LibWasm

Shannon Booth3ce76da7da0a
diff --git a/Libraries/LibWasm/CMakeLists.txt b/Libraries/LibWasm/CMakeLists.txt
index a897beeae8b..2e2ec86e144 100644
--- a/Libraries/LibWasm/CMakeLists.txt
+++ b/Libraries/LibWasm/CMakeLists.txt
@@ -4,7 +4,7 @@ set(SOURCES
ladybird_lib(LibWasm wasm EXPLICIT_SYMBOL_EXPORT)
-import_rust_crate(MANIFEST_PATH Engine/Cargo.toml CRATE_NAME libwasm_engine FEATURES allocator FFI_HEADER RustFFI.h)
+import_rust_crate(MANIFEST_PATH Engine/Cargo.toml CRATE_NAME libwasm_engine FEATURES allocator capi FFI_HEADER RustFFI.h)
target_link_libraries(LibWasm PRIVATE libwasm_engine PUBLIC LibGC)
if ((LINUX OR BSD) AND NOT BUILD_SHARED_LIBS)
target_link_options(LibWasm INTERFACE LINKER:--allow-multiple-definition)
diff --git a/Libraries/LibWasm/Engine/Cargo.toml b/Libraries/LibWasm/Engine/Cargo.toml
index 9e8c400e8e7..9f283c1a358 100644
--- a/Libraries/LibWasm/Engine/Cargo.toml
+++ b/Libraries/LibWasm/Engine/Cargo.toml
@@ -19,6 +19,9 @@ rustc-demangle = "0.1"
[features]
default = []
allocator = ["dep:ladybird_allocator"]
+# The C ABI of src/capi.rs, for LibWasm's C++ embedders. A Rust embedder uses the runtime's API instead, and leaves it out
+# so that only one copy of the engine in a process exports its C symbols.
+capi = []
[build-dependencies]
cbindgen = "0.29"
diff --git a/Libraries/LibWasm/Engine/src/lib.rs b/Libraries/LibWasm/Engine/src/lib.rs
index 074e138981e..a2777480eae 100644
--- a/Libraries/LibWasm/Engine/src/lib.rs
+++ b/Libraries/LibWasm/Engine/src/lib.rs
@@ -23,6 +23,7 @@ mod rust_panic;
#[path = "../../../LibJS/Rust/src/futex.rs"]
mod futex;
+#[cfg(feature = "capi")]
pub mod capi;
pub mod runtime;
pub mod wasi;