mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
Upgrade Bazel Rust and LLVM dependencies (#34781)
## What changed - Upgrade `rules_rs` from `0.0.58` to `0.0.96` and LLVM from `0.7.9` to `0.8.11`, updating extension paths, platform constraints, and compatibility patches for the current APIs. - Add native `windows-gnullvm` execution support for the argument-comment lint toolchain while retaining MSVC execution for existing cross-target builds. - Build `aws-lc-sys` through the Bazel Central Registry `aws-lc` module and `rules_rs` integration, removing the replaced crate-specific patches. GitOrigin-RevId: 9829bcdb6ac74e846b713568aac38ea2fa3c42a2
This commit is contained in:
committed by
copyberry
parent
c5779ed6bb
commit
cc559bb971
15
BUILD.bazel
15
BUILD.bazel
@@ -17,7 +17,8 @@ platform(
|
||||
platform(
|
||||
name = "local_windows",
|
||||
constraint_values = [
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
parents = ["@platforms//host"],
|
||||
)
|
||||
@@ -25,7 +26,7 @@ platform(
|
||||
platform(
|
||||
name = "local_windows_msvc",
|
||||
constraint_values = [
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
parents = ["@platforms//host"],
|
||||
)
|
||||
@@ -35,7 +36,8 @@ platform(
|
||||
constraint_values = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -44,7 +46,7 @@ platform(
|
||||
constraint_values = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -53,12 +55,13 @@ toolchain(
|
||||
exec_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
toolchain = "@bazel_tools//tools/test:empty_toolchain",
|
||||
toolchain_type = "@bazel_tools//tools/test:default_test_toolchain_type",
|
||||
|
||||
108
MODULE.bazel
108
MODULE.bazel
@@ -2,7 +2,7 @@ module(name = "codex")
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.9.0")
|
||||
bazel_dep(name = "platforms", version = "1.0.0")
|
||||
bazel_dep(name = "llvm", version = "0.7.9")
|
||||
bazel_dep(name = "llvm", version = "0.8.11")
|
||||
|
||||
# Patch hermetic LLVM for Codex's custom libc++ and Windows gnullvm runtime
|
||||
# needs that have not landed upstream.
|
||||
@@ -89,45 +89,39 @@ single_version_override(
|
||||
)
|
||||
|
||||
bazel_dep(name = "rules_platform", version = "0.1.0")
|
||||
bazel_dep(name = "rules_rs", version = "0.0.58")
|
||||
|
||||
# `rules_rs` still does not model `windows-gnullvm` as a distinct Windows exec
|
||||
# platform, so patch it until upstream grows that support for both x86_64 and
|
||||
# aarch64.
|
||||
bazel_dep(name = "aws-lc", version = "5.1.0.bcr.1")
|
||||
bazel_dep(name = "rules_rs", version = "0.0.96")
|
||||
single_version_override(
|
||||
module_name = "rules_rs",
|
||||
patch_strip = 1,
|
||||
patches = [
|
||||
"//patches:rules_rs_build_script_deps_annotation.patch",
|
||||
"//patches:rules_rs_windows_gnullvm_exec.patch",
|
||||
"//patches:rules_rs_windows_exec_linker.patch",
|
||||
],
|
||||
version = "0.0.58",
|
||||
version = "0.0.96",
|
||||
)
|
||||
|
||||
rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust")
|
||||
|
||||
# Build-script probe binaries inherit CFLAGS/CXXFLAGS from Bazel's C++
|
||||
# toolchain. On `windows-gnullvm`, llvm-mingw does not ship
|
||||
# `libssp_nonshared`, so strip the forwarded stack-protector flags there.
|
||||
rules_rust = use_extension("@rules_rs//rs:rules_rust.bzl", "rules_rust")
|
||||
rules_rust.patch(
|
||||
patches = [
|
||||
"//patches:rules_rust_windows_gnullvm_build_script.patch",
|
||||
"//patches:rules_rust_windows_exec_msvc_build_script_env.patch",
|
||||
"//patches:rules_rust_windows_bootstrap_process_wrapper_linker.patch",
|
||||
"//patches:rules_rust_windows_build_script_runner_paths.patch",
|
||||
# Carry the OpenAI setup fix that makes build-script tools available
|
||||
# through their runfiles after the rules_rs upgrade.
|
||||
"//patches:rules_rust_build_script_tools_transition.patch",
|
||||
# Keep direct Windows/MSVC links compatible with hermetic LLVM's
|
||||
# non-.lib runtime artifacts.
|
||||
"//patches:rules_rust_windows_msvc_direct_link_args.patch",
|
||||
# Skip transient native-Windows linker outputs while consolidating
|
||||
# dependency search paths.
|
||||
"//patches:rules_rust_windows_process_wrapper_skip_temp_outputs.patch",
|
||||
"//patches:rules_rust_windows_exec_bin_target.patch",
|
||||
"//patches:rules_rust_windows_exec_std.patch",
|
||||
"//patches:rules_rust_windows_exec_rustc_dev_rlib.patch",
|
||||
],
|
||||
strip = 1,
|
||||
)
|
||||
use_repo(rules_rust, "rules_rust")
|
||||
|
||||
# argument-comment-lint uses rustc_private and needs nightly rustc-dev
|
||||
# components. Keep that rules_rust-reexported toolchain separate from the
|
||||
# default rules_rs toolchains below, which do not expose dev_components.
|
||||
nightly_rust = use_extension(
|
||||
"@rules_rs//rs/experimental:rules_rust_reexported_extensions.bzl",
|
||||
"@rules_rs//rs:rules_rust_reexported_extensions.bzl",
|
||||
"rust",
|
||||
)
|
||||
nightly_rust.toolchain(
|
||||
@@ -136,8 +130,8 @@ nightly_rust.toolchain(
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
|
||||
# Keep Windows exec tools on MSVC so Bazel helper binaries link correctly, but
|
||||
# lint crate targets as `windows-gnullvm` to preserve the repo's actual cfgs.
|
||||
# Keep the reexported extension's default Windows set constrained to MSVC so
|
||||
# it cannot also match the gnullvm host platform.
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64",
|
||||
dev_components = True,
|
||||
@@ -145,29 +139,55 @@ nightly_rust.repository_set(
|
||||
exec_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
exec_triple = "x86_64-pc-windows-msvc",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
target_triple = "x86_64-pc-windows-msvc",
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
|
||||
# Also let that MSVC-exec set target gnullvm for existing cross lanes.
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
target_triple = "x86_64-pc-windows-gnullvm",
|
||||
)
|
||||
|
||||
# Give Windows lint a native gnullvm exec set so proc-macros link against the
|
||||
# same ABI as hermetic LLVM and BCR AWS-LC.
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64_gnullvm",
|
||||
dev_components = True,
|
||||
edition = "2024",
|
||||
exec_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
exec_triple = "x86_64-pc-windows-gnullvm",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
"@llvm//constraints/windows/crt:msvcrt",
|
||||
],
|
||||
target_triple = "x86_64-pc-windows-gnullvm",
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
use_repo(nightly_rust, "rust_toolchains")
|
||||
|
||||
toolchains = use_extension("@rules_rs//rs/experimental/toolchains:module_extension.bzl", "toolchains")
|
||||
toolchains = use_extension("@rules_rs//rs/toolchains:module_extension.bzl", "toolchains")
|
||||
toolchains.toolchain(
|
||||
edition = "2024",
|
||||
version = "1.95.0",
|
||||
@@ -178,6 +198,14 @@ register_toolchains("@default_rust_toolchains//:all")
|
||||
|
||||
register_toolchains("@rust_toolchains//:all")
|
||||
|
||||
rules_rust_bindgen = use_extension(
|
||||
"@rules_rs//rs:rules_rust_bindgen.bzl",
|
||||
"rules_rust_bindgen",
|
||||
)
|
||||
use_repo(rules_rust_bindgen, "rules_rust_bindgen")
|
||||
|
||||
register_toolchains("@rules_rust_bindgen//:all")
|
||||
|
||||
crate = use_extension("@rules_rs//rs:extensions.bzl", "crate")
|
||||
crate.from_cargo(
|
||||
cargo_lock = "//codex-rs:Cargo.lock",
|
||||
@@ -197,7 +225,6 @@ crate.from_cargo(
|
||||
"x86_64-pc-windows-msvc",
|
||||
"x86_64-pc-windows-gnullvm",
|
||||
],
|
||||
use_experimental_platforms = True,
|
||||
)
|
||||
crate.from_cargo(
|
||||
name = "argument_comment_lint_crates",
|
||||
@@ -215,7 +242,6 @@ crate.from_cargo(
|
||||
"x86_64-pc-windows-msvc",
|
||||
"x86_64-pc-windows-gnullvm",
|
||||
],
|
||||
use_experimental_platforms = True,
|
||||
)
|
||||
|
||||
bazel_dep(name = "zstd", version = "1.5.7")
|
||||
@@ -243,16 +269,18 @@ crate.annotation(
|
||||
],
|
||||
)
|
||||
crate.annotation(
|
||||
build_script_env = {
|
||||
"AWS_LC_SYS_NO_JITTER_ENTROPY": "1",
|
||||
},
|
||||
additive_build_file = "@rules_rs//3rd_party/aws-lc-sys:additive.BUILD.bazel",
|
||||
crate = "aws-lc-sys",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
"//patches:aws-lc-sys_memcmp_check.patch",
|
||||
"//patches:aws-lc-sys_windows_msvc_prebuilt_nasm.patch",
|
||||
"//patches:aws-lc-sys_windows_msvc_memcmp_probe.patch",
|
||||
],
|
||||
extra_aliased_targets = {"aws_lc_sys_build_info": "aws_lc_sys_build_info"},
|
||||
gen_build_script = "off",
|
||||
repositories = ["crates"],
|
||||
rustc_flags = ["--cfg=use_bindgen_pregenerated"],
|
||||
deps = ["@crates//:aws_lc_sys_build_info"],
|
||||
)
|
||||
crate.annotation(
|
||||
crate = "aws-lc-rs",
|
||||
gen_build_script = "off",
|
||||
repositories = ["crates"],
|
||||
)
|
||||
crate.annotation(
|
||||
# The build script only validates embedded source/version metadata.
|
||||
@@ -260,6 +288,8 @@ crate.annotation(
|
||||
gen_build_script = "off",
|
||||
)
|
||||
|
||||
inject_repo(crate, "aws-lc")
|
||||
|
||||
inject_repo(crate, "zstd")
|
||||
|
||||
use_repo(crate, "argument_comment_lint_crates")
|
||||
|
||||
237
MODULE.bazel.lock
generated
237
MODULE.bazel.lock
generated
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@ load("//:defs.bzl", "codex_rust_crate")
|
||||
codex_rust_crate(
|
||||
name = "v8-poc",
|
||||
crate_features = select({
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc": [],
|
||||
"@llvm//constraints/windows/abi:msvc": [],
|
||||
"//conditions:default": ["sandbox"],
|
||||
}),
|
||||
crate_name = "codex_v8_poc",
|
||||
|
||||
8
defs.bzl
8
defs.bzl
@@ -13,8 +13,8 @@ WINDOWS_GNULLVM_RUSTC_LINK_FLAGS = [
|
||||
]
|
||||
|
||||
WINDOWS_RUSTC_LINK_FLAGS = select({
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": WINDOWS_GNULLVM_RUSTC_LINK_FLAGS,
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc": [
|
||||
"@llvm//constraints/windows/abi:gnullvm": WINDOWS_GNULLVM_RUSTC_LINK_FLAGS,
|
||||
"@llvm//constraints/windows/abi:msvc": [
|
||||
"-C",
|
||||
"link-arg=/STACK:8388608", # 8 MiB
|
||||
"-C",
|
||||
@@ -26,12 +26,12 @@ WINDOWS_RUSTC_LINK_FLAGS = select({
|
||||
})
|
||||
|
||||
WINDOWS_GNULLVM_INCOMPATIBLE = select({
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": ["@platforms//:incompatible"],
|
||||
"@llvm//constraints/windows/abi:gnullvm": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
WINDOWS_GNULLVM_ONLY = select({
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": [],
|
||||
"@llvm//constraints/windows/abi:gnullvm": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
})
|
||||
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
exports_files([
|
||||
"abseil_windows_gnullvm_thread_identity.patch",
|
||||
"aws-lc-sys_memcmp_check.patch",
|
||||
"aws-lc-sys_windows_msvc_prebuilt_nasm.patch",
|
||||
"aws-lc-sys_windows_msvc_memcmp_probe.patch",
|
||||
"bzip2_windows_stack_args.patch",
|
||||
"llvm_rusty_v8_custom_libcxx.patch",
|
||||
"llvm_windows_arm64_powl.patch",
|
||||
"llvm_windows_mingw_compat.patch",
|
||||
"rules_rust_windows_bootstrap_process_wrapper_linker.patch",
|
||||
"rules_rust_windows_build_script_runner_paths.patch",
|
||||
"rules_rust_windows_exec_bin_target.patch",
|
||||
"rules_rust_windows_exec_std.patch",
|
||||
"rules_rust_windows_process_wrapper_skip_temp_outputs.patch",
|
||||
"rules_rust_build_script_tools_transition.patch",
|
||||
"rules_rust_windows_msvc_direct_link_args.patch",
|
||||
"rules_rust_windows_gnullvm_build_script.patch",
|
||||
"rules_rust_windows_process_wrapper_skip_temp_outputs.patch",
|
||||
"rules_cc_rusty_v8_custom_libcxx.patch",
|
||||
"rules_rs_build_script_deps_annotation.patch",
|
||||
"rules_rs_windows_gnullvm_exec.patch",
|
||||
"rules_rs_windows_exec_linker.patch",
|
||||
"rusty_v8_prebuilt_out_dir.patch",
|
||||
"ring_windows_msvc_include_dirs.patch",
|
||||
"v8_bazel_rules.patch",
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
diff --git a/builder/cc_builder.rs b/builder/cc_builder.rs
|
||||
--- a/builder/cc_builder.rs
|
||||
+++ b/builder/cc_builder.rs
|
||||
@@ -26,7 +26,7 @@
|
||||
};
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashMap;
|
||||
-use std::path::PathBuf;
|
||||
+use std::path::{Path, PathBuf};
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -681,6 +681,16 @@
|
||||
}
|
||||
let mut memcmp_compile_args = Vec::from(memcmp_compiler.args());
|
||||
|
||||
+ // Keep the probe self-contained and avoid invoking external debug tools
|
||||
+ // (for example `dsymutil`) that may be missing in hermetic sandboxes.
|
||||
+ memcmp_compile_args.retain(|arg| {
|
||||
+ let Some(arg_str) = arg.to_str() else {
|
||||
+ return true;
|
||||
+ };
|
||||
+ !arg_str.starts_with("-g")
|
||||
+ });
|
||||
+ memcmp_compile_args.push("-g0".into());
|
||||
+
|
||||
// This check invokes the compiled executable and hence needs to link
|
||||
// it. CMake handles this via LDFLAGS but `cc` doesn't. In setups with
|
||||
// custom linker setups this could lead to a mismatch between the
|
||||
@@ -692,6 +702,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ if let Some(execroot) = Self::bazel_execroot(self.manifest_dir.as_path()) {
|
||||
+ // In Bazel build-script sandboxes, `cc` can pass `bazel-out/...` args
|
||||
+ // relative to the execroot while the process runs from elsewhere.
|
||||
+ // Normalize those args to absolute paths so this check can still link.
|
||||
+ for arg in &mut memcmp_compile_args {
|
||||
+ Self::rewrite_bazel_execroot_arg(execroot.as_path(), arg);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
memcmp_compile_args.push(
|
||||
self.manifest_dir
|
||||
.join("aws-lc")
|
||||
@@ -742,6 +761,40 @@
|
||||
);
|
||||
let _ = fs::remove_file(exec_path);
|
||||
}
|
||||
+
|
||||
+ fn rewrite_bazel_execroot_arg(execroot: &Path, arg: &mut std::ffi::OsString) {
|
||||
+ let Some(arg_str) = arg.to_str() else {
|
||||
+ return;
|
||||
+ };
|
||||
+
|
||||
+ if arg_str.starts_with("bazel-out/") {
|
||||
+ *arg = execroot.join(arg_str).into_os_string();
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ for flag_prefix in ["-B", "-L"] {
|
||||
+ if let Some(path) = arg_str.strip_prefix(flag_prefix) {
|
||||
+ if path.starts_with("bazel-out/") {
|
||||
+ *arg = format!("{flag_prefix}{}", execroot.join(path).display()).into();
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ fn bazel_execroot(path: &Path) -> Option<PathBuf> {
|
||||
+ let mut prefix = PathBuf::new();
|
||||
+ for component in path.components() {
|
||||
+ if component.as_os_str() == "bazel-out" {
|
||||
+ return Some(prefix);
|
||||
+ }
|
||||
+
|
||||
+ prefix.push(component.as_os_str());
|
||||
+ }
|
||||
+
|
||||
+ None
|
||||
+ }
|
||||
+
|
||||
fn run_compiler_checks(&self, cc_build: &mut cc::Build) {
|
||||
if self.compiler_check("stdalign_check", Vec::<&'static str>::new()) {
|
||||
cc_build.define("AWS_LC_STDALIGN_AVAILABLE", Some("1"));
|
||||
diff --git a/builder/main.rs b/builder/main.rs
|
||||
--- a/builder/main.rs
|
||||
+++ b/builder/main.rs
|
||||
@@ -944,10 +944,12 @@
|
||||
// iterate over all the include paths and copy them into the final output
|
||||
for path in include_paths {
|
||||
for child in std::fs::read_dir(path).into_iter().flatten().flatten() {
|
||||
- if child.file_type().map_or(false, |t| t.is_file()) {
|
||||
+ let child_path = child.path();
|
||||
+
|
||||
+ if child_path.is_file() {
|
||||
std::fs::copy(
|
||||
- child.path(),
|
||||
- include_dir.join(child.path().file_name().unwrap()),
|
||||
+ &child_path,
|
||||
+ include_dir.join(child_path.file_name().unwrap()),
|
||||
)
|
||||
.expect("Failed to copy include file during build setup");
|
||||
continue;
|
||||
@@ -957,7 +959,7 @@
|
||||
let options = fs_extra::dir::CopyOptions::new()
|
||||
.skip_exist(true)
|
||||
.copy_inside(true);
|
||||
- fs_extra::dir::copy(child.path(), &include_dir, &options)
|
||||
+ fs_extra::dir::copy(child_path, &include_dir, &options)
|
||||
.expect("Failed to copy include directory during build setup");
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
diff --git a/builder/cc_builder.rs b/builder/cc_builder.rs
|
||||
--- a/builder/cc_builder.rs
|
||||
+++ b/builder/cc_builder.rs
|
||||
@@ -667,12 +667,24 @@
|
||||
if cargo_env("HOST") != target() {
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ let bazel_execroot = Self::bazel_execroot(self.manifest_dir.as_path());
|
||||
+ if bazel_execroot.is_some() && target().ends_with("windows-msvc") {
|
||||
+ // This probe guards a GCC memcmp miscompile. Under Bazel's
|
||||
+ // hermetic Windows/MSVC build-script toolchain we drive clang with
|
||||
+ // MinGW-flavored CFLAGS, which is good enough for compiling
|
||||
+ // aws-lc but not for linking and executing this standalone test
|
||||
+ // binary. Skip the probe in that configuration instead of failing
|
||||
+ // the whole build script.
|
||||
+ emit_warning("Skipping memcmp probe for Bazel windows-msvc build scripts.");
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
let basename = "memcmp_invalid_stripped_check";
|
||||
let exec_path = out_dir().join(basename);
|
||||
let memcmp_build = cc::Build::default();
|
||||
let memcmp_compiler = memcmp_build.get_compiler();
|
||||
if !memcmp_compiler.is_like_clang() && !memcmp_compiler.is_like_gnu() {
|
||||
// The logic below assumes a Clang or GCC compiler is in use
|
||||
return;
|
||||
}
|
||||
@@ -701,7 +713,7 @@
|
||||
memcmp_compile_args.push(flag.into());
|
||||
}
|
||||
}
|
||||
|
||||
- if let Some(execroot) = Self::bazel_execroot(self.manifest_dir.as_path()) {
|
||||
+ if let Some(execroot) = bazel_execroot {
|
||||
// In Bazel build-script sandboxes, `cc` can pass `bazel-out/...` args
|
||||
// relative to the execroot while the process runs from elsewhere.
|
||||
// Normalize those args to absolute paths so this check can still link.
|
||||
@@ -1,137 +0,0 @@
|
||||
diff --git a/builder/cc_builder.rs b/builder/cc_builder.rs
|
||||
index 95cacb0..d5d814b 100644
|
||||
--- a/builder/cc_builder.rs
|
||||
+++ b/builder/cc_builder.rs
|
||||
@@ -20,9 +20,10 @@ mod win_x86_64;
|
||||
use crate::nasm_builder::NasmBuilder;
|
||||
use crate::{
|
||||
cargo_env, disable_jitter_entropy, emit_warning, env_name_for_target, env_var_to_bool,
|
||||
- execute_command, get_crate_cc, get_crate_cflags, get_crate_cxx, is_no_asm, out_dir,
|
||||
- requested_c_std, set_env_for_target, target, target_arch, target_env, target_os, target_vendor,
|
||||
- test_clang_cl_command, CStdRequested, EnvGuard, OutputLibType,
|
||||
+ execute_command, get_crate_cc, get_crate_cflags, get_crate_cxx,
|
||||
+ is_bazel_windows_msvc_build_script, is_no_asm, out_dir, requested_c_std, set_env_for_target,
|
||||
+ target, target_arch, target_env, target_os, target_vendor, test_clang_cl_command,
|
||||
+ CStdRequested, EnvGuard, OutputLibType,
|
||||
};
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashMap;
|
||||
@@ -769,6 +770,30 @@ impl CcBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
+fn configure_windows_msvc_clang_cl() {
|
||||
+ let should_use_clang_cl = target_os() == "windows"
|
||||
+ && target_env() == "msvc"
|
||||
+ && (target_arch() == "aarch64" || is_bazel_windows_msvc_build_script());
|
||||
+ if !should_use_clang_cl {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ let clang_cl = if test_clang_cl_command() {
|
||||
+ Some(String::from("clang-cl"))
|
||||
+ } else {
|
||||
+ let system_clang_cl = PathBuf::from(r"C:\Program Files\LLVM\bin\clang-cl.exe");
|
||||
+ system_clang_cl.is_file().then(|| system_clang_cl.display().to_string())
|
||||
+ };
|
||||
+ if let Some(clang_cl) = clang_cl {
|
||||
+ if get_crate_cc().is_none() {
|
||||
+ set_env_for_target("CC", &clang_cl);
|
||||
+ }
|
||||
+ if get_crate_cxx().is_none() {
|
||||
+ set_env_for_target("CXX", &clang_cl);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
impl crate::Builder for CcBuilder {
|
||||
fn check_dependencies(&self) -> Result<(), String> {
|
||||
if OutputLibType::Dynamic == self.output_lib_type {
|
||||
@@ -784,18 +809,12 @@ impl crate::Builder for CcBuilder {
|
||||
return Err("cc_builder for libssl not supported".to_string());
|
||||
}
|
||||
|
||||
+ configure_windows_msvc_clang_cl();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build(&self) -> Result<(), String> {
|
||||
- if target_os() == "windows"
|
||||
- && target_arch() == "aarch64"
|
||||
- && target_env() == "msvc"
|
||||
- && get_crate_cc().is_none()
|
||||
- && test_clang_cl_command()
|
||||
- {
|
||||
- set_env_for_target("CC", "clang-cl");
|
||||
- }
|
||||
+ configure_windows_msvc_clang_cl();
|
||||
|
||||
println!("cargo:root={}", self.out_dir.display());
|
||||
let sources = crate::cc_builder::identify_sources();
|
||||
|
||||
diff --git a/builder/main.rs b/builder/main.rs
|
||||
index 51a9bc1..e714ba4 100644
|
||||
--- a/builder/main.rs
|
||||
+++ b/builder/main.rs
|
||||
@@ -723,14 +723,31 @@ fn get_crate_cflags() -> Option<String> {
|
||||
.or(optional_env_optional_crate_target("CFLAGS"))
|
||||
}
|
||||
|
||||
+pub(crate) fn is_bazel_windows_msvc_build_script() -> bool {
|
||||
+ if !target().ends_with("windows-msvc") {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ if optional_env("RULES_RUST_BAZEL_BUILD_SCRIPT_RUNNER").is_some() {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ let cargo_manifest_dir = cargo_env("CARGO_MANIFEST_DIR");
|
||||
+ let manifest_dir = Path::new(&cargo_manifest_dir);
|
||||
+ manifest_dir
|
||||
+ .components()
|
||||
+ .any(|component| component.as_os_str() == "bazel-out")
|
||||
+}
|
||||
+
|
||||
fn use_prebuilt_nasm() -> bool {
|
||||
+ let use_prebuilt_for_bazel_windows_msvc = is_bazel_windows_msvc_build_script();
|
||||
target_os() == "windows"
|
||||
&& target_arch() == "x86_64"
|
||||
&& !is_no_asm()
|
||||
- && !test_nasm_command() // NASM not found in environment
|
||||
&& Some(false) != allow_prebuilt_nasm() // not prevented by environment
|
||||
&& !is_disable_prebuilt_nasm() // not prevented by feature
|
||||
// permitted by environment or by feature
|
||||
+ && (use_prebuilt_for_bazel_windows_msvc || !test_nasm_command())
|
||||
&& (Some(true) == allow_prebuilt_nasm() || is_prebuilt_nasm())
|
||||
}
|
||||
|
||||
@@ -817,8 +834,12 @@ fn main() {
|
||||
initialize();
|
||||
prepare_cargo_cfg();
|
||||
|
||||
- let manifest_dir = current_dir();
|
||||
- let manifest_dir = dunce::canonicalize(Path::new(&manifest_dir)).unwrap();
|
||||
+ let manifest_dir = if is_bazel_windows_msvc_build_script() {
|
||||
+ PathBuf::from(cargo_env("CARGO_MANIFEST_DIR"))
|
||||
+ } else {
|
||||
+ let manifest_dir = current_dir();
|
||||
+ dunce::canonicalize(Path::new(&manifest_dir)).unwrap()
|
||||
+ };
|
||||
let prefix_str = prefix_string();
|
||||
let prefix = if is_no_prefix() {
|
||||
None
|
||||
|
||||
diff --git a/builder/nasm_builder.rs b/builder/nasm_builder.rs
|
||||
index cf1f5c8..f683274 100644
|
||||
--- a/builder/nasm_builder.rs
|
||||
+++ b/builder/nasm_builder.rs
|
||||
@@ -57,7 +57,7 @@ impl NasmBuilder {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
- if test_nasm_command() {
|
||||
+ if test_nasm_command() && !use_prebuilt_nasm() {
|
||||
for src in &self.files {
|
||||
let obj_name = src
|
||||
.file_name()
|
||||
@@ -1,50 +1,77 @@
|
||||
diff --git a/toolchain/BUILD.bazel b/toolchain/BUILD.bazel
|
||||
index fa00156236..bf0ee9d368 100644
|
||||
index fa00156236..c9e4348172 100644
|
||||
--- a/toolchain/BUILD.bazel
|
||||
+++ b/toolchain/BUILD.bazel
|
||||
@@ -222,11 +222,16 @@ cc_args_list(
|
||||
@@ -1,5 +1,6 @@
|
||||
load("@bazel_lib//:bzl_library.bzl", "bzl_library")
|
||||
+load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_setting")
|
||||
load("@rules_cc//cc/toolchains:actions.bzl", "cc_action_type_set")
|
||||
load("@rules_cc//cc/toolchains:artifacts.bzl", "cc_artifact_name_pattern")
|
||||
load("@rules_cc//cc/toolchains/impl:documented_api.bzl", "cc_args_list")
|
||||
@@ -64,6 +65,15 @@ config_setting(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
-
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "runtimes_all_with_rusty_v8_custom_libcxx",
|
||||
+ match_all = [
|
||||
+ ":runtimes_all",
|
||||
+ "@@//third_party/v8:use_rusty_v8_custom_libcxx",
|
||||
+ ],
|
||||
+ visibility = ["//visibility:public"],
|
||||
+)
|
||||
+
|
||||
config_setting(
|
||||
name = "runtimes_stage1",
|
||||
flag_values = {
|
||||
@@ -270,11 +280,16 @@ cc_args_list(
|
||||
|
||||
# TODO(cerisier): extract those into proper semantic args list.
|
||||
# TODO(zbarsky): This must match llvm/toolchains/llvm.bzl
|
||||
+_DEFAULT_LIBCXX_HEADER_ARGS = select({
|
||||
+_DEFAULT_CXXSTDLIB_HEADER_ARGS = select({
|
||||
+ "@@//third_party/v8:use_rusty_v8_custom_libcxx": [],
|
||||
+ "//conditions:default": [
|
||||
+ "//toolchain/args:libcxx_headers_include_search_paths",
|
||||
+ "//toolchain/args:cxxstdlib_headers_include_search_paths",
|
||||
+ ],
|
||||
+})
|
||||
+
|
||||
cc_args_list(
|
||||
name = "linux_toolchain_args",
|
||||
- args = [
|
||||
- "//toolchain/args:libcxx_headers_include_search_paths",
|
||||
- "//toolchain/args:cxxstdlib_headers_include_search_paths",
|
||||
- ] + select({
|
||||
+ args = _DEFAULT_LIBCXX_HEADER_ARGS + select({
|
||||
+ args = _DEFAULT_CXXSTDLIB_HEADER_ARGS + select({
|
||||
"//platforms/config:musl": [
|
||||
"//toolchain/args/linux:kernel_headers_include_search_paths",
|
||||
"//toolchain/args/linux:musl_libc_headers_include_search_paths",
|
||||
@@ -252,8 +257,7 @@ cc_args_list(
|
||||
@@ -302,8 +317,7 @@ cc_args_list(
|
||||
# TODO(zbarsky): This must match llvm/toolchains/llvm.bzl
|
||||
cc_args_list(
|
||||
name = "windows_toolchain_args",
|
||||
- args = [
|
||||
- "//toolchain/args:libcxx_headers_include_search_paths",
|
||||
+ args = _DEFAULT_LIBCXX_HEADER_ARGS + [
|
||||
- "//toolchain/args:cxxstdlib_headers_include_search_paths",
|
||||
+ args = _DEFAULT_CXXSTDLIB_HEADER_ARGS + [
|
||||
"//toolchain/args/windows:mingw_headers_include_search_paths",
|
||||
],
|
||||
)
|
||||
diff --git a/toolchain/llvm/llvm.bzl b/toolchain/llvm/llvm.bzl
|
||||
index d36d8b94bd..97aa879d4a 100644
|
||||
index d36d8b94bd..900aa908d5 100644
|
||||
--- a/toolchain/llvm/llvm.bzl
|
||||
+++ b/toolchain/llvm/llvm.bzl
|
||||
@@ -186,16 +186,22 @@ def declare_llvm_targets(*, suffix = ""):
|
||||
@@ -297,18 +297,23 @@ def declare_llvm_targets(*, suffix = ""):
|
||||
],
|
||||
)
|
||||
|
||||
+ default_libcxx_target_headers = select({
|
||||
+ "@@//third_party/v8:use_rusty_v8_custom_libcxx": [],
|
||||
+ default_cxxstdlib_target_headers = select({
|
||||
+ "@llvm//toolchain:runtimes_all_with_rusty_v8_custom_libcxx": [],
|
||||
+ "@llvm//toolchain:runtimes_stage1": [],
|
||||
+ "@llvm//toolchain:runtimes_stage1_hosted": [],
|
||||
+ "@llvm//toolchain:runtimes_none": [],
|
||||
+ "//conditions:default": [
|
||||
+ "@llvm//runtimes/libcxx:libcxx_headers_include_search_directory",
|
||||
+ "@llvm//runtimes/libcxx:libcxxabi_headers_include_search_directory",
|
||||
+ "@llvm//runtimes/cxxstdlib:headers_include_search_directory",
|
||||
+ "@llvm//runtimes/cxxstdlib:abi_headers_include_search_directory",
|
||||
+ ],
|
||||
+ })
|
||||
+
|
||||
@@ -53,27 +80,29 @@ index d36d8b94bd..97aa879d4a 100644
|
||||
name = "linux_target_headers",
|
||||
srcs = [
|
||||
":builtin_resource_dir",
|
||||
- "@llvm//runtimes/libcxx:libcxx_headers_include_search_directory",
|
||||
- "@llvm//runtimes/libcxx:libcxxabi_headers_include_search_directory",
|
||||
- ] + select({
|
||||
- "@llvm//toolchain:runtimes_all": [
|
||||
- "@llvm//runtimes/cxxstdlib:headers_include_search_directory",
|
||||
- "@llvm//runtimes/cxxstdlib:abi_headers_include_search_directory",
|
||||
- ],
|
||||
- "//conditions:default": [],
|
||||
- }) + [
|
||||
+ ] + default_cxxstdlib_target_headers + [
|
||||
"@kernel_headers//:kernel_headers_directory",
|
||||
"@llvm//sanitizers:sanitizers_headers_include_search_directory",
|
||||
- ] + select({
|
||||
+ ] + default_libcxx_target_headers + select({
|
||||
"@llvm//platforms/config:musl": [
|
||||
"@llvm//runtimes/musl:musl_headers_include_search_directory",
|
||||
],
|
||||
@@ -210,13 +216,11 @@ def declare_llvm_targets(*, suffix = ""):
|
||||
] + select({
|
||||
@@ -324,13 +329,7 @@ def declare_llvm_targets(*, suffix = ""):
|
||||
name = "windows_target_headers",
|
||||
srcs = [
|
||||
":builtin_resource_dir",
|
||||
- "@llvm//runtimes/libcxx:libcxx_headers_include_search_directory",
|
||||
- "@llvm//runtimes/libcxx:libcxxabi_headers_include_search_directory",
|
||||
- ] + select({
|
||||
- "@llvm//toolchain:runtimes_all": [
|
||||
- "@llvm//runtimes/cxxstdlib:headers_include_search_directory",
|
||||
- "@llvm//runtimes/cxxstdlib:abi_headers_include_search_directory",
|
||||
- ],
|
||||
- "//conditions:default": [],
|
||||
- }) + [
|
||||
+ ] + default_cxxstdlib_target_headers + [
|
||||
"@mingw//:mingw_generated_headers_crt_directory",
|
||||
"@mingw//:mingw_w64_headers_include_directory",
|
||||
"@mingw//:mingw_w64_headers_crt_directory",
|
||||
"@mingw//:mingw_w64_winpthreads_include_directory",
|
||||
- ],
|
||||
+ ] + default_libcxx_target_headers,
|
||||
)
|
||||
|
||||
include_path(
|
||||
|
||||
@@ -2,15 +2,13 @@ diff --git a/build.rs b/build.rs
|
||||
index 9843ad8aa..573075489 100644
|
||||
--- a/build.rs
|
||||
+++ b/build.rs
|
||||
@@ -346,7 +346,29 @@ fn ring_build_rs_main(c_root_dir: &Path, core_name_and_version: &str) {
|
||||
@@ -346,7 +346,28 @@ fn ring_build_rs_main(c_root_dir: &Path, core_name_and_version: &str) {
|
||||
// we want to optimize for minimizing the build tools required: No Perl,
|
||||
// no nasm, etc.
|
||||
let generated_dir = if !is_git {
|
||||
- c_root_dir.join(PREGENERATED)
|
||||
+ let pregenerated_dir = c_root_dir.join(PREGENERATED);
|
||||
+ if target.os == WINDOWS
|
||||
+ && target.env == "msvc"
|
||||
+ && env::var_os("RULES_RUST_BAZEL_BUILD_SCRIPT_RUNNER").is_some()
|
||||
+ if target.os == WINDOWS && target.env == "msvc"
|
||||
+ {
|
||||
+ let mut pending = vec![(pregenerated_dir.clone(), out_dir.clone())];
|
||||
+ while let Some((src_dir, dst_dir)) = pending.pop() {
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
# What: expose the existing unconditional build-script dependency input through
|
||||
# the `rules_rs` crate annotation API.
|
||||
# Scope: annotation plumbing only; generated dependency resolution is unchanged.
|
||||
# What: restore explicit build-script dependency annotations used by Codex.
|
||||
# Scope: rules_rs crate-universe annotation plumbing only.
|
||||
|
||||
diff --git a/rs/extensions.bzl b/rs/extensions.bzl
|
||||
--- a/rs/extensions.bzl
|
||||
+++ b/rs/extensions.bzl
|
||||
@@ -737,7 +737,7 @@ def _generate_hub_and_spokes(
|
||||
additive_build_file = annotation.additive_build_file,
|
||||
additive_build_file_content = annotation.additive_build_file_content,
|
||||
@@ -321,7 +321,7 @@ def _generate_hub_and_spokes(
|
||||
kwargs = dict(
|
||||
hub_name = hub_name,
|
||||
gen_build_script = annotation.gen_build_script,
|
||||
- build_script_deps = [],
|
||||
+ build_script_deps = annotation.build_script_deps,
|
||||
build_script_deps_select = _select(feature_resolutions.build_deps),
|
||||
build_script_data = annotation.build_script_data,
|
||||
build_script_data_select = annotation.build_script_data_select,
|
||||
@@ -1417,9 +1417,9 @@ _annotation = tag_class(
|
||||
"build_script_data_select": attr.string_list_dict(
|
||||
doc = "A list of labels to add to a crate's `cargo_build_script::data` attribute. Keys should be the platform triplet. Value should be a list of labels.",
|
||||
@@ -881,9 +881,9 @@ _annotation = tag_class(
|
||||
"build_script_data_select": _label_list_dict(
|
||||
doc = "Labels to add to a crate's `cargo_build_script::data` attribute, keyed by platform triplet.",
|
||||
),
|
||||
- # "build_script_deps": _relative_label_list(
|
||||
- # "build_script_deps": attr.label_list(
|
||||
- # doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute.",
|
||||
- # ),
|
||||
+ "build_script_deps": _relative_label_list(
|
||||
+ "build_script_deps": attr.string_list(
|
||||
+ doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute.",
|
||||
+ ),
|
||||
"build_script_env": attr.string_dict(
|
||||
@@ -30,31 +29,30 @@ diff --git a/rs/extensions.bzl b/rs/extensions.bzl
|
||||
diff --git a/rs/private/annotations.bzl b/rs/private/annotations.bzl
|
||||
--- a/rs/private/annotations.bzl
|
||||
+++ b/rs/private/annotations.bzl
|
||||
@@ -5,6 +5,7 @@ def _crate_annotation(
|
||||
@@ -2,6 +2,7 @@ def _crate_annotation(
|
||||
additive_build_file = None,
|
||||
additive_build_file_content = "",
|
||||
gen_build_script = "auto",
|
||||
+ build_script_deps = [],
|
||||
build_script_data = [],
|
||||
build_script_data_select = {},
|
||||
+ build_script_deps = [],
|
||||
build_script_env = {},
|
||||
build_script_env_select = {},
|
||||
build_script_tools = [],
|
||||
@@ -28,6 +29,7 @@ def _crate_annotation(
|
||||
@@ -30,6 +31,7 @@ def _crate_annotation(
|
||||
additive_build_file = additive_build_file,
|
||||
additive_build_file_content = additive_build_file_content,
|
||||
gen_build_script = gen_build_script,
|
||||
+ build_script_deps = build_script_deps,
|
||||
build_script_data = build_script_data,
|
||||
build_script_data_select = build_script_data_select,
|
||||
+ build_script_deps = build_script_deps,
|
||||
build_script_env = build_script_env,
|
||||
build_script_env_select = build_script_env_select,
|
||||
build_script_tools = build_script_tools,
|
||||
diff --git a/rs/private/repository_utils.bzl b/rs/private/repository_utils.bzl
|
||||
--- a/rs/private/repository_utils.bzl
|
||||
+++ b/rs/private/repository_utils.bzl
|
||||
@@ -216,7 +216,7 @@ common_attrs = {
|
||||
"additive_build_file": attr.label(),
|
||||
"additive_build_file_content": attr.string(),
|
||||
@@ -298,6 +298,6 @@ rust_crate_attrs = {
|
||||
"hub_name": attr.string(),
|
||||
"gen_build_script": attr.string(),
|
||||
- "build_script_deps": attr.label_list(default = []),
|
||||
+ "build_script_deps": attr.string_list(default = []),
|
||||
"build_script_deps_select": attr.string_list_dict(),
|
||||
"build_script_data": attr.label_list(default = []),
|
||||
"build_script_data_select": attr.string_list_dict(),
|
||||
- "build_script_deps": attr.label_list(),
|
||||
+ "build_script_deps": attr.string_list(),
|
||||
"build_script_deps_select": _label_list_dict(),
|
||||
"build_script_data": attr.label_list(),
|
||||
"build_script_data_select": _label_list_dict(),
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
# What: use a working Windows direct linker for `rules_rs` exec toolchains and
|
||||
# preserve the Windows stdlib link flags the stable wrapper was dropping.
|
||||
# Scope: Windows-only linker metadata for the generated `rules_rs` toolchains.
|
||||
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -58,6 +58,8 @@ def declare_rustc_toolchains(
|
||||
rust_toolchain(
|
||||
name = rust_toolchain_name,
|
||||
rust_doc = "{}rustdoc".format(rustc_repo_label),
|
||||
+ linker = "{}rust-lld".format(rustc_repo_label) if exec_triple.system == "windows" else None,
|
||||
+ linker_type = "direct" if exec_triple.system == "windows" else None,
|
||||
rust_std = select(rust_std_select),
|
||||
rustc = "{}rustc".format(rustc_repo_label),
|
||||
cargo = "{}cargo".format(cargo_repo_label),
|
||||
@@ -104,7 +106,20 @@ def declare_rustc_toolchains(
|
||||
"@platforms//os:nixos": ["-ldl", "-lpthread"],
|
||||
"@platforms//os:openbsd": ["-lpthread"],
|
||||
"@platforms//os:ios": ["-lSystem", "-lobjc", "-Wl,-framework,Security", "-Wl,-framework,Foundation", "-lresolv"],
|
||||
- # TODO: windows
|
||||
+ "@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": [
|
||||
+ "advapi32.lib",
|
||||
+ "ws2_32.lib",
|
||||
+ "userenv.lib",
|
||||
+ "Bcrypt.lib",
|
||||
+ ],
|
||||
+ "@rules_rs//rs/experimental/platforms/constraints:windows_msvc": [
|
||||
+ "advapi32.lib",
|
||||
+ "ws2_32.lib",
|
||||
+ "userenv.lib",
|
||||
+ "Bcrypt.lib",
|
||||
+ "ucrt.lib",
|
||||
+ ],
|
||||
+ # TODO: other platforms
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
default_edition = edition,
|
||||
diff --git a/rs/private/rustc_repository.bzl b/rs/private/rustc_repository.bzl
|
||||
--- a/rs/private/rustc_repository.bzl
|
||||
+++ b/rs/private/rustc_repository.bzl
|
||||
@@ -7,10 +7,24 @@ load(
|
||||
)
|
||||
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
|
||||
+
|
||||
+_WINDOWS_EXEC_LINKER_BUILD = """
|
||||
+filegroup(
|
||||
+ name = "rust-lld",
|
||||
+ srcs = ["bin/lld-link.exe"],
|
||||
+ visibility = ["//visibility:public"],
|
||||
+)
|
||||
+"""
|
||||
|
||||
def _rustc_repository_impl(rctx):
|
||||
exec_triple = triple(rctx.attr.triple)
|
||||
download_and_extract(rctx, "rustc", "rustc", exec_triple)
|
||||
build_content = [BUILD_for_compiler(exec_triple)]
|
||||
+ if exec_triple.system == "windows":
|
||||
+ lld_link = rctx.which("lld-link.exe")
|
||||
+ if lld_link == None:
|
||||
+ fail("lld-link.exe not found on PATH")
|
||||
+ rctx.symlink(lld_link, "bin/lld-link.exe")
|
||||
+ build_content.append(_WINDOWS_EXEC_LINKER_BUILD)
|
||||
if includes_rust_analyzer_proc_macro_srv(rctx.attr.version, rctx.attr.iso_date):
|
||||
build_content.append(BUILD_for_rust_analyzer_proc_macro_srv(exec_triple))
|
||||
rctx.file("BUILD.bazel", "\n".join(build_content))
|
||||
@@ -1,212 +0,0 @@
|
||||
# What: teach `rules_rs` that `windows-gnullvm` is a distinct Windows exec ABI.
|
||||
# Scope: experimental platform/toolchain naming only; no Cargo target changes.
|
||||
|
||||
diff --git a/rs/experimental/platforms/triples.bzl b/rs/experimental/platforms/triples.bzl
|
||||
--- a/rs/experimental/platforms/triples.bzl
|
||||
+++ b/rs/experimental/platforms/triples.bzl
|
||||
@@ -30,7 +30,9 @@ SUPPORTED_EXEC_TRIPLES = [
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"x86_64-pc-windows-msvc",
|
||||
+ "x86_64-pc-windows-gnullvm",
|
||||
"aarch64-pc-windows-msvc",
|
||||
+ "aarch64-pc-windows-gnullvm",
|
||||
"x86_64-apple-darwin",
|
||||
"aarch64-apple-darwin",
|
||||
]
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -9,6 +9,11 @@ def _channel(version):
|
||||
if version.startswith("beta"):
|
||||
return "beta"
|
||||
return "stable"
|
||||
+
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
+ return "{}_{}_{}".format(exec_triple.system, exec_triple.arch, exec_triple.abi)
|
||||
+ return "{}_{}".format(exec_triple.system, exec_triple.arch)
|
||||
|
||||
def _rustc_flags_to_select(rustc_flags_by_triple):
|
||||
return select(
|
||||
@@ -31,15 +36,14 @@ def declare_rustc_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rustc_repo_label = "@rustc_{}_{}//:".format(triple_suffix, version_key)
|
||||
cargo_repo_label = "@cargo_{}_{}//:".format(triple_suffix, version_key)
|
||||
clippy_repo_label = "@clippy_{}_{}//:".format(triple_suffix, version_key)
|
||||
|
||||
- rust_toolchain_name = "{}_{}_{}_rust_toolchain".format(
|
||||
- exec_triple.system,
|
||||
- exec_triple.arch,
|
||||
+ rust_toolchain_name = "{}_{}_rust_toolchain".format(
|
||||
+ triple_suffix,
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -116,11 +120,8 @@ def declare_rustc_toolchains(
|
||||
target_key = sanitize_triple(target_triple)
|
||||
|
||||
native.toolchain(
|
||||
- name = "{}_{}_to_{}_{}".format(exec_triple.system, exec_triple.arch, target_key, version_key),
|
||||
- exec_compatible_with = [
|
||||
- "@platforms//os:" + exec_triple.system,
|
||||
- "@platforms//cpu:" + exec_triple.arch,
|
||||
- ],
|
||||
+ name = "{}_to_{}_{}".format(triple_suffix, target_key, version_key),
|
||||
+ exec_compatible_with = triple_to_constraint_set(triple),
|
||||
target_compatible_with = triple_to_constraint_set(target_triple),
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl b/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
@@ -1,7 +1,12 @@
|
||||
load("@rules_rust//rust:toolchain.bzl", "rustfmt_toolchain")
|
||||
load("@rules_rust//rust/platform:triple.bzl", _parse_triple = "triple")
|
||||
-load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES")
|
||||
+load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES", "triple_to_constraint_set")
|
||||
load("//rs/experimental/toolchains:toolchain_utils.bzl", "sanitize_version")
|
||||
+
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
+ return "{}_{}_{}".format(exec_triple.system, exec_triple.arch, exec_triple.abi)
|
||||
+ return "{}_{}".format(exec_triple.system, exec_triple.arch)
|
||||
|
||||
def _channel(version):
|
||||
if version.startswith("nightly"):
|
||||
@@ -22,14 +27,13 @@ def declare_rustfmt_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rustc_repo_label = "@rustc_{}_{}//:".format(triple_suffix, version_key)
|
||||
rustfmt_repo_label = "@rustfmt_{}_{}//:".format(triple_suffix, rustfmt_version_key)
|
||||
|
||||
- rustfmt_toolchain_name = "{}_{}_{}_rustfmt_toolchain".format(
|
||||
- exec_triple.system,
|
||||
- exec_triple.arch,
|
||||
+ rustfmt_toolchain_name = "{}_{}_rustfmt_toolchain".format(
|
||||
+ triple_suffix,
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -43,11 +47,8 @@ def declare_rustfmt_toolchains(
|
||||
)
|
||||
|
||||
native.toolchain(
|
||||
- name = "{}_{}_rustfmt_{}".format(exec_triple.system, exec_triple.arch, version_key),
|
||||
- exec_compatible_with = [
|
||||
- "@platforms//os:" + exec_triple.system,
|
||||
- "@platforms//cpu:" + exec_triple.arch,
|
||||
- ],
|
||||
+ name = "{}_rustfmt_{}".format(triple_suffix, version_key),
|
||||
+ exec_compatible_with = triple_to_constraint_set(triple),
|
||||
target_compatible_with = [],
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl b/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
@@ -4,7 +4,7 @@ load(
|
||||
"@rules_rust//rust/private:repository_utils.bzl",
|
||||
"includes_rust_analyzer_proc_macro_srv",
|
||||
)
|
||||
-load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES")
|
||||
+load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES", "triple_to_constraint_set")
|
||||
load("//rs/experimental/toolchains:toolchain_utils.bzl", "sanitize_version")
|
||||
|
||||
def _channel(version):
|
||||
@@ -13,6 +13,11 @@ def _channel(version):
|
||||
if version.startswith("beta"):
|
||||
return "beta"
|
||||
return "stable"
|
||||
+
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
+ return "{}_{}_{}".format(exec_triple.system, exec_triple.arch, exec_triple.abi)
|
||||
+ return "{}_{}".format(exec_triple.system, exec_triple.arch)
|
||||
|
||||
def _parse_version(version):
|
||||
if "/" in version:
|
||||
@@ -31,15 +36,14 @@ def declare_rust_analyzer_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rustc_repo_label = "@rustc_{}_{}//:".format(triple_suffix, rust_analyzer_version_key)
|
||||
rust_analyzer_repo_label = "@rust_analyzer_{}_{}//:".format(triple_suffix, rust_analyzer_version_key)
|
||||
rust_src_repo_label = "@rust_src_{}//lib/rustlib/src:rustc_srcs".format(rust_analyzer_version_key)
|
||||
|
||||
- rust_analyzer_toolchain_name = "{}_{}_{}_rust_analyzer_toolchain".format(
|
||||
- exec_triple.system,
|
||||
- exec_triple.arch,
|
||||
+ rust_analyzer_toolchain_name = "{}_{}_rust_analyzer_toolchain".format(
|
||||
+ triple_suffix,
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -57,11 +61,8 @@ def declare_rust_analyzer_toolchains(
|
||||
rust_analyzer_toolchain(**rust_analyzer_toolchain_kwargs)
|
||||
|
||||
native.toolchain(
|
||||
- name = "{}_{}_rust_analyzer_{}".format(exec_triple.system, exec_triple.arch, version_key),
|
||||
- exec_compatible_with = [
|
||||
- "@platforms//os:" + exec_triple.system,
|
||||
- "@platforms//cpu:" + exec_triple.arch,
|
||||
- ],
|
||||
+ name = "{}_rust_analyzer_{}".format(triple_suffix, version_key),
|
||||
+ exec_compatible_with = triple_to_constraint_set(triple),
|
||||
target_compatible_with = [],
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/module_extension.bzl b/rs/experimental/toolchains/module_extension.bzl
|
||||
--- a/rs/experimental/toolchains/module_extension.bzl
|
||||
+++ b/rs/experimental/toolchains/module_extension.bzl
|
||||
@@ -39,6 +39,11 @@ def _normalize_arch_name(arch):
|
||||
return "aarch64"
|
||||
return arch
|
||||
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
+ return "{}_{}_{}".format(exec_triple.system, exec_triple.arch, exec_triple.abi)
|
||||
+ return "{}_{}".format(exec_triple.system, exec_triple.arch)
|
||||
+
|
||||
def _sanitize_path_fragment(path):
|
||||
return path.replace("/", "_").replace(":", "_")
|
||||
|
||||
@@ -209,7 +214,7 @@ def _toolchains_impl(mctx):
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
rustc_name = "rustc_{}_{}".format(triple_suffix, version_key)
|
||||
|
||||
rustc_repository(
|
||||
@@ -258,7 +263,7 @@ def _toolchains_impl(mctx):
|
||||
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rustfmt_repository(
|
||||
name = "rustfmt_{}_{}".format(triple_suffix, version_key),
|
||||
@@ -282,7 +287,7 @@ def _toolchains_impl(mctx):
|
||||
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rust_analyzer_repository(
|
||||
name = "rust_analyzer_{}_{}".format(triple_suffix, version_key),
|
||||
19
patches/rules_rust_build_script_tools_transition.patch
Normal file
19
patches/rules_rust_build_script_tools_transition.patch
Normal file
@@ -0,0 +1,19 @@
|
||||
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
|
||||
--- a/cargo/private/cargo_build_script.bzl
|
||||
+++ b/cargo/private/cargo_build_script.bzl
|
||||
@@ -396,3 +396,8 @@ def _cargo_build_script_impl(ctx):
|
||||
+ script_tools = []
|
||||
+ for target in ctx.attr.tools:
|
||||
+ script_tools.append(target[DefaultInfo].files)
|
||||
+ script_tools.append(target[DefaultInfo].default_runfiles.files)
|
||||
+
|
||||
workspace_name = ctx.label.workspace_name
|
||||
if not workspace_name:
|
||||
workspace_name = ctx.workspace_name
|
||||
@@ -581,5 +586,5 @@ def _cargo_build_script_impl(ctx):
|
||||
direct = [
|
||||
ctx.executable._cargo_build_script_runner,
|
||||
] + ([toolchain.target_json] if toolchain.target_json else []),
|
||||
- transitive = script_data + toolchain_tools,
|
||||
+ transitive = script_data + script_tools + toolchain_tools,
|
||||
)
|
||||
@@ -1,21 +0,0 @@
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -472,7 +472,17 @@
|
||||
)
|
||||
ld_is_direct_driver = False
|
||||
|
||||
- if not ld or toolchain.linker_preference == "rust":
|
||||
+ # Windows MSVC Rust targets can inherit a GNU-flavored C++ linker path
|
||||
+ # (`clang++`) alongside MSVC-style arguments. Prefer the toolchain linker
|
||||
+ # there so both exec helpers and ordinary MSVC Rust targets link through
|
||||
+ # the Windows direct linker instead.
|
||||
+ use_windows_rust_linker = (
|
||||
+ toolchain.target_os.startswith("windows") and
|
||||
+ toolchain.target_abi == "msvc" and
|
||||
+ toolchain.linker != None
|
||||
+ )
|
||||
+
|
||||
+ if not ld or toolchain.linker_preference == "rust" or use_windows_rust_linker:
|
||||
ld = toolchain.linker.path
|
||||
ld_is_direct_driver = toolchain.linker_type == "direct"
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
--- a/cargo/private/cargo_build_script_runner/bin.rs
|
||||
+++ b/cargo/private/cargo_build_script_runner/bin.rs
|
||||
@@ -24,6 +24,85 @@
|
||||
use cargo_build_script_runner::cargo_manifest_dir::{remove_symlink, symlink, RunfilesMaker};
|
||||
use cargo_build_script_runner::{BuildScriptOutput, CompileAndLinkFlags};
|
||||
|
||||
+#[cfg(windows)]
|
||||
+fn normalize_windows_relative_path(path: &str) -> String {
|
||||
+ path.replace('/', "\\")
|
||||
+}
|
||||
+
|
||||
+#[cfg(not(windows))]
|
||||
+fn normalize_windows_relative_path(path: &str) -> String {
|
||||
+ path.to_owned()
|
||||
+}
|
||||
+
|
||||
+fn exec_root_join(exec_root: &Path, relative: &str) -> PathBuf {
|
||||
+ exec_root.join(normalize_windows_relative_path(relative))
|
||||
+}
|
||||
+
|
||||
+#[cfg(windows)]
|
||||
+#[link(name = "Kernel32")]
|
||||
+unsafe extern "system" {
|
||||
+ fn GetShortPathNameW(
|
||||
+ lpszLongPath: *const u16,
|
||||
+ lpszShortPath: *mut u16,
|
||||
+ cchBuffer: u32,
|
||||
+ ) -> u32;
|
||||
+}
|
||||
+
|
||||
+#[cfg(windows)]
|
||||
+fn windows_extended_length_path(path: &Path) -> PathBuf {
|
||||
+ let path = path.as_os_str().to_string_lossy();
|
||||
+ if path.starts_with(r"\\?\") {
|
||||
+ PathBuf::from(path.to_string())
|
||||
+ } else if let Some(stripped) = path.strip_prefix(r"\\") {
|
||||
+ PathBuf::from(format!(r"\\?\UNC\{stripped}"))
|
||||
+ } else {
|
||||
+ PathBuf::from(format!(r"\\?\{path}"))
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+#[cfg(windows)]
|
||||
+fn shorten_windows_path(path: &Path) -> PathBuf {
|
||||
+ use std::os::windows::ffi::OsStrExt;
|
||||
+
|
||||
+ let long_path = windows_extended_length_path(path);
|
||||
+ let long_path = long_path
|
||||
+ .as_os_str()
|
||||
+ .encode_wide()
|
||||
+ .chain(Some(0))
|
||||
+ .collect::<Vec<u16>>();
|
||||
+
|
||||
+ unsafe {
|
||||
+ let required = GetShortPathNameW(long_path.as_ptr(), std::ptr::null_mut(), 0);
|
||||
+ if required == 0 {
|
||||
+ return path.to_owned();
|
||||
+ }
|
||||
+
|
||||
+ let mut short_path = vec![0u16; required as usize];
|
||||
+ let written = GetShortPathNameW(long_path.as_ptr(), short_path.as_mut_ptr(), required);
|
||||
+ if written == 0 {
|
||||
+ path.to_owned()
|
||||
+ } else {
|
||||
+ let short_path = PathBuf::from(
|
||||
+ <std::ffi::OsString as std::os::windows::ffi::OsStringExt>::from_wide(
|
||||
+ &short_path[..written as usize],
|
||||
+ ),
|
||||
+ );
|
||||
+ PathBuf::from(
|
||||
+ short_path
|
||||
+ .as_os_str()
|
||||
+ .to_string_lossy()
|
||||
+ .trim_start_matches(r"\\?\")
|
||||
+ .to_string(),
|
||||
+ )
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+#[cfg(not(windows))]
|
||||
+fn shorten_windows_path(path: &Path) -> PathBuf {
|
||||
+ path.to_owned()
|
||||
+}
|
||||
+
|
||||
fn run_buildrs() -> Result<(), String> {
|
||||
// We use exec_root.join rather than std::fs::canonicalize, to avoid resolving symlinks, as
|
||||
// some execution strategies and remote execution environments may use symlinks in ways which
|
||||
@@ -31,10 +110,11 @@ fn run_buildrs() -> Result<(), String> {
|
||||
// directory - resolving these may cause tools which inspect $0, or try to resolve files
|
||||
// relative to themselves, to fail.
|
||||
let exec_root = env::current_dir().expect("Failed to get current directory");
|
||||
- let manifest_dir_env = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR was not set");
|
||||
- let rustc_env = env::var("RUSTC").expect("RUSTC was not set");
|
||||
- let manifest_dir = exec_root.join(manifest_dir_env);
|
||||
- let rustc = exec_root.join(&rustc_env);
|
||||
+ let manifest_dir_env =
|
||||
+ normalize_windows_relative_path(&env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR was not set"));
|
||||
+ let rustc_env = normalize_windows_relative_path(&env::var("RUSTC").expect("RUSTC was not set"));
|
||||
+ let manifest_dir = exec_root_join(&exec_root, &manifest_dir_env);
|
||||
+ let rustc = shorten_windows_path(&exec_root_join(&exec_root, &rustc_env));
|
||||
let Args {
|
||||
progname,
|
||||
crate_links,
|
||||
@@ -55,7 +135,8 @@ fn run_buildrs() -> Result<(), String> {
|
||||
cargo_manifest_maker.create_runfiles_dir().unwrap()
|
||||
}
|
||||
|
||||
- let out_dir_abs = exec_root.join(out_dir);
|
||||
+ let out_dir_abs = shorten_windows_path(&exec_root_join(&exec_root, &out_dir));
|
||||
// For some reason Google's RBE does not create the output directory, force create it.
|
||||
create_dir_all(&out_dir_abs)
|
||||
.unwrap_or_else(|_| panic!("Failed to make output directory: {:?}", out_dir_abs));
|
||||
@@ -89,11 +170,12 @@ fn run_buildrs() -> Result<(), String> {
|
||||
|
||||
let working_directory = resolve_rundir(&rundir, &exec_root, &manifest_dir)?;
|
||||
|
||||
- let mut command = Command::new(exec_root.join(progname));
|
||||
+ let mut command = Command::new(exec_root_join(&exec_root, &progname));
|
||||
command
|
||||
- .current_dir(&working_directory)
|
||||
+ .current_dir(shorten_windows_path(&working_directory))
|
||||
.envs(target_env_vars)
|
||||
.env("OUT_DIR", &out_dir_abs)
|
||||
+ .env("RULES_RUST_BAZEL_BUILD_SCRIPT_RUNNER", "1")
|
||||
.env("CARGO_MANIFEST_DIR", manifest_dir)
|
||||
.env("RUSTC", rustc)
|
||||
.env("RUST_BACKTRACE", "full");
|
||||
@@ -123,7 +205,7 @@ fn run_buildrs() -> Result<(), String> {
|
||||
|
||||
for tool_env_var in &["CC", "CXX", "LD"] {
|
||||
if let Some(tool_path) = env::var_os(tool_env_var) {
|
||||
- command.env(tool_env_var, exec_root.join(tool_path));
|
||||
+ command.env(tool_env_var, exec_root_join(&exec_root, &tool_path.to_string_lossy()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +221,7 @@ fn run_buildrs() -> Result<(), String> {
|
||||
command.env_remove("AR");
|
||||
command.env_remove("ARFLAGS");
|
||||
} else {
|
||||
- command.env("AR", exec_root.join(ar_path));
|
||||
+ command.env("AR", exec_root_join(&exec_root, &ar_path.to_string_lossy()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +339,8 @@ fn resolve_rundir(rundir: &str, exec_root: &Path, manifest_dir: &Path) -> Result
|
||||
if rundir.is_empty() {
|
||||
return Ok(manifest_dir.to_owned());
|
||||
}
|
||||
- let rundir_path = Path::new(rundir);
|
||||
+ let rundir = normalize_windows_relative_path(rundir);
|
||||
+ let rundir_path = Path::new(&rundir);
|
||||
if rundir_path.is_absolute() {
|
||||
return Err(format!("rundir must be empty (to run in manifest path) or relative path (relative to exec root), but was {:?}", rundir));
|
||||
}
|
||||
diff --git a/cargo/private/cargo_build_script_runner/cargo_manifest_dir.rs b/cargo/private/cargo_build_script_runner/cargo_manifest_dir.rs
|
||||
--- a/cargo/private/cargo_build_script_runner/cargo_manifest_dir.rs
|
||||
+++ b/cargo/private/cargo_build_script_runner/cargo_manifest_dir.rs
|
||||
@@ -282,7 +282,7 @@
|
||||
/// been copied into the runfiles directory.
|
||||
fn drain_runfiles_dir_windows(&self) -> Result<(), String> {
|
||||
for dest in self.runfiles.values() {
|
||||
- if !self
|
||||
+ if self
|
||||
.filename_suffixes_to_retain
|
||||
.iter()
|
||||
.any(|suffix| dest.ends_with(suffix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
# What: compile exec-side Rust binaries against the exec Windows triple instead
|
||||
# of the lint target triple.
|
||||
# Why: Windows native argument-comment-lint keeps the repo target platform on
|
||||
# `windows-gnullvm` to preserve cfg coverage, but exec-side helper binaries
|
||||
# (build.rs, runners, bootstrap tools) must link as host tools. With
|
||||
# `toolchain_linker_preference=rust`, rules_rust was still feeding those exec
|
||||
# binaries the `windows-gnullvm` target/std path, which broke linking under the
|
||||
# native Bazel lint lane.
|
||||
|
||||
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -129,6 +129,20 @@
|
||||
build_setting = config.bool(flag = True),
|
||||
)
|
||||
|
||||
-def _get_rustc_env(attr, toolchain, crate_name):
|
||||
+def _effective_target_arch(toolchain, use_exec_target):
|
||||
+ return toolchain.exec_triple.arch if use_exec_target else toolchain.target_arch
|
||||
+
|
||||
+def _effective_target_os(toolchain, use_exec_target):
|
||||
+ return toolchain.exec_triple.system if use_exec_target else toolchain.target_os
|
||||
+
|
||||
+def _effective_target_flag_value(toolchain, use_exec_target):
|
||||
+ return toolchain.exec_triple.str if use_exec_target else toolchain.target_flag_value
|
||||
+
|
||||
+def _effective_rust_std_paths(toolchain, use_exec_target):
|
||||
+ if use_exec_target:
|
||||
+ return ["{}/lib/rustlib/{}/lib".format(toolchain.sysroot, toolchain.exec_triple.str)]
|
||||
+ return toolchain.rust_std_paths
|
||||
+
|
||||
+def _get_rustc_env(attr, toolchain, crate_name, use_exec_target = False):
|
||||
"""Gathers rustc environment variables
|
||||
|
||||
@@ -147,6 +161,6 @@
|
||||
|
||||
result = {
|
||||
- "CARGO_CFG_TARGET_ARCH": "" if toolchain.target_arch == None else toolchain.target_arch,
|
||||
- "CARGO_CFG_TARGET_OS": "" if toolchain.target_os == None else toolchain.target_os,
|
||||
+ "CARGO_CFG_TARGET_ARCH": "" if _effective_target_arch(toolchain, use_exec_target) == None else _effective_target_arch(toolchain, use_exec_target),
|
||||
+ "CARGO_CFG_TARGET_OS": "" if _effective_target_os(toolchain, use_exec_target) == None else _effective_target_os(toolchain, use_exec_target),
|
||||
"CARGO_CRATE_NAME": crate_name,
|
||||
"CARGO_PKG_AUTHORS": "",
|
||||
@@ -997,9 +1011,11 @@
|
||||
if build_metadata and not use_json_output:
|
||||
fail("build_metadata requires parse_json_output")
|
||||
|
||||
+ use_exec_target = is_exec_configuration(ctx) and crate_info.type == "bin"
|
||||
+
|
||||
output_dir = getattr(crate_info.output, "dirname", None)
|
||||
linker_script = getattr(file, "linker_script", None)
|
||||
|
||||
- env = _get_rustc_env(attr, toolchain, crate_info.name)
|
||||
+ env = _get_rustc_env(attr, toolchain, crate_info.name, use_exec_target)
|
||||
|
||||
# Wrapper args first
|
||||
@@ -1138,5 +1154,5 @@
|
||||
if error_format != "json":
|
||||
# Color is not compatible with json output.
|
||||
rustc_flags.add("--color=always")
|
||||
- rustc_flags.add(toolchain.target_flag_value, format = "--target=%s")
|
||||
+ rustc_flags.add(_effective_target_flag_value(toolchain, use_exec_target), format = "--target=%s")
|
||||
if hasattr(attr, "crate_features"):
|
||||
@@ -1144,6 +1160,6 @@
|
||||
if linker_script:
|
||||
rustc_flags.add(linker_script, format = "--codegen=link-arg=-T%s")
|
||||
|
||||
# Tell Rustc where to find the standard library (or libcore)
|
||||
- rustc_flags.add_all(toolchain.rust_std_paths, before_each = "-L", format_each = "%s")
|
||||
+ rustc_flags.add_all(_effective_rust_std_paths(toolchain, use_exec_target), before_each = "-L", format_each = "%s")
|
||||
rustc_flags.add_all(rust_flags, map_each = map_flag)
|
||||
@@ -1,184 +0,0 @@
|
||||
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
|
||||
--- a/cargo/private/cargo_build_script.bzl
|
||||
+++ b/cargo/private/cargo_build_script.bzl
|
||||
@@ -144,9 +144,14 @@ def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
if toolchain.target_flag_value != toolchain.exec_triple.str or not toolchain.exec_triple.str.endswith("-pc-windows-msvc"):
|
||||
return args
|
||||
|
||||
- rewritten = []
|
||||
+ rewritten = [
|
||||
+ "-target",
|
||||
+ toolchain.target_flag_value,
|
||||
+ ]
|
||||
skip_next = False
|
||||
- for arg in args:
|
||||
+ for index in range(len(args)):
|
||||
+ arg = args[index]
|
||||
+
|
||||
if skip_next:
|
||||
skip_next = False
|
||||
continue
|
||||
@@ -161,21 +166,58 @@ def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
if arg == "-nostdlibinc" or arg.startswith("--sysroot"):
|
||||
continue
|
||||
|
||||
- if "mingw-w64-" in arg or "mingw_import_libraries_directory" in arg or "mingw_crt_library_search_directory" in arg:
|
||||
+ if arg.startswith("-fstack-protector") or arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
+ continue
|
||||
+
|
||||
+ if arg == "-isystem" and index + 1 < len(args):
|
||||
+ path = args[index + 1]
|
||||
+ if "mingw-w64-" in path or "mingw_import_libraries_directory" in path or "mingw_crt_library_search_directory" in path:
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+
|
||||
+ rewritten.append(arg)
|
||||
+
|
||||
+ return rewritten
|
||||
+
|
||||
+def _rewrite_windows_exec_msvc_link_args(toolchain, args):
|
||||
+ """Translate GNU-flavored link args when exec-side build scripts target Windows MSVC."""
|
||||
+ if toolchain.target_flag_value != toolchain.exec_triple.str or not toolchain.exec_triple.str.endswith("-pc-windows-msvc"):
|
||||
+ return args
|
||||
+
|
||||
+ rewritten = []
|
||||
+ skip_next = False
|
||||
+ for index in range(len(args)):
|
||||
+ arg = args[index]
|
||||
+
|
||||
+ if skip_next:
|
||||
+ skip_next = False
|
||||
+ continue
|
||||
+
|
||||
+ if arg == "--sysroot":
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+
|
||||
+ if arg.startswith("--sysroot="):
|
||||
continue
|
||||
|
||||
- if arg.startswith("-fstack-protector"):
|
||||
+ if arg == "-L" and index + 1 < len(args):
|
||||
+ path = args[index + 1]
|
||||
+ if "mingw_import_libraries_directory" in path or "mingw_crt_library_search_directory" in path:
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+ rewritten.extend([arg, path])
|
||||
+ skip_next = True
|
||||
continue
|
||||
|
||||
- if arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
+ if arg.startswith("-L") and (
|
||||
+ "mingw_import_libraries_directory" in arg or
|
||||
+ "mingw_crt_library_search_directory" in arg
|
||||
+ ):
|
||||
continue
|
||||
|
||||
rewritten.append(arg)
|
||||
|
||||
- return [
|
||||
- "-target",
|
||||
- toolchain.target_flag_value,
|
||||
- ] + rewritten
|
||||
+ return rewritten
|
||||
|
||||
def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
|
||||
"""Gather cc environment variables from the given `cc_toolchain`
|
||||
@@ -508,15 +550,23 @@ def _cargo_build_script_impl(ctx):
|
||||
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
|
||||
linker, _, link_args, linker_env = get_linker_and_args(ctx, "bin", toolchain, cc_toolchain, feature_configuration, None)
|
||||
env.update(**linker_env)
|
||||
- env["LD"] = linker
|
||||
- env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
|
||||
+ use_windows_exec_msvc_path_tools = (
|
||||
+ toolchain.target_flag_value == toolchain.exec_triple.str and
|
||||
+ toolchain.exec_triple.str.endswith("-pc-windows-msvc")
|
||||
+ )
|
||||
+
|
||||
+ if not use_windows_exec_msvc_path_tools:
|
||||
+ env["LD"] = linker
|
||||
+ link_args = _rewrite_windows_exec_msvc_link_args(toolchain, link_args)
|
||||
+ env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
|
||||
+
|
||||
+ # Defaults for cxx flags.
|
||||
+ env["CFLAGS"] = ""
|
||||
+ env["CXXFLAGS"] = ""
|
||||
|
||||
- # Defaults for cxx flags.
|
||||
env["ARFLAGS"] = ""
|
||||
- env["CFLAGS"] = ""
|
||||
- env["CXXFLAGS"] = ""
|
||||
fallback_tools = []
|
||||
- if not cc_toolchain:
|
||||
+ if not cc_toolchain and not use_windows_exec_msvc_path_tools:
|
||||
fallbacks = {
|
||||
"AR": "_fallback_ar",
|
||||
"CC": "_fallback_cc",
|
||||
@@ -542,36 +592,37 @@ def _cargo_build_script_impl(ctx):
|
||||
|
||||
toolchain_tools.append(cc_toolchain.all_files)
|
||||
|
||||
- env["CC"] = cc_common.get_tool_for_action(
|
||||
- feature_configuration = feature_configuration,
|
||||
- action_name = ACTION_NAMES.c_compile,
|
||||
- )
|
||||
- env["CXX"] = cc_common.get_tool_for_action(
|
||||
- feature_configuration = feature_configuration,
|
||||
- action_name = ACTION_NAMES.cpp_compile,
|
||||
- )
|
||||
- env["AR"] = cc_common.get_tool_for_action(
|
||||
- feature_configuration = feature_configuration,
|
||||
- action_name = ACTION_NAMES.cpp_link_static_library,
|
||||
- )
|
||||
-
|
||||
- # Many C/C++ toolchains are missing an action_config for AR because
|
||||
- # one was never included in the unix_cc_toolchain_config.
|
||||
- if not env["AR"]:
|
||||
- env["AR"] = cc_toolchain.ar_executable
|
||||
-
|
||||
- cc_c_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_c_args)
|
||||
- cc_cxx_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_cxx_args)
|
||||
- cc_c_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_c_args)
|
||||
- cc_cxx_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_cxx_args)
|
||||
- # Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
|
||||
- # to determine the deployment target when building for apple platforms (`macosx-version-min`
|
||||
- # for example, itself derived from the `macos_minimum_os` Bazel argument).
|
||||
- env["CFLAGS"] = " ".join(_pwd_flags(cc_c_args))
|
||||
- env["CXXFLAGS"] = " ".join(_pwd_flags(cc_cxx_args))
|
||||
- # It may be tempting to forward ARFLAGS, but cc-rs is opinionated enough
|
||||
- # that doing so is more likely to hurt than help. If you need to change
|
||||
- # ARFLAGS, make changes to cc-rs.
|
||||
+ if not use_windows_exec_msvc_path_tools:
|
||||
+ env["CC"] = cc_common.get_tool_for_action(
|
||||
+ feature_configuration = feature_configuration,
|
||||
+ action_name = ACTION_NAMES.c_compile,
|
||||
+ )
|
||||
+ env["CXX"] = cc_common.get_tool_for_action(
|
||||
+ feature_configuration = feature_configuration,
|
||||
+ action_name = ACTION_NAMES.cpp_compile,
|
||||
+ )
|
||||
+ env["AR"] = cc_common.get_tool_for_action(
|
||||
+ feature_configuration = feature_configuration,
|
||||
+ action_name = ACTION_NAMES.cpp_link_static_library,
|
||||
+ )
|
||||
+
|
||||
+ # Many C/C++ toolchains are missing an action_config for AR because
|
||||
+ # one was never included in the unix_cc_toolchain_config.
|
||||
+ if not env["AR"]:
|
||||
+ env["AR"] = cc_toolchain.ar_executable
|
||||
+
|
||||
+ cc_c_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_c_args)
|
||||
+ cc_cxx_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_cxx_args)
|
||||
+ cc_c_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_c_args)
|
||||
+ cc_cxx_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_cxx_args)
|
||||
+ # Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
|
||||
+ # to determine the deployment target when building for apple platforms (`macosx-version-min`
|
||||
+ # for example, itself derived from the `macos_minimum_os` Bazel argument).
|
||||
+ env["CFLAGS"] = " ".join(_pwd_flags(cc_c_args))
|
||||
+ env["CXXFLAGS"] = " ".join(_pwd_flags(cc_cxx_args))
|
||||
+ # It may be tempting to forward ARFLAGS, but cc-rs is opinionated enough
|
||||
+ # that doing so is more likely to hurt than help. If you need to change
|
||||
+ # ARFLAGS, make changes to cc-rs.
|
||||
|
||||
# Inform build scripts of rustc flags
|
||||
# https://github.com/rust-lang/cargo/issues/9600
|
||||
@@ -1,11 +0,0 @@
|
||||
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
|
||||
--- a/rust/private/repository_utils.bzl
|
||||
+++ b/rust/private/repository_utils.bzl
|
||||
@@ -53,6 +53,7 @@ filegroup(
|
||||
"lib/*{dylib_ext}*",
|
||||
"lib/rustlib/{target_triple}/codegen-backends/*{dylib_ext}",
|
||||
"lib/rustlib/{target_triple}/lib/*{dylib_ext}*",
|
||||
+ "lib/rustlib/{target_triple}/lib/*.rlib",
|
||||
"lib/rustlib/{target_triple}/lib/*.rmeta",
|
||||
],
|
||||
allow_empty = True,
|
||||
@@ -1,178 +0,0 @@
|
||||
# What: expose an exec-side Rust standard library alongside the target stdlib.
|
||||
# Why: mixed Windows toolchains compile repo crates for `windows-gnullvm`, but
|
||||
# exec-side helper binaries (build.rs, runners) may need the host MSVC stdlib.
|
||||
# The toolchain sysroot must therefore carry both stdlib trees so rustc can
|
||||
# resolve the correct one for each `--target`.
|
||||
|
||||
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
--- a/rust/toolchain.bzl
|
||||
+++ b/rust/toolchain.bzl
|
||||
@@ -211,6 +211,7 @@
|
||||
clippy = None,
|
||||
cargo_clippy = None,
|
||||
llvm_tools = None,
|
||||
+ exec_rust_std = None,
|
||||
rust_std = None,
|
||||
rustfmt = None,
|
||||
linker = None):
|
||||
@@ -315,6 +316,14 @@
|
||||
# Made available to support $(location) expansion in stdlib_linkflags and extra_rustc_flags.
|
||||
transitive_file_sets.append(depset(ctx.files.rust_std))
|
||||
|
||||
+ sysroot_exec_rust_std = None
|
||||
+ if exec_rust_std:
|
||||
+ sysroot_exec_rust_std = _symlink_sysroot_tree(ctx, name, exec_rust_std)
|
||||
+ transitive_file_sets.extend([sysroot_exec_rust_std])
|
||||
+
|
||||
+ # Made available to support $(location) expansion in extra_exec_rustc_flags.
|
||||
+ transitive_file_sets.append(depset(ctx.files.exec_rust_std))
|
||||
+
|
||||
# Declare a file in the root of the sysroot to make locating the sysroot easy
|
||||
sysroot_anchor = ctx.actions.declare_file("{}/rust.sysroot".format(name))
|
||||
ctx.actions.write(
|
||||
@@ -325,6 +334,7 @@
|
||||
"cargo-clippy: {}".format(cargo_clippy),
|
||||
"linker: {}".format(linker),
|
||||
"llvm_tools: {}".format(llvm_tools),
|
||||
+ "exec_rust_std: {}".format(exec_rust_std),
|
||||
"rust_std: {}".format(rust_std),
|
||||
"rustc_lib: {}".format(rustc_lib),
|
||||
"rustc: {}".format(rustc),
|
||||
@@ -342,6 +352,7 @@
|
||||
cargo_clippy = sysroot_cargo_clippy,
|
||||
clippy = sysroot_clippy,
|
||||
linker = sysroot_linker,
|
||||
+ exec_rust_std = sysroot_exec_rust_std,
|
||||
rust_std = sysroot_rust_std,
|
||||
rustc = sysroot_rustc,
|
||||
rustc_lib = sysroot_rustc_lib,
|
||||
@@ -412,12 +423,14 @@
|
||||
)
|
||||
|
||||
rust_std = ctx.attr.rust_std
|
||||
+ exec_rust_std = ctx.attr.exec_rust_std if ctx.attr.exec_rust_std else rust_std
|
||||
|
||||
sysroot = _generate_sysroot(
|
||||
ctx = ctx,
|
||||
rustc = ctx.file.rustc,
|
||||
rustdoc = ctx.file.rust_doc,
|
||||
rustc_lib = ctx.attr.rustc_lib,
|
||||
+ exec_rust_std = exec_rust_std,
|
||||
rust_std = rust_std,
|
||||
rustfmt = ctx.file.rustfmt,
|
||||
clippy = ctx.file.clippy_driver,
|
||||
@@ -454,7 +467,7 @@
|
||||
|
||||
expanded_stdlib_linkflags = _expand_flags(ctx, "stdlib_linkflags", rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
expanded_extra_rustc_flags = _expand_flags(ctx, "extra_rustc_flags", rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
- expanded_extra_exec_rustc_flags = _expand_flags(ctx, "extra_exec_rustc_flags", rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
+ expanded_extra_exec_rustc_flags = _expand_flags(ctx, "extra_exec_rustc_flags", exec_rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
|
||||
linking_context = cc_common.create_linking_context(
|
||||
linker_inputs = depset([
|
||||
@@ -807,6 +820,10 @@
|
||||
doc = "The Rust standard library.",
|
||||
mandatory = True,
|
||||
),
|
||||
+ "exec_rust_std": attr.label(
|
||||
+ doc = "Optional Rust standard library for exec-configuration Rust tools. Defaults to rust_std.",
|
||||
+ mandatory = False,
|
||||
+ ),
|
||||
"rustc": attr.label(
|
||||
doc = "The location of the `rustc` binary. Can be a direct source or a filegroup containing one item.",
|
||||
allow_single_file = True,
|
||||
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
|
||||
--- a/rust/private/repository_utils.bzl
|
||||
+++ b/rust/private/repository_utils.bzl
|
||||
@@ -342,6 +342,7 @@
|
||||
name = "{toolchain_name}",
|
||||
rust_doc = "//:rustdoc",
|
||||
rust_std = "//:rust_std-{target_triple}",
|
||||
+ exec_rust_std = {exec_rust_std_label},
|
||||
rustc = "//:rustc",
|
||||
linker = {linker_label},
|
||||
linker_type = {linker_type},
|
||||
@@ -389,6 +390,7 @@
|
||||
include_llvm_tools = False,
|
||||
include_linker = False,
|
||||
include_objcopy = False,
|
||||
+ exec_rust_std_label = None,
|
||||
stdlib_linkflags = None,
|
||||
extra_rustc_flags = None,
|
||||
extra_exec_rustc_flags = None,
|
||||
@@ -412,6 +414,7 @@
|
||||
include_llvm_tools (bool): Whether llvm-tools are present in the toolchain.
|
||||
include_linker (bool): Whether a linker is available in the toolchain.
|
||||
include_objcopy (bool): Whether rust-objcopy is available in the toolchain.
|
||||
+ exec_rust_std_label (str, optional): Label for an exec-side stdlib when it differs from rust_std.
|
||||
stdlib_linkflags (list, optional): Overridden flags needed for linking to rust
|
||||
stdlib, akin to BAZEL_LINKLIBS. Defaults to
|
||||
None.
|
||||
@@ -465,6 +468,7 @@
|
||||
staticlib_ext = system_to_staticlib_ext(target_triple.system),
|
||||
dylib_ext = system_to_dylib_ext(target_triple.system),
|
||||
allocator_library = repr(allocator_library_label),
|
||||
+ exec_rust_std_label = repr(exec_rust_std_label),
|
||||
global_allocator_library = repr(global_allocator_library_label),
|
||||
stdlib_linkflags = stdlib_linkflags,
|
||||
default_edition = default_edition,
|
||||
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -1010,7 +1010,10 @@
|
||||
if build_metadata and not use_json_output:
|
||||
fail("build_metadata requires parse_json_output")
|
||||
|
||||
- use_exec_target = is_exec_configuration(ctx) and crate_info.type == "bin"
|
||||
+ # Exec-configuration crates (build scripts, proc-macros, and their
|
||||
+ # dependencies) must all target the exec triple so they can link against
|
||||
+ # each other and the exec-side standard library.
|
||||
+ use_exec_target = is_exec_configuration(ctx)
|
||||
|
||||
output_dir = getattr(crate_info.output, "dirname", None)
|
||||
linker_script = getattr(file, "linker_script", None)
|
||||
diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
--- a/rust/repositories.bzl
|
||||
+++ b/rust/repositories.bzl
|
||||
@@ -574,6 +574,18 @@
|
||||
build_components.append(rust_stdlib_content)
|
||||
sha256s.update(rust_stdlib_sha256)
|
||||
|
||||
+ exec_rust_std_label = None
|
||||
+ if exec_triple.str != target_triple.str:
|
||||
+ exec_rust_stdlib_content, exec_rust_stdlib_sha256 = load_rust_stdlib(
|
||||
+ ctx = ctx,
|
||||
+ target_triple = exec_triple,
|
||||
+ version = version,
|
||||
+ iso_date = iso_date,
|
||||
+ )
|
||||
+ build_components.append(exec_rust_stdlib_content)
|
||||
+ sha256s.update(exec_rust_stdlib_sha256)
|
||||
+ exec_rust_std_label = "//:rust_std-{}".format(exec_triple.str)
|
||||
+
|
||||
stdlib_linkflags = None
|
||||
if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx.os.environ:
|
||||
stdlib_linkflags = ctx.os.environ["BAZEL_RUST_STDLIB_LINKFLAGS"].split(":")
|
||||
@@ -590,6 +602,7 @@
|
||||
include_llvm_tools = include_llvm_tools,
|
||||
include_linker = include_linker,
|
||||
include_objcopy = include_objcopy,
|
||||
+ exec_rust_std_label = exec_rust_std_label,
|
||||
extra_rustc_flags = ctx.attr.extra_rustc_flags,
|
||||
extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags,
|
||||
opt_level = ctx.attr.opt_level if ctx.attr.opt_level else None,
|
||||
@@ -608,6 +621,14 @@
|
||||
iso_date = iso_date,
|
||||
)
|
||||
sha256s.update(rustc_dev_sha256)
|
||||
+ if exec_triple.str != target_triple.str:
|
||||
+ exec_rustc_dev_sha256 = load_rustc_dev_nightly(
|
||||
+ ctx = ctx,
|
||||
+ target_triple = exec_triple,
|
||||
+ version = version,
|
||||
+ iso_date = iso_date,
|
||||
+ )
|
||||
+ sha256s.update(exec_rustc_dev_sha256)
|
||||
|
||||
ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
|
||||
ctx.name,
|
||||
@@ -1,78 +0,0 @@
|
||||
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
|
||||
--- a/cargo/private/cargo_build_script.bzl
|
||||
+++ b/cargo/private/cargo_build_script.bzl
|
||||
@@ -120,6 +120,63 @@
|
||||
executable = True,
|
||||
)
|
||||
|
||||
+def _strip_stack_protector_for_windows_llvm_mingw(toolchain, args):
|
||||
+ """Drop stack protector flags unsupported by llvm-mingw build-script probes."""
|
||||
+ if "windows-gnullvm" not in toolchain.target_flag_value:
|
||||
+ return args
|
||||
+
|
||||
+ uses_llvm_mingw = False
|
||||
+ for arg in args:
|
||||
+ if "mingw-w64-" in arg:
|
||||
+ uses_llvm_mingw = True
|
||||
+ break
|
||||
+
|
||||
+ if not uses_llvm_mingw:
|
||||
+ return args
|
||||
+
|
||||
+ # llvm-mingw does not ship libssp_nonshared, so forwarding stack-protector
|
||||
+ # flags through CFLAGS/CXXFLAGS breaks build.rs probe binaries compiled via
|
||||
+ # cc-rs.
|
||||
+ return [arg for arg in args if not arg.startswith("-fstack-protector")]
|
||||
+
|
||||
+def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
+ """Translate GNU-flavored cc args when exec-side build scripts target Windows MSVC."""
|
||||
+ if toolchain.target_flag_value != toolchain.exec_triple.str or not toolchain.exec_triple.str.endswith("-pc-windows-msvc"):
|
||||
+ return args
|
||||
+
|
||||
+ rewritten = []
|
||||
+ skip_next = False
|
||||
+ for arg in args:
|
||||
+ if skip_next:
|
||||
+ skip_next = False
|
||||
+ continue
|
||||
+
|
||||
+ if arg == "-target":
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+
|
||||
+ if arg.startswith("-target=") or arg.startswith("--target="):
|
||||
+ continue
|
||||
+
|
||||
+ if arg == "-nostdlibinc" or arg.startswith("--sysroot"):
|
||||
+ continue
|
||||
+
|
||||
+ if "mingw-w64-" in arg or "mingw_import_libraries_directory" in arg or "mingw_crt_library_search_directory" in arg:
|
||||
+ continue
|
||||
+
|
||||
+ if arg.startswith("-fstack-protector"):
|
||||
+ continue
|
||||
+
|
||||
+ if arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
+ continue
|
||||
+
|
||||
+ rewritten.append(arg)
|
||||
+
|
||||
+ return [
|
||||
+ "-target",
|
||||
+ toolchain.target_flag_value,
|
||||
+ ] + rewritten
|
||||
+
|
||||
def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
|
||||
"""Gather cc environment variables from the given `cc_toolchain`
|
||||
|
||||
@@ -503,6 +560,10 @@
|
||||
if not env["AR"]:
|
||||
env["AR"] = cc_toolchain.ar_executable
|
||||
|
||||
+ cc_c_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_c_args)
|
||||
+ cc_cxx_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_cxx_args)
|
||||
+ cc_c_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_c_args)
|
||||
+ cc_cxx_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_cxx_args)
|
||||
# Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
|
||||
# to determine the deployment target when building for apple platforms (`macosx-version-min`
|
||||
# for example, itself derived from the `macos_minimum_os` Bazel argument).
|
||||
@@ -1,32 +1,32 @@
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -501,11 +501,41 @@
|
||||
@@ -468,11 +468,25 @@
|
||||
filtered_args.append(version)
|
||||
# Keep library search path flags
|
||||
|
||||
+ elif processed_arg == "-L" and i + 1 < len(link_args):
|
||||
+ path = link_args[i + 1]
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows":
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows" and toolchain.target_abi == "msvc":
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+ filtered_args.extend([processed_arg, path])
|
||||
+ skip_next = True
|
||||
+
|
||||
elif processed_arg.startswith("-L"):
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows":
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows" and toolchain.target_abi == "msvc":
|
||||
+ continue
|
||||
filtered_args.append(processed_arg)
|
||||
# Keep sysroot flags (as single or two-part arguments)
|
||||
|
||||
elif processed_arg == "--sysroot" or processed_arg.startswith("--sysroot="):
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows":
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows" and toolchain.target_abi == "msvc":
|
||||
+ if processed_arg == "--sysroot" and i + 1 < len(link_args):
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
filtered_args.append(processed_arg)
|
||||
if processed_arg == "--sysroot" and i + 1 < len(link_args):
|
||||
# Two-part argument, keep the next arg too
|
||||
@@ -2256,8 +2256,10 @@
|
||||
@@ -2943,8 +2957,10 @@
|
||||
use_pic,
|
||||
ambiguous_libs,
|
||||
get_lib_name,
|
||||
@@ -38,11 +38,22 @@
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
@@ -2310,6 +2312,11 @@
|
||||
@@ -2952,8 +2968,10 @@
|
||||
use_pic (_type_): _description_
|
||||
ambiguous_libs (_type_): _description_
|
||||
get_lib_name (_type_): _description_
|
||||
+ for_windows (bool, optional): _description_. Defaults to False.
|
||||
for_darwin (bool, optional): _description_. Defaults to False.
|
||||
flavor_msvc (bool, optional): _description_. Defaults to False.
|
||||
+ use_direct_driver (bool, optional): _description_. Defaults to False.
|
||||
|
||||
Returns:
|
||||
_type_: _description_
|
||||
@@ -2997,6 +3015,11 @@
|
||||
):
|
||||
return [] if for_darwin else ["-lstatic=%s" % get_lib_name(artifact)]
|
||||
|
||||
+ if for_windows and use_direct_driver and not artifact.basename.endswith(".lib"):
|
||||
+ if for_windows and flavor_msvc and use_direct_driver and not artifact.basename.endswith(".lib"):
|
||||
+ return [
|
||||
+ "-Clink-arg={}".format(artifact.path),
|
||||
+ ]
|
||||
@@ -50,7 +61,7 @@
|
||||
if flavor_msvc:
|
||||
return [
|
||||
"-lstatic=%s" % get_lib_name(artifact),
|
||||
@@ -2346,7 +2353,7 @@
|
||||
@@ -3045,7 +3068,7 @@
|
||||
])
|
||||
elif include_link_flags:
|
||||
get_lib_name = get_lib_name_for_windows if flavor_msvc else get_lib_name_default
|
||||
@@ -59,34 +70,26 @@
|
||||
|
||||
# Windows toolchains can inherit POSIX defaults like -pthread from C deps,
|
||||
# which fails to link with the MinGW/LLD toolchain. Drop them here.
|
||||
@@ -2522,17 +2529,25 @@
|
||||
else:
|
||||
# For all other crate types we want to link C++ runtime library statically
|
||||
# (for example libstdc++.a or libc++.a).
|
||||
+ runtime_libs = cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration)
|
||||
args.add_all(
|
||||
- cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration),
|
||||
+ runtime_libs,
|
||||
map_each = _get_dirname,
|
||||
@@ -3257,11 +3280,18 @@
|
||||
format_each = "-Lnative=%s",
|
||||
)
|
||||
if include_link_flags:
|
||||
- args.add_all(
|
||||
- cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration),
|
||||
- runtime_libs,
|
||||
- map_each = get_lib_name,
|
||||
- format_each = "-lstatic=%s",
|
||||
- format_each = static_runtime_link_format,
|
||||
- )
|
||||
+ if toolchain.target_os == "windows" and use_direct_link_driver:
|
||||
+ if toolchain.target_os == "windows" and toolchain.target_abi == "msvc" and use_direct_link_driver:
|
||||
+ for runtime_lib in runtime_libs.to_list():
|
||||
+ if runtime_lib.basename.endswith(".lib"):
|
||||
+ args.add(get_lib_name(runtime_lib), format = "-lstatic=%s")
|
||||
+ args.add(get_lib_name(runtime_lib), format = static_runtime_link_format)
|
||||
+ else:
|
||||
+ args.add(runtime_lib.path, format = "--codegen=link-arg=%s")
|
||||
+ else:
|
||||
+ args.add_all(
|
||||
+ runtime_libs,
|
||||
+ map_each = get_lib_name,
|
||||
+ format_each = "-lstatic=%s",
|
||||
+ format_each = static_runtime_link_format,
|
||||
+ )
|
||||
|
||||
def _get_dirname(file):
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.to_string_lossy()
|
||||
.to_ascii_lowercase();
|
||||
+ if file_name_lower.contains(".tmp") || file_name_lower.ends_with(".rcgu.o") {
|
||||
+ // MSVC link actions can leave transient `*.exe.tmp*` and
|
||||
+ // Native Windows Rust link actions can leave transient `*.exe.tmp*` and
|
||||
+ // per-codegen-unit `*.rcgu.o` outputs next to the final binary.
|
||||
+ // Those are not stable linker search-path inputs.
|
||||
+ continue;
|
||||
|
||||
32
third_party/v8/BUILD.bazel
vendored
32
third_party/v8/BUILD.bazel
vendored
@@ -89,15 +89,15 @@ alias(
|
||||
alias(
|
||||
name = "rusty_v8_archive_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-apple-darwin": ":v8_149_2_0_aarch64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-pc-windows-gnullvm": ":v8_149_2_0_aarch64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-pc-windows-msvc": ":v8_149_2_0_aarch64_pc_windows_msvc",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-unknown-linux-gnu": ":v8_149_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": ":v8_149_2_0_aarch64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-gnullvm": ":v8_149_2_0_aarch64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":v8_149_2_0_aarch64_pc_windows_msvc",
|
||||
"@rules_rs//rs/platforms/config:aarch64-unknown-linux-gnu": ":v8_149_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
":platform_aarch64_unknown_linux_musl": ":v8_149_2_0_aarch64_unknown_linux_musl_release_base",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-apple-darwin": ":v8_149_2_0_x86_64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-pc-windows-gnullvm": ":v8_149_2_0_x86_64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-pc-windows-msvc": ":v8_149_2_0_x86_64_pc_windows_msvc",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-unknown-linux-gnu": ":v8_149_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": ":v8_149_2_0_x86_64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-gnullvm": ":v8_149_2_0_x86_64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":v8_149_2_0_x86_64_pc_windows_msvc",
|
||||
"@rules_rs//rs/platforms/config:x86_64-unknown-linux-gnu": ":v8_149_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
":platform_x86_64_unknown_linux_musl": ":v8_149_2_0_x86_64_unknown_linux_musl_release",
|
||||
"//conditions:default": ":v8_149_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
}),
|
||||
@@ -106,15 +106,15 @@ alias(
|
||||
alias(
|
||||
name = "rusty_v8_binding_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-apple-darwin": ":src_binding_release_aarch64_apple_darwin_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-pc-windows-gnullvm": ":src_binding_release_aarch64_pc_windows_gnullvm_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-pc-windows-msvc": ":src_binding_release_aarch64_pc_windows_msvc_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:aarch64-unknown-linux-gnu": ":src_binding_release_aarch64_unknown_linux_gnu_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": ":src_binding_release_aarch64_apple_darwin_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-gnullvm": ":src_binding_release_aarch64_pc_windows_gnullvm_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":src_binding_release_aarch64_pc_windows_msvc_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:aarch64-unknown-linux-gnu": ":src_binding_release_aarch64_unknown_linux_gnu_149_2_0_release",
|
||||
":platform_aarch64_unknown_linux_musl": ":src_binding_release_aarch64_unknown_linux_musl_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-apple-darwin": ":src_binding_release_x86_64_apple_darwin_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-pc-windows-gnullvm": ":src_binding_release_x86_64_pc_windows_gnullvm_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-pc-windows-msvc": ":src_binding_release_x86_64_pc_windows_msvc_149_2_0_release",
|
||||
"@rules_rs//rs/experimental/platforms/config:x86_64-unknown-linux-gnu": ":src_binding_release_x86_64_unknown_linux_gnu_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": ":src_binding_release_x86_64_apple_darwin_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-gnullvm": ":src_binding_release_x86_64_pc_windows_gnullvm_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":src_binding_release_x86_64_pc_windows_msvc_149_2_0_release",
|
||||
"@rules_rs//rs/platforms/config:x86_64-unknown-linux-gnu": ":src_binding_release_x86_64_unknown_linux_gnu_149_2_0_release",
|
||||
":platform_x86_64_unknown_linux_musl": ":src_binding_release_x86_64_unknown_linux_musl_149_2_0_release",
|
||||
"//conditions:default": ":src_binding_release_x86_64_unknown_linux_gnu_149_2_0_release",
|
||||
}),
|
||||
|
||||
@@ -109,7 +109,7 @@ def _rust_argument_comment_lint_aspect_impl(target, ctx):
|
||||
attr = ctx.rule.attr,
|
||||
file = ctx.file,
|
||||
toolchain = toolchain,
|
||||
tool_path = ctx.executable._driver.path,
|
||||
tool_file = ctx.executable._driver,
|
||||
cc_toolchain = cc_toolchain,
|
||||
feature_configuration = feature_configuration,
|
||||
crate_info = crate_info,
|
||||
@@ -142,7 +142,7 @@ def _rust_argument_comment_lint_aspect_impl(target, ctx):
|
||||
)
|
||||
|
||||
ctx.actions.run(
|
||||
executable = ctx.executable._process_wrapper,
|
||||
executable = toolchain.process_wrapper,
|
||||
inputs = action_inputs,
|
||||
outputs = [success_marker],
|
||||
env = env,
|
||||
|
||||
Reference in New Issue
Block a user