1313# limitations under the License.
1414
1515load("@rules_cc//cc:defs.bzl", "cc_library")
16- load("@rules_rust//rust:defs.bzl", "rust_static_library")
1716
1817licenses(["notice"]) # Apache 2
1918
2019package(default_visibility = ["//visibility:public"])
2120
2221cc_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
4831genrule(
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)
0 commit comments