Skip to content

Commit

Permalink
Restructure building the C API
Browse files Browse the repository at this point in the history
This commit introduces a wrapper crate which is now the new "real" C
API. The purpose of this change is to enable using LTO when building the
C API. Currently LTO is disabled because one of the crate types of the C
API is an "rlib" which means that it can't have LTO performed due to
rustc limitations. The solution here is to remove the "cdylib" and
"staticlib" crate types from the "wasmtime-c-api" crate and introduce a
new crate 'wasmtime-c-api-artfact' which wraps the previous crate and
reexports it.

This way LTO can be enabled when just building the artifacts and the use
case from bytecodealliance#6765 is still satisfied by having a crate that can be linked
to from Rust. Locally this reduces the size of the C API artifact for me
by nearly 1M.
  • Loading branch information
alexcrichton committed Oct 23, 2023
1 parent 9d8ca82 commit 282d5fd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ members = [
"cranelift/isle/islec",
"cranelift/serde",
"crates/bench-api",
"crates/c-api",
"crates/c-api/artifact",
"crates/environ/fuzz",
"crates/test-programs",
"crates/wasi-preview1-component-adapter",
Expand Down
2 changes: 1 addition & 1 deletion ci/build-release-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ else
fi

cargo build --release $flags --target $target -p wasmtime-cli $bin_flags
cargo build --release $flags --target $target -p wasmtime-c-api
cargo build --release $flags --target $target -p wasmtime-c-api-artifact
12 changes: 0 additions & 12 deletions crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ edition.workspace = true
publish = false

[lib]
name = "wasmtime"
crate-type = ["staticlib", "cdylib", "rlib"]
doc = false
test = false
doctest = false
Expand All @@ -38,16 +36,6 @@ wasi-common = { workspace = true, optional = true }
futures = { workspace = true, optional = true }

[features]
default = [
'profiling',
'wat',
'wasi',
'cache',
'parallel-compilation',
'async',
'coredump',
'addr2line',
]
async = ['wasmtime/async', 'futures']
profiling = ["wasmtime/profiling"]
cache = ["wasmtime/cache"]
Expand Down
42 changes: 42 additions & 0 deletions crates/c-api/artifact/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "wasmtime-c-api-artifact"
version.workspace = true
authors.workspace = true
description = "C API to expose the Wasmtime runtime"
license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/bytecodealliance/wasmtime"
readme = "README.md"
edition.workspace = true
publish = false

[lib]
name = "wasmtime"
crate-type = ["staticlib", "cdylib"]
doc = false
test = false
doctest = false

[dependencies]
wasmtime-c-api = { path = '..' }

[features]
default = [
'profiling',
'wat',
'wasi',
'cache',
'parallel-compilation',
'async',
'coredump',
'addr2line',
]
async = ['wasmtime-c-api/async']
profiling = ["wasmtime-c-api/profiling"]
cache = ["wasmtime-c-api/cache"]
parallel-compilation = ['wasmtime-c-api/parallel-compilation']
wasi = ['wasmtime-c-api/wasi']
logging = ['wasmtime-c-api/logging']
disable-logging = ["wasmtime-c-api/disable-logging"]
coredump = ["wasmtime-c-api/coredump"]
addr2line = ["wasmtime-c-api/addr2line"]
wat = ["wasmtime-c-api/wat"]
1 change: 1 addition & 0 deletions crates/c-api/artifact/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use wasmtime_c_api::*;

0 comments on commit 282d5fd

Please sign in to comment.