Skip to content

Commit 373bf95

Browse files
committed
wasmtime: update to v39.0.1
Signed-off-by: Matt Leon <mattleon@google.com>
1 parent 6f72a85 commit 373bf95

19 files changed

Lines changed: 266 additions & 681 deletions

File tree

.github/workflows/format.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
run: |
104104
bazel run //bazel/cargo/wasmsign:crates_vendor
105105
bazel run //bazel/cargo/wasmtime:crates_vendor
106+
perl -pi -e 's/rust_library/rust_static_library/g' bazel/cargo/wasmtime/remote/BUILD.wasmtime-c-api-impl-*.bazel
106107
git diff --exit-code
107108
108109
clang_format:

BUILD

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ cc_library(
190190
name = "wasmtime_lib",
191191
srcs = [
192192
"src/common/types.h",
193-
"src/wasmtime/types.h",
194193
"src/wasmtime/wasmtime.cc",
195194
],
196195
hdrs = ["include/proxy-wasm/wasmtime.h"],
@@ -201,6 +200,7 @@ cc_library(
201200
"PROXY_WASM_HAS_RUNTIME_WASMTIME",
202201
"PROXY_WASM_HOST_ENGINE_WASMTIME",
203202
],
203+
includes = ["@com_github_bytecodealliance_wasmtime//:wasmtime_lib"],
204204
# See: https://bytecodealliance.github.io/wasmtime/c-api/
205205
linkopts = select({
206206
"@platforms//os:macos": [],
@@ -225,65 +225,6 @@ cc_library(
225225
],
226226
)
227227

228-
genrule(
229-
name = "prefixed_wasmtime_sources",
230-
srcs = [
231-
"src/wasmtime/types.h",
232-
"src/wasmtime/wasmtime.cc",
233-
],
234-
outs = [
235-
"src/wasmtime/prefixed_types.h",
236-
"src/wasmtime/prefixed_wasmtime.cc",
237-
],
238-
cmd = """
239-
for file in $(SRCS); do
240-
sed -e 's/wasm_/wasmtime_wasm_/g' \
241-
-e 's/include\\/wasm.h/include\\/prefixed_wasm.h/g' \
242-
-e 's/wasmtime\\/types.h/wasmtime\\/prefixed_types.h/g' \
243-
$$file >$(@D)/$$(dirname $$file)/prefixed_$$(basename $$file)
244-
done
245-
""",
246-
)
247-
248-
cc_library(
249-
name = "prefixed_wasmtime_lib",
250-
srcs = [
251-
"src/common/types.h",
252-
"src/wasmtime/prefixed_types.h",
253-
"src/wasmtime/prefixed_wasmtime.cc",
254-
],
255-
hdrs = ["include/proxy-wasm/wasmtime.h"],
256-
copts = [
257-
"-DWASM_API_EXTERN=",
258-
],
259-
defines = [
260-
"PROXY_WASM_HAS_RUNTIME_WASMTIME",
261-
"PROXY_WASM_HOST_ENGINE_WASMTIME",
262-
],
263-
# See: https://bytecodealliance.github.io/wasmtime/c-api/
264-
linkopts = select({
265-
"@platforms//os:macos": [],
266-
"@platforms//os:windows": [
267-
"ws2_32.lib",
268-
"advapi32.lib",
269-
"userenv.lib",
270-
"ntdll.lib",
271-
"shell32.lib",
272-
"ole32.lib",
273-
"bcrypt.lib",
274-
],
275-
"//conditions:default": [
276-
"-ldl",
277-
"-lm",
278-
"-lpthread",
279-
],
280-
}),
281-
deps = [
282-
":wasm_vm_headers",
283-
"@com_github_bytecodealliance_wasmtime//:prefixed_wasmtime_lib",
284-
],
285-
)
286-
287228
cc_library(
288229
name = "lib",
289230
deps = [
@@ -298,6 +239,5 @@ cc_library(
298239
[":wasmedge_lib"],
299240
) + proxy_wasm_select_engine_wasmtime(
300241
[":wasmtime_lib"],
301-
[":prefixed_wasmtime_lib"],
302242
),
303243
)

bazel/cargo/wasmtime/Cargo.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@
1313
# limitations under the License.
1414

1515
[package]
16-
edition = "2021"
16+
edition = "2024"
1717
name = "wasmtime-c-api-bazel"
18-
version = "24.0.0"
19-
rust-version = "1.78.0"
18+
version = "39.0.1"
2019

2120
[lib]
2221
path = "fake_lib.rs"
2322

2423
[dependencies]
25-
env_logger = "0.10"
26-
anyhow = "1.0"
27-
once_cell = "1.12"
28-
log = {version = "0.4.8", default-features = false}
29-
tracing = "0.1.26"
30-
wasmtime = {version = "24.0.0", default-features = false, features = ['cranelift', 'runtime', 'gc', 'std']}
31-
wasmtime-c-api-macros = {git = "https://github.com/bytecodealliance/wasmtime", tag = "v24.0.0"}
24+
# IMPORTANT NOTE: prefixed linking of wasmtime requires changing the generated
25+
# file to specify `rust_static_library` instead of `rust_library`. The
26+
# following sed command will do it for you:
27+
#
28+
# `sed -i.bak -e 's/rust_library/rust_static_library/g' bazel/cargo/wasmtime/remote/BUILD.wasmtime-c-api-impl-*.bazel`
29+
wasmtime-c-api-impl = {version = "39.0.1", default-features = false, features = ['cranelift', 'wasi', 'wat', 'gc-drc']}

bazel/external/wasmtime.BUILD

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,25 @@
1313
# limitations under the License.
1414

1515
load("@rules_cc//cc:defs.bzl", "cc_library")
16-
load("@rules_rust//rust:defs.bzl", "rust_static_library")
1716

1817
licenses(["notice"]) # Apache 2
1918

2019
package(default_visibility = ["//visibility:public"])
2120

2221
cc_library(
2322
name = "wasmtime_lib",
24-
hdrs = [
25-
"crates/c-api/include/wasm.h",
26-
],
27-
deps = [
28-
":rust_c_api",
29-
],
30-
)
31-
32-
genrule(
33-
name = "prefixed_wasmtime_c_api_headers",
3423
srcs = [
35-
"crates/c-api/include/wasm.h",
36-
],
37-
outs = [
38-
"crates/c-api/include/prefixed_wasm.h",
24+
":prefixed_wasmtime_c_api_lib",
3925
],
40-
cmd = """
41-
sed -e 's/\\ wasm_/\\ wasmtime_wasm_/g' \
42-
-e 's/\\*wasm_/\\*wasmtime_wasm_/g' \
43-
-e 's/(wasm_/(wasmtime_wasm_/g' \
44-
$(<) >$@
45-
""",
26+
hdrs = glob(["crates/c-api/include/**"]) + [":wasmtime_conf.h"],
27+
includes = ["crates/c-api/include/"],
28+
linkstatic = 1,
4629
)
4730

4831
genrule(
4932
name = "prefixed_wasmtime_c_api_lib",
5033
srcs = [
51-
":rust_c_api",
34+
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:wasmtime-c-api-impl",
5235
],
5336
outs = [
5437
"prefixed_wasmtime_c_api.a",
@@ -63,31 +46,27 @@ genrule(
6346
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
6447
)
6548

66-
cc_library(
67-
name = "prefixed_wasmtime_lib",
68-
srcs = [
69-
":prefixed_wasmtime_c_api_lib",
70-
],
71-
hdrs = [
72-
":prefixed_wasmtime_c_api_headers",
73-
],
74-
linkstatic = 1,
75-
)
49+
# This must match the features defined in `bazel/cargo/wasmtime/Cargo.toml` for
50+
# the C/C++ API to expose the right set of methods.
51+
features = [
52+
"cranelift",
53+
"wat",
54+
"wasi",
55+
"gc-drc",
56+
]
7657

77-
rust_static_library(
78-
name = "rust_c_api",
79-
srcs = glob(["crates/c-api/src/**/*.rs"]),
80-
crate_features = ["cranelift"],
81-
crate_root = "crates/c-api/src/lib.rs",
82-
edition = "2021",
83-
proc_macro_deps = [
84-
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:wasmtime-c-api-macros",
85-
],
86-
deps = [
87-
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:anyhow",
88-
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:env_logger",
89-
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:once_cell",
90-
# buildifier: leave-alone
91-
"@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:wasmtime",
92-
],
58+
# Wasmtime C-api headers use cmakedefines to generate the config file.
59+
# This does the same as CMake's configure_file, but using the crate features array above.
60+
genrule(
61+
name = "wasmtime_conf.h",
62+
srcs = ["crates/c-api/include/wasmtime/conf.h.in"],
63+
outs = ["crates/c-api/include/wasmtime/conf.h"],
64+
cmd = """
65+
cat < $< > $$TMPDIR/working_file
66+
for enabled_feature in $$(echo "{}"); do
67+
sed -i "s/#cmakedefine WASMTIME_FEATURE_$$enabled_feature/#define WASMTIME_FEATURE_$$enabled_feature 1/" $$TMPDIR/working_file
68+
done
69+
sed -i 's/#cmakedefine \\(.*\\)/\\/\\/ \\1 is not defined./' $$TMPDIR/working_file
70+
cp $$TMPDIR/working_file $@
71+
""".format(" ".join([f.upper() for f in features])),
9372
)

bazel/repositories.bzl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,20 @@ def proxy_wasm_cpp_host_repositories():
336336
http_archive,
337337
name = "com_github_bytecodealliance_wasmtime",
338338
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD",
339-
sha256 = "2ccb49bb3bfa4d86907ad4c80d1147aef6156c7b6e3f7f14ed02a39de9761155",
340-
strip_prefix = "wasmtime-24.0.0",
341-
url = "https://github.com/bytecodealliance/wasmtime/archive/v24.0.0.tar.gz",
339+
strip_prefix = "wasmtime-39.0.1",
340+
integrity = "sha256-iJSGlux/AIc6k+hM6Ax6hWQeT4U7UJtj//ra22+B4+E=",
341+
url = "https://github.com/bytecodealliance/wasmtime/archive/v39.0.1.tar.gz",
342+
# Prefix wasm_c_api functions for coexistence with other runtimes.
343+
patch_cmds = ["""
344+
find ./crates/c-api -type f -exec sed -i.bak \
345+
-e 's/\\ wasm_/\\ wasmtime_wasm_/g' \
346+
-e 's/\\*wasm_/\\*wasmtime_wasm_/g' \
347+
-e 's/^wasm_/wasmtime_wasm_/g' \
348+
-e 's/<wasm_/<wasmtime_wasm_/g' \
349+
-e 's/\\.wasm_/\\.wasmtime_wasm_/g' \
350+
-e 's/\\&wasm_/\\&wasmtime_wasm_/g' \
351+
-e 's/\\[wasm_/\\[wasmtime_wasm_/g' \
352+
-e 's/wasmtime_config_wasm_/wasmtime_config_wasmtime_wasm_/g' \
353+
-e 's/(wasm_/(wasmtime_wasm_/g' {} \\;
354+
"""],
342355
)

bazel/select.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def proxy_wasm_select_engine_wamr(xs):
3434
"//conditions:default": [],
3535
})
3636

37-
def proxy_wasm_select_engine_wasmtime(xs, xp):
37+
def proxy_wasm_select_engine_wasmtime(xs):
3838
return select({
3939
"@proxy_wasm_cpp_host//bazel:engine_wasmtime": xs,
40-
"@proxy_wasm_cpp_host//bazel:multiengine": xp,
40+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
4141
"//conditions:default": [],
4242
})
4343

bazel/wasm.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def wasm_rust_binary(name, tags = [], wasi = False, signing_key = [], **kwargs):
8383

8484
rust_binary(
8585
name = wasm_name,
86-
edition = "2018",
86+
edition = "2024",
8787
crate_type = "cdylib",
8888
out_binary = True,
8989
tags = ["manual"],

src/wasmtime/types.h

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)