Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ build --cxxopt="-fbracket-depth=512" --host_cxxopt="-fbracket-depth=512"
build --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=n
build --@rules_rust//:extra_exec_rustc_flags=-Cdebug-assertions=n
build --@rules_rust//:rustfmt.toml=//src/rust:rustfmt.toml
# We use nightly because of https://github.com/bazelbuild/rules_rust/issues/3459
build --@rules_rust//rust/toolchain/channel=nightly
build --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols

# We default to not enabling debug assertions and unwinding for Rust. For debug builds this is not
# the right setting, but unfortunately we can't set that directly.
Expand Down
2 changes: 1 addition & 1 deletion build/rust_lint.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build:rust-enable-clippy-checks --output_groups=+clippy_checks
# - clippy::non_std_lazy_statics – triggers on lazy_static, non-trivial to replace
# - clippy::format_push_string – avoids single memory allocation, but makes code less readable
# - clippy::cast_possible_truncation - usize/u64 conversion warning is unbelievably noisy
build:rust-enable-clippy-checks --@rules_rust//:clippy_flags=-Wclippy::pedantic,-Wclippy::redundant_clone,-Wclippy::str_to_string,-Wclippy::string_to_string,-Wclippy::to_string_in_format_args,-Wclippy::unnecessary_to_owned,-Wclippy::implicit_clone,-Wclippy::suspicious_to_owned,-Wclippy::unnecessary_to_owned,-Wclippy::nursery,-Wclippy::dbg_macro,-Wclippy::unwrap_used,-Wclippy::allow_attributes,-Aclippy::missing_const_for_fn,-Aclippy::cognitive_complexity,-Aclippy::trait_duplication_in_bounds,-Aclippy::non_send_fields_in_send_ty,-Aclippy::option_if_let_else,-Aclippy::missing_errors_doc,-Aclippy::must_use_candidate,-Aclippy::future_not_send,-Aclippy::trivial_regex,-Aclippy::literal_string_with_formatting_args,-Aclippy::non_std_lazy_statics,-Aclippy::format_push_string,-Aclippy::cast_possible_truncation,-Dwarnings
build:rust-enable-clippy-checks --@rules_rust//:clippy_flags=-Wclippy::pedantic,-Wclippy::redundant_clone,-Wclippy::str_to_string,-Wclippy::to_string_in_format_args,-Wclippy::unnecessary_to_owned,-Wclippy::implicit_clone,-Wclippy::suspicious_to_owned,-Wclippy::unnecessary_to_owned,-Wclippy::nursery,-Wclippy::dbg_macro,-Wclippy::unwrap_used,-Wclippy::allow_attributes,-Aclippy::missing_const_for_fn,-Aclippy::cognitive_complexity,-Aclippy::trait_duplication_in_bounds,-Aclippy::non_send_fields_in_send_ty,-Aclippy::option_if_let_else,-Aclippy::missing_errors_doc,-Aclippy::must_use_candidate,-Aclippy::future_not_send,-Aclippy::trivial_regex,-Aclippy::literal_string_with_formatting_args,-Aclippy::non_std_lazy_statics,-Aclippy::format_push_string,-Aclippy::cast_possible_truncation,-Dwarnings
build --@rules_rust//rust/settings:clippy.toml=//src/rust:clippy.toml

# enable rustfmt checks
Expand Down
20 changes: 13 additions & 7 deletions build/rust_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
load("//deps/rust/crates:crates.bzl", "crate_repositories")

RUST_STABLE_VERSION = "1.86.0" # LLVM 19
# We use nightly because of https://github.com/bazelbuild/rules_rust/issues/3459
RUST_VERSION = "nightly/2025-09-18"

RUST_NIGHTLY_VERSION = "nightly/2025-02-20"
# List of allowed unstable features
ALLOWED_FEATURES = []

# rustc flags applied to all workerd source code
RUSTC_FLAGS = [
# We can't enable this in .bazelrc because 3rd-party crates don't like this.
# used manually everywhere instead.
"-Zallow-features=" + ",".join(ALLOWED_FEATURES),
]

# List of additional triples to be configured on top of the local platform triple
RUST_TARGET_TRIPLES = [
Expand All @@ -29,17 +38,14 @@ def rust_toolchains():
"aarch64-unknown-linux-gnu": ["-Ctarget-feature=+crc"],
# No options needed for aarch64-apple-darwin: CRC feature is enabled by default.
},
versions = [
RUST_STABLE_VERSION,
RUST_NIGHTLY_VERSION,
],
versions = [RUST_VERSION],
)

for t in RUST_TARGET_TRIPLES:
rustfmt_toolchain_repository(
name = "rustfmt_toolchain_" + t,
exec_triple = t,
version = RUST_NIGHTLY_VERSION,
version = RUST_VERSION,
)

crate_universe_dependencies()
Expand Down
3 changes: 3 additions & 0 deletions build/wd_rust_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test")
load("@workerd//:build/rust_toolchains.bzl", "RUSTC_FLAGS")
load("@workerd//:build/wd_rust_crate.bzl", "rust_cxx_bridge")

def wd_rust_binary(
Expand Down Expand Up @@ -62,6 +63,7 @@ def wd_rust_binary(
"@//build/config:no_build": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
rustc_flags = RUSTC_FLAGS,
)

rust_test(
Expand All @@ -83,4 +85,5 @@ def wd_rust_binary(
"//conditions:default": [],
}),
size = test_size,
rustc_flags = RUSTC_FLAGS,
)
2 changes: 2 additions & 0 deletions build/wd_rust_capnp_library.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""wd_rust_capnp_library definition"""

load("@capnp-cpp//src/capnp:rust_capnp_library.bzl", "rust_capnp_library")
load("@workerd//:build/rust_toolchains.bzl", "RUSTC_FLAGS")

def wd_rust_capnp_library(**kwargs):
"""Wrapper for rust_capnp_library that sets common attributes
"""
rust_capnp_library(
src_prefix = "src",
rustc_flags = RUSTC_FLAGS,
**kwargs
)
3 changes: 3 additions & 0 deletions build/wd_rust_crate.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test", "rust_unpretty")
load("@workerd//:build/rust_toolchains.bzl", "RUSTC_FLAGS")

def rust_cxx_bridge(
name,
Expand Down Expand Up @@ -120,6 +121,7 @@ def wd_rust_crate(
"@//build/config:no_build": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
rustc_flags = RUSTC_FLAGS,
)

rust_test(
Expand All @@ -140,6 +142,7 @@ def wd_rust_crate(
"@platforms//os:windows": 0,
"//conditions:default": 1,
}),
rustc_flags = RUSTC_FLAGS,
)

if len(proc_macro_deps) + len(cxx_bridge_srcs) > 0:
Expand Down
3 changes: 1 addition & 2 deletions src/rust/cxx-integration-test/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Non-production crate to help test various aspects of rust/c++ integration.

use std::io::Error;
use std::io::ErrorKind;
use std::pin::Pin;
use std::time::Duration;

Expand Down Expand Up @@ -100,7 +99,7 @@ fn result_ok() -> Result<i32> {
}

fn result_error() -> Result<i32> {
Err(Error::new(ErrorKind::Other, "test error"))
Err(Error::other("test error"))
}

fn log_every_level() {
Expand Down
2 changes: 1 addition & 1 deletion src/rust/kj/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::io::AsyncIoStream;
#[cxx::bridge(namespace = "kj::rust")]
#[expect(clippy::missing_panics_doc)]
#[expect(clippy::missing_safety_doc)]
#[expect(clippy::needless_lifetimes)]
#[expect(clippy::elidable_lifetime_names)]
pub mod ffi {
unsafe extern "C++" {
include!("workerd/rust/kj/ffi.h");
Expand Down
Loading