diff --git a/.github/workflows/evidence.yml b/.github/workflows/evidence.yml index 3d46dcceaf..1402dd3b5e 100644 --- a/.github/workflows/evidence.yml +++ b/.github/workflows/evidence.yml @@ -285,8 +285,10 @@ jobs: mkdir -p "$det" first_root="$(bazel info "${flags[@]}" execution_root | tr -d '\r')" second_root="$(bazel "--output_base=$base" info "${flags[@]}" execution_root | tr -d '\r')" - bazel cquery --noshow_progress --output=files "${patterns[@]}" "${flags[@]}" | tr -d '\r' > "$det/first.txt" - bazel "--output_base=$base" cquery --noshow_progress --output=files "${patterns[@]}" "${flags[@]}" | tr -d '\r' > "$det/relocated.txt" + # cquery takes one expression. evidence_inputs.rs joins the scope with + # single spaces and only allows // or @rules_dx_ patterns, so a union is safe. + bazel cquery --noshow_progress --output=files "${DX_SCOPE// / + }" "${flags[@]}" | tr -d '\r' > "$det/first.txt" + bazel "--output_base=$base" cquery --noshow_progress --output=files "${DX_SCOPE// / + }" "${flags[@]}" | tr -d '\r' > "$det/relocated.txt" sort -u "$det/first.txt" "$det/relocated.txt" > "$det/files.txt" while read -r f; do [ -d "$first_root/$f" ] && continue diff --git a/MODULE.bazel b/MODULE.bazel index 5e9410fed9..da98f88c59 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,6 +14,7 @@ single_version_override( "//patches/rules_rust:pipelined_rmeta_path.patch", "//patches/rules_rust:crate_universe_root_lookup.patch", "//patches/rules_rust:exec_cc_toolchain_env.patch", + "//patches/rules_rust:msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/cli/adopt/BUILD.bazel b/cli/adopt/BUILD.bazel index ead7f197ad..d205b20e21 100644 --- a/cli/adopt/BUILD.bazel +++ b/cli/adopt/BUILD.bazel @@ -65,6 +65,7 @@ dx_rust_crate( "//patches/rules_rust:pipelined_rmeta_path.patch", "//patches/rules_rust:crate_universe_root_lookup.patch", "//patches/rules_rust:exec_cc_toolchain_env.patch", + "//patches/rules_rust:msvc_pdb_output.patch", "//patches/llvm:libunwind_copy.patch", "//patches/llvm:clang_cl_crt_default_lib.patch", "//patches/windows_support:host_tools.patch", diff --git a/cli/adopt/src/overrides.rs b/cli/adopt/src/overrides.rs index 1aba51a679..b0cae4d5af 100644 --- a/cli/adopt/src/overrides.rs +++ b/cli/adopt/src/overrides.rs @@ -75,6 +75,10 @@ pub const OVERRIDES: &[Override] = &[ file: "exec_cc_toolchain_env.patch", content: include_str!("../../../patches/rules_rust/exec_cc_toolchain_env.patch"), }, + OverridePatch { + file: "msvc_pdb_output.patch", + content: include_str!("../../../patches/rules_rust/msvc_pdb_output.patch"), + }, ], }, Override { @@ -946,7 +950,7 @@ mod tests { "\nsingle_version_override(\n module_name = \"aspect_rules_ts\",\n patch_strip = 1,\n patches = [\"//third_party/rules_dx:aspect_rules_ts.typecheck_root_dir.patch\"],\n version = \"3.10.1\",\n)\n" )); assert!(rendered.contains( - " patches = [\n \"//third_party/rules_dx:rules_rust.clippy_metadata_inputs.patch\",\n \"//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch\",\n \"//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch\",\n \"//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch\",\n ],\n" + " patches = [\n \"//third_party/rules_dx:rules_rust.clippy_metadata_inputs.patch\",\n \"//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch\",\n \"//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch\",\n \"//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch\",\n \"//third_party/rules_dx:rules_rust.msvc_pdb_output.patch\",\n ],\n" )); assert!(rendered.contains( r#" diff --git a/families/android/third_party/rules_dx/BUILD.bazel b/families/android/third_party/rules_dx/BUILD.bazel index 702fa35fa4..cf5203dfe1 100644 --- a/families/android/third_party/rules_dx/BUILD.bazel +++ b/families/android/third_party/rules_dx/BUILD.bazel @@ -28,6 +28,7 @@ exports_files([ "rules_rust.clippy_metadata_inputs.patch", "rules_rust.crate_universe_root_lookup.patch", "rules_rust.exec_cc_toolchain_env.patch", + "rules_rust.msvc_pdb_output.patch", "rules_rust.pipelined_rmeta_path.patch", "windows_support.host_tools.patch", "windows_support.hostarm64_packages.patch", diff --git a/families/android/third_party/rules_dx/rules_dx.MODULE.bazel b/families/android/third_party/rules_dx/rules_dx.MODULE.bazel index eefcec07c0..cde1f2e316 100644 --- a/families/android/third_party/rules_dx/rules_dx.MODULE.bazel +++ b/families/android/third_party/rules_dx/rules_dx.MODULE.bazel @@ -10,6 +10,7 @@ single_version_override( "//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch", "//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch", "//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch", + "//third_party/rules_dx:rules_rust.msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/families/android/third_party/rules_dx/rules_rust.msvc_pdb_output.patch b/families/android/third_party/rules_dx/rules_rust.msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/families/android/third_party/rules_dx/rules_rust.msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/families/apple/third_party/rules_dx/BUILD.bazel b/families/apple/third_party/rules_dx/BUILD.bazel index 702fa35fa4..cf5203dfe1 100644 --- a/families/apple/third_party/rules_dx/BUILD.bazel +++ b/families/apple/third_party/rules_dx/BUILD.bazel @@ -28,6 +28,7 @@ exports_files([ "rules_rust.clippy_metadata_inputs.patch", "rules_rust.crate_universe_root_lookup.patch", "rules_rust.exec_cc_toolchain_env.patch", + "rules_rust.msvc_pdb_output.patch", "rules_rust.pipelined_rmeta_path.patch", "windows_support.host_tools.patch", "windows_support.hostarm64_packages.patch", diff --git a/families/apple/third_party/rules_dx/rules_dx.MODULE.bazel b/families/apple/third_party/rules_dx/rules_dx.MODULE.bazel index eefcec07c0..cde1f2e316 100644 --- a/families/apple/third_party/rules_dx/rules_dx.MODULE.bazel +++ b/families/apple/third_party/rules_dx/rules_dx.MODULE.bazel @@ -10,6 +10,7 @@ single_version_override( "//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch", "//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch", "//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch", + "//third_party/rules_dx:rules_rust.msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/families/apple/third_party/rules_dx/rules_rust.msvc_pdb_output.patch b/families/apple/third_party/rules_dx/rules_rust.msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/families/apple/third_party/rules_dx/rules_rust.msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/families/beam/third_party/rules_dx/BUILD.bazel b/families/beam/third_party/rules_dx/BUILD.bazel index 8f96a3f678..9424b52c06 100644 --- a/families/beam/third_party/rules_dx/BUILD.bazel +++ b/families/beam/third_party/rules_dx/BUILD.bazel @@ -29,6 +29,7 @@ exports_files([ "rules_rust.clippy_metadata_inputs.patch", "rules_rust.crate_universe_root_lookup.patch", "rules_rust.exec_cc_toolchain_env.patch", + "rules_rust.msvc_pdb_output.patch", "rules_rust.pipelined_rmeta_path.patch", "windows_support.host_tools.patch", "windows_support.hostarm64_packages.patch", diff --git a/families/beam/third_party/rules_dx/rules_dx.MODULE.bazel b/families/beam/third_party/rules_dx/rules_dx.MODULE.bazel index 0b7b573bd4..64819c9a87 100644 --- a/families/beam/third_party/rules_dx/rules_dx.MODULE.bazel +++ b/families/beam/third_party/rules_dx/rules_dx.MODULE.bazel @@ -10,6 +10,7 @@ single_version_override( "//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch", "//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch", "//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch", + "//third_party/rules_dx:rules_rust.msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/families/beam/third_party/rules_dx/rules_rust.msvc_pdb_output.patch b/families/beam/third_party/rules_dx/rules_rust.msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/families/beam/third_party/rules_dx/rules_rust.msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/families/dotnet/third_party/rules_dx/BUILD.bazel b/families/dotnet/third_party/rules_dx/BUILD.bazel index 702fa35fa4..cf5203dfe1 100644 --- a/families/dotnet/third_party/rules_dx/BUILD.bazel +++ b/families/dotnet/third_party/rules_dx/BUILD.bazel @@ -28,6 +28,7 @@ exports_files([ "rules_rust.clippy_metadata_inputs.patch", "rules_rust.crate_universe_root_lookup.patch", "rules_rust.exec_cc_toolchain_env.patch", + "rules_rust.msvc_pdb_output.patch", "rules_rust.pipelined_rmeta_path.patch", "windows_support.host_tools.patch", "windows_support.hostarm64_packages.patch", diff --git a/families/dotnet/third_party/rules_dx/rules_dx.MODULE.bazel b/families/dotnet/third_party/rules_dx/rules_dx.MODULE.bazel index eefcec07c0..cde1f2e316 100644 --- a/families/dotnet/third_party/rules_dx/rules_dx.MODULE.bazel +++ b/families/dotnet/third_party/rules_dx/rules_dx.MODULE.bazel @@ -10,6 +10,7 @@ single_version_override( "//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch", "//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch", "//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch", + "//third_party/rules_dx:rules_rust.msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/families/dotnet/third_party/rules_dx/rules_rust.msvc_pdb_output.patch b/families/dotnet/third_party/rules_dx/rules_rust.msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/families/dotnet/third_party/rules_dx/rules_rust.msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/families/jvm/third_party/rules_dx/BUILD.bazel b/families/jvm/third_party/rules_dx/BUILD.bazel index 8f96a3f678..9424b52c06 100644 --- a/families/jvm/third_party/rules_dx/BUILD.bazel +++ b/families/jvm/third_party/rules_dx/BUILD.bazel @@ -29,6 +29,7 @@ exports_files([ "rules_rust.clippy_metadata_inputs.patch", "rules_rust.crate_universe_root_lookup.patch", "rules_rust.exec_cc_toolchain_env.patch", + "rules_rust.msvc_pdb_output.patch", "rules_rust.pipelined_rmeta_path.patch", "windows_support.host_tools.patch", "windows_support.hostarm64_packages.patch", diff --git a/families/jvm/third_party/rules_dx/rules_dx.MODULE.bazel b/families/jvm/third_party/rules_dx/rules_dx.MODULE.bazel index 0b7b573bd4..64819c9a87 100644 --- a/families/jvm/third_party/rules_dx/rules_dx.MODULE.bazel +++ b/families/jvm/third_party/rules_dx/rules_dx.MODULE.bazel @@ -10,6 +10,7 @@ single_version_override( "//third_party/rules_dx:rules_rust.pipelined_rmeta_path.patch", "//third_party/rules_dx:rules_rust.crate_universe_root_lookup.patch", "//third_party/rules_dx:rules_rust.exec_cc_toolchain_env.patch", + "//third_party/rules_dx:rules_rust.msvc_pdb_output.patch", ], version = "0.75.0", ) diff --git a/families/jvm/third_party/rules_dx/rules_rust.msvc_pdb_output.patch b/families/jvm/third_party/rules_dx/rules_rust.msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/families/jvm/third_party/rules_dx/rules_rust.msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/patches/README.md b/patches/README.md index 8af22db49c..12ee26cd8f 100644 --- a/patches/README.md +++ b/patches/README.md @@ -28,7 +28,7 @@ files but leaves the `include()` out and says so on stderr. Without a | Module | Version | Patches | Why | | --- | --- | --- | --- | -| `rules_rust` | 0.75.0 | `clippy_metadata_inputs.patch`, `pipelined_rmeta_path.patch`, `crate_universe_root_lookup.patch`, `exec_cc_toolchain_env.patch` | Rust on Windows (MSVC stdlib link flags, bazelbuild/rules_rust#4376); clippy reads dependency `.rmeta`; the full rustc action writes its own `.rmeta` so it does not hit the read-only one from the metadata action (bazelbuild/rules_rust#3383, #3662; drop when a rules_rust release has it); `crate_universe` looks up the root `MODULE.bazel` only in the root module, so a consumer without a root `BUILD.bazel` can use `dx_crates` (#6144); build scripts get `HOST_CC`/`HOST_CXX`/`HOST_AR`/`HOST_CFLAGS`/`HOST_CXXFLAGS` from the exec cc toolchain and `TARGET_*` from the target one | +| `rules_rust` | 0.75.0 | `clippy_metadata_inputs.patch`, `pipelined_rmeta_path.patch`, `crate_universe_root_lookup.patch`, `exec_cc_toolchain_env.patch`, `msvc_pdb_output.patch` | Rust on Windows (MSVC stdlib link flags, bazelbuild/rules_rust#4376); clippy reads dependency `.rmeta`; the full rustc action writes its own `.rmeta` so it does not hit the read-only one from the metadata action (bazelbuild/rules_rust#3383, #3662; drop when a rules_rust release has it); `crate_universe` looks up the root `MODULE.bazel` only in the root module, so a consumer without a root `BUILD.bazel` can use `dx_crates` (#6144); build scripts get `HOST_CC`/`HOST_CXX`/`HOST_AR`/`HOST_CFLAGS`/`HOST_CXXFLAGS` from the exec cc toolchain and `TARGET_*` from the target one; MSVC `bin` and `cdylib` crates always declare their `.pdb`, since rustc writes it whatever the strip level (rust-lang/rust#115120) | | `rules_android` | 0.8.0 | `bundle_keystore_properties.patch` | App Bundles with key rotation: write the oldest-signer properties file instead of reading the removed `_bundle_keystore_properties` attribute (#3739) | | `rules_cuda` | 0.4.0-beta1 | `msvc_dlink_crt.patch`, `redist_cccl_key.patch` | `nvcc -dlink` on Windows gets the same `/MD` or `/MT` as the compile action, so rdc links do not mix LIBCMT with the dynamic CRT (#4704); CUDA 13.3+ redist manifests key CCCL as `cccl` instead of `cuda_cccl`; the helper accepts both (bazel-contrib/rules_cuda#523, merged; drop on the next release, #8365) | | `protobuf` | 36.2 | `no_crate_universe.patch` | Drops protobuf's own `crate_universe` use so it does not clash with `dx_crates` | diff --git a/patches/rules_rust/BUILD.bazel b/patches/rules_rust/BUILD.bazel index 1a7795bcd4..a7db92e18b 100644 --- a/patches/rules_rust/BUILD.bazel +++ b/patches/rules_rust/BUILD.bazel @@ -4,6 +4,7 @@ exports_files([ "clippy_metadata_inputs.patch", "crate_universe_root_lookup.patch", "exec_cc_toolchain_env.patch", + "msvc_pdb_output.patch", "pipelined_rmeta_path.patch", ]) diff --git a/patches/rules_rust/msvc_pdb_output.patch b/patches/rules_rust/msvc_pdb_output.patch new file mode 100644 index 0000000000..4ee47d9d3f --- /dev/null +++ b/patches/rules_rust/msvc_pdb_output.patch @@ -0,0 +1,13 @@ +--- a/rust/private/rustc.bzl ++++ b/rust/private/rustc.bzl +@@ -2048,7 +2048,9 @@ + pdb_file = None + dsym_folder = None + if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link: +- if toolchain.target_abi == "msvc" and compilation_mode.strip_level == "none": ++ # rustc ignores -Cstrip on MSVC and always links with /DEBUG, so the PDB is written ++ # whatever the strip level (rust-lang/rust#115120). ++ if toolchain.target_abi == "msvc": + pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) + action_outputs.append(pdb_file) + elif toolchain.target_os in ["macos", "darwin"]: diff --git a/rust/rules/defs.bzl b/rust/rules/defs.bzl index dbda602df8..f37213505e 100644 --- a/rust/rules/defs.bzl +++ b/rust/rules/defs.bzl @@ -30,7 +30,8 @@ _CL_EXE = Label("//cc/toolchains:msvc_selected") MSVC_LINK_FLAGS = ["-Clink-arg=kernel32.lib", "-Clink-arg=ntdll.lib"] _MSVC_OPT = Label("//rust/rules:msvc_opt") -# rustc always passes /DEBUG; /Brepro makes the PDB GUID a content hash (#8409, #8410). +# rustc always passes /DEBUG and msvc_pdb_output.patch declares the PDB as an output; +# /Brepro makes the PDB GUID a content hash (#8409, #8410). MSVC_OPT_LINK_FLAGS = ["-Clink-arg=/Brepro"] + REPRODUCIBLE_PDB_LINK_FLAGS _NO_STATIC_CPP_RUNTIMES = "-static_link_cpp_runtimes" _EXTRA_RUSTC_FLAG = str(Label("@rules_rust//rust/settings:extra_rustc_flag"))