Skip to content

Commit eb4ce05

Browse files
committed
Restructure building the C API
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, rename that crate to "wasmtime-c-api-impl", and reintroduce 'wasmtime-c-api' as a new crate which wraps the previous crate and reexports it. This way LTO can be enabled when just building the artifacts and the use case from #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.
1 parent 9d8ca82 commit eb4ce05

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ members = [
101101
"cranelift/isle/islec",
102102
"cranelift/serde",
103103
"crates/bench-api",
104-
"crates/c-api",
104+
"crates/c-api/artifact",
105105
"crates/environ/fuzz",
106106
"crates/test-programs",
107107
"crates/wasi-preview1-component-adapter",

crates/c-api/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ExternalProject_Add(
100100
CONFIGURE_COMMAND ""
101101
INSTALL_COMMAND "${WASMTIME_INSTALL_COMMAND}"
102102
BUILD_COMMAND ${WASMTIME_PREBUILD_COMMAND} ${WASMTIME_CARGO_BINARY} build ${WASMTIME_BUILD_TYPE_FLAG} ${WASMTIME_USER_CARGO_BUILD_OPTIONS} ${WASMTIME_BUILD_TARGET}
103-
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}
103+
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/artifact
104104
BUILD_ALWAYS ${WASMTIME_ALWAYS_BUILD}
105105
BUILD_BYPRODUCTS ${WASMTIME_BUILD_PRODUCT})
106106
add_library(wasmtime INTERFACE)
@@ -137,5 +137,5 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/include/wasm.h
137137
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
138138
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/wasmtime
139139
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
140-
install(FILES ${WASMTIME_BUILD_PRODUCT}
140+
install(FILES ${WASMTIME_BUILD_PRODUCT}
141141
DESTINATION ${CMAKE_INSTALL_LIBDIR})

crates/c-api/Cargo.toml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "wasmtime-c-api"
2+
name = "wasmtime-c-api-impl"
33
version.workspace = true
44
authors.workspace = true
55
description = "C API to expose the Wasmtime runtime"
@@ -10,8 +10,7 @@ edition.workspace = true
1010
publish = false
1111

1212
[lib]
13-
name = "wasmtime"
14-
crate-type = ["staticlib", "cdylib", "rlib"]
13+
name = "wamstime_c_api"
1514
doc = false
1615
test = false
1716
doctest = false
@@ -38,16 +37,6 @@ wasi-common = { workspace = true, optional = true }
3837
futures = { workspace = true, optional = true }
3938

4039
[features]
41-
default = [
42-
'profiling',
43-
'wat',
44-
'wasi',
45-
'cache',
46-
'parallel-compilation',
47-
'async',
48-
'coredump',
49-
'addr2line',
50-
]
5140
async = ['wasmtime/async', 'futures']
5241
profiling = ["wasmtime/profiling"]
5342
cache = ["wasmtime/cache"]

crates/c-api/artifact/Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "wasmtime-c-api"
3+
version.workspace = true
4+
authors.workspace = true
5+
description = "C API to expose the Wasmtime runtime"
6+
license = "Apache-2.0 WITH LLVM-exception"
7+
repository = "https://github.com/bytecodealliance/wasmtime"
8+
readme = "README.md"
9+
edition.workspace = true
10+
publish = false
11+
12+
[lib]
13+
name = "wasmtime"
14+
crate-type = ["staticlib", "cdylib"]
15+
doc = false
16+
test = false
17+
doctest = false
18+
19+
[dependencies]
20+
wasmtime-c-api = { path = '..', package = 'wasmtime-c-api-impl' }
21+
22+
[features]
23+
default = [
24+
'profiling',
25+
'wat',
26+
'wasi',
27+
'cache',
28+
'parallel-compilation',
29+
'async',
30+
'coredump',
31+
'addr2line',
32+
]
33+
async = ['wasmtime-c-api/async']
34+
profiling = ["wasmtime-c-api/profiling"]
35+
cache = ["wasmtime-c-api/cache"]
36+
parallel-compilation = ['wasmtime-c-api/parallel-compilation']
37+
wasi = ['wasmtime-c-api/wasi']
38+
logging = ['wasmtime-c-api/logging']
39+
disable-logging = ["wasmtime-c-api/disable-logging"]
40+
coredump = ["wasmtime-c-api/coredump"]
41+
addr2line = ["wasmtime-c-api/addr2line"]
42+
wat = ["wasmtime-c-api/wat"]

crates/c-api/artifact/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub use wasmtime_c_api::*;

0 commit comments

Comments
 (0)