Skip to content

Commit 8e65039

Browse files
committed
[build] Transition Rust+cargo to bzlmod
1 parent 0688c51 commit 8e65039

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

MODULE.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ git_override(
3737
remote = "https://chromium.googlesource.com/chromium/src/third_party/zlib.git",
3838
)
3939

40-
# Rust
41-
bazel_dep(name = "rules_rust", version = "0.68.1")
42-
4340
# BoringSSL may subtly break backwards compatibility and behave differently than the latest FIPS
4441
# version, often by rejecting key values that it considers invalid/unsafe even though they are still
4542
# accepted by BoringSSL. Update with caution and only after confirming this is compatible with the
@@ -60,6 +57,7 @@ archive_override(
6057
include("//build/deps:deps.MODULE.bazel")
6158
include("//build/deps:nodejs.MODULE.bazel")
6259
include("//build/deps:python.MODULE.bazel")
60+
include("//build/deps:rust.MODULE.bazel")
6361
include("//build/deps:v8.MODULE.bazel")
6462
include("//build/deps:oci.MODULE.bazel")
6563

WORKSPACE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ http_archive(
1616
url = "https://github.com/cloudflare/workerd-cxx/tarball/916f0e7be8f1d43fe5ece1b72edd3c5844243d7b",
1717
)
1818

19-
load("//:build/rust_toolchains.bzl", "rust_toolchains")
20-
21-
rust_toolchains()
22-
2319
# rust-based lolhtml dependency, including the API header.
2420
# Presented as a separate repository to allow overrides.
2521
new_local_repository(

build/deps/rust.MODULE.bazel

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
bazel_dep(name = "rules_rust", version = "0.68.1")
2+
3+
RUST_STABLE_VERSION = "1.91.0" # LLVM 21
4+
5+
RUST_NIGHTLY_VERSION = "nightly/2025-10-30"
6+
7+
# List of additional triples to be configured on top of the local platform triple
8+
RUST_TARGET_TRIPLES = [
9+
# Add support for macOS cross-compilation
10+
"x86_64-apple-darwin",
11+
# Add support for macOS rosetta
12+
"aarch64-unknown-linux-gnu",
13+
]
14+
15+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
16+
rust.toolchain(
17+
allocator_library = "@rules_rust//ffi/rs:empty",
18+
edition = "2024",
19+
extra_rustc_flags_triples = {
20+
# Enable ISA extensions matching the ones used for C++. The clmul feature is not included as
21+
# it is still "unstable" as of 1.86.0.
22+
"x86_64-unknown-linux-gnu": ["-Ctarget-feature=+sse4.2"],
23+
"x86_64-apple-darwin": ["-Ctarget-feature=+sse4.2"],
24+
"x86_64-pc-windows-msvc": ["-Ctarget-feature=+sse4.2"],
25+
"aarch64-unknown-linux-gnu": ["-Ctarget-feature=+crc"],
26+
# No options needed for aarch64-apple-darwin: CRC feature is enabled by default.
27+
},
28+
extra_target_triples = RUST_TARGET_TRIPLES,
29+
rustfmt_version = RUST_NIGHTLY_VERSION,
30+
versions = [
31+
RUST_STABLE_VERSION,
32+
RUST_NIGHTLY_VERSION,
33+
],
34+
)
35+
use_repo(rust, "rust_toolchains")
36+
37+
register_toolchains("@rust_toolchains//:all")
38+
39+
crate_repositories = use_extension("//deps/rust:extension.bzl", "crate_repositories")
40+
use_repo(
41+
crate_repositories,
42+
"crates_vendor",
43+
# Needed to retrieve lol-html header
44+
"crates_vendor__lol_html_c_api-1.3.0",
45+
)

build/rust_toolchains.bzl

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

deps/rust/extension.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Module extensions for using vendored crates with bzlmod. Derived from https://github.com/bazelbuild/rules_rust/blob/0.68.1/examples/hello_world/third-party-in-workspace/extension.bzl. """
2+
3+
load("//deps/rust/crates:crates.bzl", _crate_repositories = "crate_repositories")
4+
5+
def _crate_repositories_impl(module_ctx):
6+
direct_deps = _crate_repositories()
7+
return module_ctx.extension_metadata(
8+
root_module_direct_deps = ["crates_vendor", "crates_vendor__lol_html_c_api-1.3.0"],
9+
root_module_direct_dev_deps = [],
10+
)
11+
12+
crate_repositories = module_extension(
13+
implementation = _crate_repositories_impl,
14+
)

0 commit comments

Comments
 (0)