SERVER-116041 Add building wasmtime crate to mongo build (#47072)

GitOrigin-RevId: c87f2886f2e9348c185bd0f9803cebf263597a29
This commit is contained in:
Andrew Bradshaw 2026-01-30 14:34:16 -08:00 committed by MongoDB Bot
parent 1e6cac007a
commit ccc5c7c482
10 changed files with 5737 additions and 55 deletions

View File

@ -587,6 +587,9 @@ common:public-release --//bazel/config:release=True
common:public-release --//bazel/config:extensions_signature_verification_secure=True
common:public-release --stamp
common --@rules_rust//rust/toolchain/channel=nightly
common --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols=true
--config=fission
common:fission --fission=yes
common:fission --remote_download_regex=.*\.dwo$

1
.github/CODEOWNERS vendored
View File

@ -3419,6 +3419,7 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
/src/third_party/**/unicode-8.0.0 @10gen/query-execution @svc-auto-approve-bot
/src/third_party/**/unwind @10gen/server-programmability @svc-auto-approve-bot
/src/third_party/**/valgrind @10gen/devprod-build @svc-auto-approve-bot
/src/third_party/**/wasmtime @10gen/query-integration-features @svc-auto-approve-bot
/src/third_party/**/wiredtiger @10gen/storage-engines @svc-auto-approve-bot
/src/third_party/**/yaml-cpp @10gen/server-security @svc-auto-approve-bot
/src/third_party/**/zlib @10gen/server-networking-and-observability @svc-auto-approve-bot

View File

@ -82,10 +82,10 @@ http_file(
)
bazel_dep(name = "rules_cc", version = "0.2.10")
bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "platforms", version = "0.0.11")
single_version_override(
module_name = "platforms",
version = "0.0.9",
version = "0.0.11",
)
# TODO move over from WORKSPACE
@ -282,3 +282,63 @@ setup_mongo_windows_toolchains_extension = use_extension("//bazel/toolchains/cc/
use_repo(setup_mongo_windows_toolchains_extension, "mongo_windows_toolchain")
register_toolchains("@mongo_windows_toolchain//...")
###################### RUST DEPS ######################
bazel_dep(name = "rules_rust", version = "0.68.1")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2024",
versions = ["nightly/2025-12-11"],
)
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.spec(
package = "wasmtime",
version = "40.0.2",
)
crate.spec(
features = [
"cranelift",
"component-model",
"async",
"wasi",
],
package = "wasmtime-c-api-impl",
version = "40.0.2",
)
# We partially custom build wasmtime_c because otherwise it tries to use cmake
# to create generate conf.h
crate.annotation(
additive_build_file = "//src/third_party/wasmtime:BUILD.bazel.wasmtime",
crate = "wasmtime-c-api-impl",
extra_aliased_targets = {"wasmtime_c": "wasmtime_c"},
gen_build_script = "off",
)
crate.spec(
package = "zstd-sys",
version = "2.0.16+zstd.1.5.7",
)
# Bindgen uses libclang to parse code so it needs to know the path to libclang
crate.annotation_select(
build_script_data = [
"@@mongo_toolchain_v5//:libclang",
],
build_script_env = {
"LIBCLANG_PATH": "$(execpath @@mongo_toolchain_v5//:libclang)",
"BINDGEN_EXTRA_CLANG_ARGS": "-isystem$${pwd}/external/mongo_toolchain_v5/stow/llvm-v5/lib/clang/19/include",
},
crate = "zstd-sys",
repositories = ["crates"],
triples = [
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-gnu",
"powerpc-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
],
)
crate.from_specs()
use_repo(crate, "crates")
#################### END RUST DEPS ####################

5580
MODULE.bazel.lock generated

File diff suppressed because one or more lines are too long

View File

@ -322,8 +322,11 @@ def _impl(ctx):
flag_set(
actions = all_compile_actions,
flag_groups = [flag_group(flags = [
"-isystem{}".format(include)
# -isystem and the include path need to be separate strings in the array
# as things like rules_rust parse each flag individually
final_include
for include in ctx.attr.includes
for final_include in ["-isystem", include]
])],
),
] if ctx.attr.includes != None and len(ctx.attr.includes) > 0 else [],
@ -336,8 +339,11 @@ def _impl(ctx):
flag_set(
actions = all_compile_actions + all_link_actions + lto_index_actions,
flag_groups = [flag_group(flags = [
"-B{}".format(bin_dir)
# -B and the bin dirs need to be separate strings in the array
# as things like rules_rust parse each flag individually
final_bin_dir
for bin_dir in ctx.attr.bin_dirs
for final_bin_dir in ["-B", bin_dir]
])],
),
] if ctx.attr.bin_dirs != None and len(ctx.attr.bin_dirs) > 0 else [],
@ -468,7 +474,10 @@ def _impl(ctx):
flag_groups = [flag_group(flags = ["-fPIE"])],
),
flag_set(
actions = all_link_actions + lto_index_actions,
actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.lto_index_for_executable,
],
flag_groups = [flag_group(flags = ["-pie"])],
),
],
@ -1158,6 +1167,11 @@ def _impl(ctx):
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
flag_set(
actions = [
@ -1196,6 +1210,11 @@ def _impl(ctx):
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
],
)
@ -1456,10 +1475,24 @@ def _impl(ctx):
flag_group(
flags = [
"-fsanitize=address",
],
),
],
),
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"-fsanitize-blacklist=" + ctx.attr.asan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.asan_denylist != None else "",
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
flag_set(
actions = all_link_actions + lto_index_actions,
@ -1521,10 +1554,24 @@ def _impl(ctx):
flags = [
"-fsanitize=memory",
"-fsanitize-memory-track-origins",
],
),
],
),
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"-fsanitize-blacklist=" + ctx.attr.msan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.msan_denylist != None else "",
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
flag_set(
actions = all_link_actions + lto_index_actions,
@ -1549,10 +1596,24 @@ def _impl(ctx):
flag_group(
flags = [
"-fsanitize=thread",
],
),
],
),
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"-fsanitize-blacklist=" + ctx.attr.tsan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.tsan_denylist != None else "",
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
flag_set(
actions = all_link_actions + lto_index_actions,
@ -1595,11 +1656,25 @@ def _impl(ctx):
flag_group(
flags = [
"-fsanitize=undefined",
"-fsanitize-blacklist=" + ctx.attr.ubsan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.ubsan_denylist != None else "",
] + ubsan_compile_flags,
),
],
),
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"-fsanitize-blacklist=" + ctx.attr.ubsan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.ubsan_denylist != None else "",
],
),
],
with_features = [
with_feature_set(
features = ["rules_rust_unsupported_feature"],
),
],
),
flag_set(
actions = all_link_actions + lto_index_actions,
flag_groups = [
@ -1841,6 +1916,14 @@ def _impl(ctx):
],
)
# This feature is disabled during rust crate execution
# This means that any feature that depends on this feature being
# enabled will be disabled during crate compilation/linking.
rules_rust_unsupported_feature = feature(
name = "rules_rust_unsupported_feature",
enabled = True,
)
features = [
enable_all_warnings_feature,
general_clang_or_gcc_warnings_feature,
@ -1929,6 +2012,7 @@ def _impl(ctx):
first_party_gcc_warnings_feature,
trivial_auto_var_init_pattern_feature,
glibcxx_assertions_feature,
rules_rust_unsupported_feature,
] + get_common_features(ctx) + [
# These flags are at the bottom so they get applied after anything else.
# These are things like the flags people apply directly on cc_library through copts/linkopts

View File

@ -437,3 +437,10 @@ filegroup(
"{version}/bin/clang-format",
],
)
filegroup(
name = "libclang",
srcs = [
"{version}/lib/libclang.so",
],
)

View File

@ -315,6 +315,8 @@ def main() -> int:
third_party_libs.remove("sasl")
# This is not a real third party, its just the local ssl pretending to be boringssl
third_party_libs.remove("boringssl_replacement")
# This is just a build file that gets inserted into a third party
third_party_libs.remove("wasmtime")
# Nothing in this directory is included in Community/EA
third_party_libs.remove("private")
error_manager = lint_sbom(input_file, output_file, third_party_libs, should_format)

View File

@ -136,6 +136,9 @@ filters:
- "valgrind":
approvers:
- 10gen/devprod-build
- "wasmtime":
approvers:
- 10gen/query-integration-features
- "wiredtiger":
approvers:
- 10gen/storage-engines

0
src/third_party/wasmtime/BUILD.bazel vendored Normal file
View File

View File

@ -0,0 +1,40 @@
# This file is injected into the crate BUILD file - to reference build with @crates//:wasmtime_c
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
expand_template(
name = "gen_conf",
out = "include/wasmtime/conf.h",
substitutions = {
"#cmakedefine WASMTIME_FEATURE_PROFILING": "#define WASMTIME_FEATURE_PROFILING",
"#cmakedefine WASMTIME_FEATURE_WAT": "#define WASMTIME_FEATURE_WAT",
"#cmakedefine WASMTIME_FEATURE_CACHE": "#define WASMTIME_FEATURE_CACHE",
"#cmakedefine WASMTIME_FEATURE_PARALLEL_COMPILATION": "#define WASMTIME_FEATURE_PARALLEL_COMPILATION",
"#cmakedefine WASMTIME_FEATURE_WASI": "#define WASMTIME_FEATURE_WASI",
"#cmakedefine WASMTIME_FEATURE_LOGGING": "#define WASMTIME_FEATURE_LOGGING",
"#cmakedefine WASMTIME_FEATURE_DISABLE_LOGGING": "/* #undef WASMTIME_FEATURE_DISABLE_LOGGING */",
"#cmakedefine WASMTIME_FEATURE_COREDUMP": "#define WASMTIME_FEATURE_COREDUMP",
"#cmakedefine WASMTIME_FEATURE_ADDR2LINE": "#define WASMTIME_FEATURE_ADDR2LINE",
"#cmakedefine WASMTIME_FEATURE_DEMANGLE": "#define WASMTIME_FEATURE_DEMANGLE",
"#cmakedefine WASMTIME_FEATURE_THREADS": "#define WASMTIME_FEATURE_THREADS",
"#cmakedefine WASMTIME_FEATURE_GC": "#define WASMTIME_FEATURE_GC",
"#cmakedefine WASMTIME_FEATURE_GC_DRC": "#define WASMTIME_FEATURE_GC_DRC",
"#cmakedefine WASMTIME_FEATURE_GC_NULL": "#define WASMTIME_FEATURE_GC_NULL",
"#cmakedefine WASMTIME_FEATURE_ASYNC": "#define WASMTIME_FEATURE_ASYNC",
"#cmakedefine WASMTIME_FEATURE_CRANELIFT": "#define WASMTIME_FEATURE_CRANELIFT",
"#cmakedefine WASMTIME_FEATURE_WINCH": "#define WASMTIME_FEATURE_WINCH",
"#cmakedefine WASMTIME_FEATURE_DEBUG_BUILTINS": "#define WASMTIME_FEATURE_DEBUG_BUILTINS",
"#cmakedefine WASMTIME_FEATURE_POOLING_ALLOCATOR": "#define WASMTIME_FEATURE_POOLING_ALLOCATOR",
"#cmakedefine WASMTIME_FEATURE_COMPONENT_MODEL": "#define WASMTIME_FEATURE_COMPONENT_MODEL",
"#cmakedefine WASMTIME_FEATURE_PULLEY": "#define WASMTIME_FEATURE_PULLEY",
"#cmakedefine WASMTIME_FEATURE_ALL_ARCH": "/* #undef WASMTIME_FEATURE_ALL_ARCH */",
},
template = "include/wasmtime/conf.h.in",
)
cc_library(
name = "wasmtime_c",
hdrs = glob(["include/**"]) + [":gen_conf"],
strip_include_prefix = "include",
deps = [":wasmtime_c_api"],
)