mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Upgrade rules_rs and llvm to latest BCR versions (#18397)
## Why This branch brings the Bazel module pins for `rules_rs` and `llvm` up to the latest BCR releases and aligns the root direct dependencies with the versions the module graph already resolves to. That gives us a few concrete wins: - picks up newer upstream fixes in the `rules_rs` / `rules_rust` stack, including work around repo-rule nondeterminism and default Cargo binary target generation - picks up test sharding support from the newer `rules_rust` stack ([hermeticbuild/rules_rust#13](https://github.com/hermeticbuild/rules_rust/pull/13)) - picks up newer built-in knowledge for common system crates like `gio-sys`, `glib-sys`, `gobject-sys`, `libgit2-sys`, and `libssh2-sys`, which gives us a future path to reduce custom build-script handling - reduces local patch maintenance by dropping fixes that are now upstream and rebasing the remaining Windows patch stack onto a newer upstream base - removes the direct-dependency warnings from `bazel-lock-check` by making the root pins match the resolved graph ## What Changed - bump `rules_rs` from `0.0.43` to `0.0.58` - bump `llvm` from `0.6.8` to `0.7.1` - bump `bazel_skylib` from `1.8.2` to `1.9.0` so the root direct dep matches the resolved graph - regenerate `MODULE.bazel.lock` for the updated module graph - refresh the remaining Windows-specific patch stack against the newer upstream sources: - `patches/rules_rs_windows_gnullvm_exec.patch` - `patches/rules_rs_windows_exec_linker.patch` - `patches/rules_rust_windows_exec_std.patch` - `patches/rules_rust_windows_msvc_direct_link_args.patch` - remove patches that are no longer needed because the underlying fixes are upstream now: - `patches/rules_rs_delete_git_worktree_pointer.patch` - `patches/rules_rust_repository_set_exec_constraints.patch` ## Validation - `just bazel-lock-update` - `just bazel-lock-check` --------- Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
f705f42ba8
commit
680c4102ae
+5
-7
@@ -1,8 +1,8 @@
|
||||
module(name = "codex")
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.8.2")
|
||||
bazel_dep(name = "bazel_skylib", version = "1.9.0")
|
||||
bazel_dep(name = "platforms", version = "1.0.0")
|
||||
bazel_dep(name = "llvm", version = "0.6.8")
|
||||
bazel_dep(name = "llvm", version = "0.7.1")
|
||||
# The upstream LLVM archive contains a few unix-only symlink entries and is
|
||||
# missing a couple of MinGW compatibility archives that windows-gnullvm needs
|
||||
# during extraction and linking, so patch it until upstream grows native support.
|
||||
@@ -78,8 +78,8 @@ use_repo(osx, "macos_sdk")
|
||||
bazel_dep(name = "apple_support", version = "2.1.0")
|
||||
bazel_dep(name = "rules_cc", version = "0.2.16")
|
||||
bazel_dep(name = "rules_platform", version = "0.1.0")
|
||||
bazel_dep(name = "rules_rs", version = "0.0.43")
|
||||
# `rules_rs` 0.0.43 does not model `windows-gnullvm` as a distinct Windows exec
|
||||
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.
|
||||
single_version_override(
|
||||
@@ -87,10 +87,9 @@ single_version_override(
|
||||
patch_strip = 1,
|
||||
patches = [
|
||||
"//patches:rules_rs_windows_gnullvm_exec.patch",
|
||||
"//patches:rules_rs_delete_git_worktree_pointer.patch",
|
||||
"//patches:rules_rs_windows_exec_linker.patch",
|
||||
],
|
||||
version = "0.0.43",
|
||||
version = "0.0.58",
|
||||
)
|
||||
|
||||
rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust")
|
||||
@@ -108,7 +107,6 @@ rules_rust.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",
|
||||
"//patches:rules_rust_repository_set_exec_constraints.patch",
|
||||
],
|
||||
strip = 1,
|
||||
)
|
||||
|
||||
Generated
+78
-19
File diff suppressed because one or more lines are too long
@@ -10,7 +10,6 @@ exports_files([
|
||||
"rules_rust_windows_exec_bin_target.patch",
|
||||
"rules_rust_windows_exec_std.patch",
|
||||
"rules_rust_windows_process_wrapper_skip_temp_outputs.patch",
|
||||
"rules_rust_repository_set_exec_constraints.patch",
|
||||
"rules_rust_windows_msvc_direct_link_args.patch",
|
||||
"rules_rust_windows_gnullvm_build_script.patch",
|
||||
"rules_rs_windows_gnullvm_exec.patch",
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
diff --git a/rs/private/crate_git_repository.bzl b/rs/private/crate_git_repository.bzl
|
||||
--- a/rs/private/crate_git_repository.bzl
|
||||
+++ b/rs/private/crate_git_repository.bzl
|
||||
@@ -35,6 +35,14 @@
|
||||
"HEAD"
|
||||
])
|
||||
if result.return_code != 0:
|
||||
fail(result.stderr)
|
||||
|
||||
+ # Remove .git worktree pointer file. It contains an absolute path to
|
||||
+ # the bazel output base which is machine-specific and non-deterministic.
|
||||
+ # Leaving it in pollutes compile_data globs and causes AC misses.
|
||||
+ #
|
||||
+ # Note that bazelbuild/rules_rust ignores .git (among other paths) during splicing:
|
||||
+ # https://github.com/bazelbuild/rules_rust/blob/ca4915c0210bcd240152a5333ecb24d266bda144/crate_universe/src/splicing/splicer.rs#L42
|
||||
+ rctx.delete(root.get_child(".git"))
|
||||
+
|
||||
if strip_prefix:
|
||||
dest_link = dest_dir.get_child(strip_prefix)
|
||||
if not dest_link.exists:
|
||||
@@ -3,10 +3,9 @@
|
||||
# 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
|
||||
index 67e491c..3f1cff5 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -50,6 +50,8 @@ def declare_rustc_toolchains(
|
||||
@@ -58,6 +58,8 @@ def declare_rustc_toolchains(
|
||||
rust_toolchain(
|
||||
name = rust_toolchain_name,
|
||||
rust_doc = "{}rustdoc".format(rustc_repo_label),
|
||||
@@ -15,10 +14,10 @@ index 67e491c..3f1cff5 100644
|
||||
rust_std = select(rust_std_select),
|
||||
rustc = "{}rustc".format(rustc_repo_label),
|
||||
cargo = "{}cargo".format(cargo_repo_label),
|
||||
@@ -82,7 +84,20 @@ def declare_rustc_toolchains(
|
||||
stdlib_linkflags = select({
|
||||
"@platforms//os:freebsd": ["-lexecinfo", "-lpthread"],
|
||||
"@platforms//os:macos": ["-lSystem", "-lresolv"],
|
||||
@@ -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",
|
||||
@@ -38,17 +37,12 @@ index 67e491c..3f1cff5 100644
|
||||
}),
|
||||
default_edition = edition,
|
||||
diff --git a/rs/private/rustc_repository.bzl b/rs/private/rustc_repository.bzl
|
||||
index f4f0286..6558bb2 100644
|
||||
--- a/rs/private/rustc_repository.bzl
|
||||
+++ b/rs/private/rustc_repository.bzl
|
||||
@@ -1,13 +1,28 @@
|
||||
load("@rules_rust//rust/platform:triple.bzl", "triple")
|
||||
load(
|
||||
"@rules_rust//rust/private:repository_utils.bzl",
|
||||
"BUILD_for_compiler",
|
||||
@@ -7,10 +7,24 @@ load(
|
||||
)
|
||||
load(":rust_repository_utils.bzl", "download_and_extract", "RUST_REPOSITORY_COMMON_ATTR")
|
||||
|
||||
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
|
||||
+
|
||||
+_WINDOWS_EXEC_LINKER_BUILD = """
|
||||
+filegroup(
|
||||
+ name = "rust-lld",
|
||||
@@ -56,18 +50,17 @@ index f4f0286..6558bb2 100644
|
||||
+ visibility = ["//visibility:public"],
|
||||
+)
|
||||
+"""
|
||||
+
|
||||
|
||||
def _rustc_repository_impl(rctx):
|
||||
exec_triple = triple(rctx.attr.triple)
|
||||
download_and_extract(rctx, "rustc", "rustc", exec_triple)
|
||||
- rctx.file("BUILD.bazel", BUILD_for_compiler(exec_triple))
|
||||
+ build_file = BUILD_for_compiler(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_file += _WINDOWS_EXEC_LINKER_BUILD
|
||||
+ rctx.file("BUILD.bazel", build_file)
|
||||
|
||||
return rctx.repo_metadata(reproducible = True)
|
||||
+ 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))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Scope: experimental platform/toolchain naming only; no Cargo target changes.
|
||||
|
||||
diff --git a/rs/experimental/platforms/triples.bzl b/rs/experimental/platforms/triples.bzl
|
||||
index 3ca3bb1..dd15656 100644
|
||||
--- a/rs/experimental/platforms/triples.bzl
|
||||
+++ b/rs/experimental/platforms/triples.bzl
|
||||
@@ -30,7 +30,9 @@ SUPPORTED_EXEC_TRIPLES = [
|
||||
@@ -16,22 +15,21 @@ index 3ca3bb1..dd15656 100644
|
||||
"aarch64-apple-darwin",
|
||||
]
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
index b9a0ce1..67e491c 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -10,6 +10,11 @@ def _channel(version):
|
||||
@@ -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 declare_rustc_toolchains(
|
||||
*,
|
||||
version,
|
||||
@@ -23,15 +28,14 @@ def declare_rustc_toolchains(
|
||||
|
||||
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)
|
||||
@@ -50,7 +48,7 @@ index b9a0ce1..67e491c 100644
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -90,11 +94,8 @@ def declare_rustc_toolchains(
|
||||
@@ -116,11 +120,8 @@ def declare_rustc_toolchains(
|
||||
target_key = sanitize_triple(target_triple)
|
||||
|
||||
native.toolchain(
|
||||
@@ -65,24 +63,22 @@ index b9a0ce1..67e491c 100644
|
||||
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
|
||||
index a219209..ecb6b05 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
@@ -1,8 +1,13 @@
|
||||
@@ -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"):
|
||||
return "nightly"
|
||||
@@ -22,14 +27,13 @@ def declare_rustfmt_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
@@ -111,15 +107,71 @@ index a219209..ecb6b05 100644
|
||||
- "@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
|
||||
index 7bb0205..ace556b 100644
|
||||
--- a/rs/experimental/toolchains/module_extension.bzl
|
||||
+++ b/rs/experimental/toolchains/module_extension.bzl
|
||||
@@ -37,6 +37,11 @@ def _normalize_arch_name(arch):
|
||||
@@ -39,6 +39,11 @@ def _normalize_arch_name(arch):
|
||||
return "aarch64"
|
||||
return arch
|
||||
|
||||
@@ -131,7 +183,7 @@ index 7bb0205..ace556b 100644
|
||||
def _sanitize_path_fragment(path):
|
||||
return path.replace("/", "_").replace(":", "_")
|
||||
|
||||
@@ -181,7 +186,7 @@ def _toolchains_impl(mctx):
|
||||
@@ -209,7 +214,7 @@ def _toolchains_impl(mctx):
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
|
||||
@@ -140,7 +192,7 @@ index 7bb0205..ace556b 100644
|
||||
rustc_name = "rustc_{}_{}".format(triple_suffix, version_key)
|
||||
|
||||
rustc_repository(
|
||||
@@ -230,7 +235,7 @@ def _toolchains_impl(mctx):
|
||||
@@ -258,7 +263,7 @@ def _toolchains_impl(mctx):
|
||||
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
@@ -149,3 +201,12 @@ index 7bb0205..ace556b 100644
|
||||
|
||||
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),
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# What: let `rules_rust` repository_set entries specify an explicit exec-platform
|
||||
# constraint set.
|
||||
# Why: codex needs Windows nightly lint toolchains to run helper binaries on an
|
||||
# MSVC exec platform while still targeting `windows-gnullvm` crates.
|
||||
|
||||
diff --git a/rust/extensions.bzl b/rust/extensions.bzl
|
||||
--- a/rust/extensions.bzl
|
||||
+++ b/rust/extensions.bzl
|
||||
@@ -52,6 +52,7 @@ def _rust_impl(module_ctx):
|
||||
"allocator_library": repository_set.allocator_library,
|
||||
"dev_components": repository_set.dev_components,
|
||||
"edition": repository_set.edition,
|
||||
+ "exec_compatible_with": [str(v) for v in repository_set.exec_compatible_with] if repository_set.exec_compatible_with else None,
|
||||
"exec_triple": repository_set.exec_triple,
|
||||
"extra_target_triples": {repository_set.target_triple: [str(v) for v in repository_set.target_compatible_with]},
|
||||
"name": repository_set.name,
|
||||
@@ -166,6 +167,9 @@ _COMMON_TAG_KWARGS = {
|
||||
|
||||
_RUST_REPOSITORY_SET_TAG_ATTRS = {
|
||||
+ "exec_compatible_with": attr.label_list(
|
||||
+ doc = "Execution platform constraints for this repository_set.",
|
||||
+ ),
|
||||
"exec_triple": attr.string(
|
||||
doc = "Exec triple for this repository_set.",
|
||||
),
|
||||
"name": attr.string(
|
||||
@@ -7,7 +7,7 @@
|
||||
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
--- a/rust/toolchain.bzl
|
||||
+++ b/rust/toolchain.bzl
|
||||
@@ -209,6 +209,7 @@ def _generate_sysroot(
|
||||
@@ -211,6 +211,7 @@
|
||||
clippy = None,
|
||||
cargo_clippy = None,
|
||||
llvm_tools = None,
|
||||
@@ -15,23 +15,22 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = None,
|
||||
rustfmt = None,
|
||||
linker = None):
|
||||
@@ -312,7 +313,15 @@ def _generate_sysroot(
|
||||
|
||||
@@ -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(
|
||||
@@ -323,6 +332,7 @@ def _generate_sysroot(
|
||||
@@ -325,6 +334,7 @@
|
||||
"cargo-clippy: {}".format(cargo_clippy),
|
||||
"linker: {}".format(linker),
|
||||
"llvm_tools: {}".format(llvm_tools),
|
||||
@@ -39,7 +38,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
"rust_std: {}".format(rust_std),
|
||||
"rustc_lib: {}".format(rustc_lib),
|
||||
"rustc: {}".format(rustc),
|
||||
@@ -340,6 +350,7 @@ def _generate_sysroot(
|
||||
@@ -342,6 +352,7 @@
|
||||
cargo_clippy = sysroot_cargo_clippy,
|
||||
clippy = sysroot_clippy,
|
||||
linker = sysroot_linker,
|
||||
@@ -47,7 +46,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = sysroot_rust_std,
|
||||
rustc = sysroot_rustc,
|
||||
rustc_lib = sysroot_rustc_lib,
|
||||
@@ -410,12 +421,14 @@ def _rust_toolchain_impl(ctx):
|
||||
@@ -412,12 +423,14 @@
|
||||
)
|
||||
|
||||
rust_std = ctx.attr.rust_std
|
||||
@@ -62,7 +61,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = rust_std,
|
||||
rustfmt = ctx.file.rustfmt,
|
||||
clippy = ctx.file.clippy_driver,
|
||||
@@ -452,7 +465,7 @@ def _rust_toolchain_impl(ctx):
|
||||
@@ -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)
|
||||
@@ -71,7 +70,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
|
||||
linking_context = cc_common.create_linking_context(
|
||||
linker_inputs = depset([
|
||||
@@ -793,6 +806,10 @@ rust_toolchain = rule(
|
||||
@@ -807,6 +820,10 @@
|
||||
doc = "The Rust standard library.",
|
||||
mandatory = True,
|
||||
),
|
||||
@@ -85,7 +84,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
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
|
||||
@@ -341,6 +341,7 @@ rust_toolchain(
|
||||
@@ -342,6 +342,7 @@
|
||||
name = "{toolchain_name}",
|
||||
rust_doc = "//:rustdoc",
|
||||
rust_std = "//:rust_std-{target_triple}",
|
||||
@@ -93,15 +92,15 @@ diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.b
|
||||
rustc = "//:rustc",
|
||||
linker = {linker_label},
|
||||
linker_type = {linker_type},
|
||||
@@ -384,6 +385,7 @@ def BUILD_for_rust_toolchain(
|
||||
include_llvm_tools,
|
||||
include_linker,
|
||||
@@ -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,
|
||||
@@ -405,6 +407,7 @@ def BUILD_for_rust_toolchain(
|
||||
@@ -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.
|
||||
@@ -109,7 +108,7 @@ diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.b
|
||||
stdlib_linkflags (list, optional): Overridden flags needed for linking to rust
|
||||
stdlib, akin to BAZEL_LINKLIBS. Defaults to
|
||||
None.
|
||||
@@ -453,6 +456,7 @@ def BUILD_for_rust_toolchain(
|
||||
@@ -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),
|
||||
@@ -120,7 +119,7 @@ diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.b
|
||||
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -1011,7 +1011,10 @@ def construct_arguments(
|
||||
@@ -1010,7 +1010,10 @@
|
||||
if build_metadata and not use_json_output:
|
||||
fail("build_metadata requires parse_json_output")
|
||||
|
||||
@@ -135,7 +134,7 @@ diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
--- a/rust/repositories.bzl
|
||||
+++ b/rust/repositories.bzl
|
||||
@@ -536,6 +536,18 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
@@ -574,6 +574,18 @@
|
||||
build_components.append(rust_stdlib_content)
|
||||
sha256s.update(rust_stdlib_sha256)
|
||||
|
||||
@@ -154,7 +153,7 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
stdlib_linkflags = None
|
||||
if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx.os.environ:
|
||||
stdlib_linkflags = ctx.os.environ["BAZEL_RUST_STDLIB_LINKFLAGS"].split(":")
|
||||
@@ -552,6 +564,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
@@ -590,6 +602,7 @@
|
||||
include_llvm_tools = include_llvm_tools,
|
||||
include_linker = include_linker,
|
||||
include_objcopy = include_objcopy,
|
||||
@@ -162,12 +161,7 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
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,
|
||||
@@ -575,8 +588,16 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
if ctx.attr.dev_components:
|
||||
rustc_dev_sha256 = load_rustc_dev_nightly(
|
||||
ctx = ctx,
|
||||
target_triple = target_triple,
|
||||
version = version,
|
||||
@@ -608,6 +621,14 @@
|
||||
iso_date = iso_date,
|
||||
)
|
||||
sha256s.update(rustc_dev_sha256)
|
||||
@@ -179,3 +173,6 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
+ iso_date = iso_date,
|
||||
+ )
|
||||
+ sha256s.update(exec_rustc_dev_sha256)
|
||||
|
||||
ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
|
||||
ctx.name,
|
||||
|
||||
@@ -26,47 +26,44 @@
|
||||
filtered_args.append(processed_arg)
|
||||
if processed_arg == "--sysroot" and i + 1 < len(link_args):
|
||||
# Two-part argument, keep the next arg too
|
||||
@@ -2305,7 +2335,7 @@
|
||||
return crate.metadata.dirname
|
||||
return crate.output.dirname
|
||||
@@ -2256,8 +2256,10 @@
|
||||
use_pic,
|
||||
ambiguous_libs,
|
||||
get_lib_name,
|
||||
+ for_windows = False,
|
||||
for_darwin = False,
|
||||
- flavor_msvc = False):
|
||||
+ flavor_msvc = False,
|
||||
+ use_direct_driver = False):
|
||||
"""_summary_
|
||||
|
||||
-def _portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = False, for_darwin = False, flavor_msvc = False):
|
||||
+def _portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = False, for_darwin = False, flavor_msvc = False, use_direct_driver = False):
|
||||
artifact = get_preferred_artifact(lib, use_pic)
|
||||
if ambiguous_libs and artifact.path in ambiguous_libs:
|
||||
artifact = ambiguous_libs[artifact.path]
|
||||
@@ -2344,6 +2344,11 @@
|
||||
artifact.basename.startswith("test-") or artifact.basename.startswith("std-")
|
||||
Args:
|
||||
@@ -2310,6 +2312,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"):
|
||||
+ return [
|
||||
+ "-Clink-arg={}".format(artifact.path),
|
||||
+ ]
|
||||
|
||||
+
|
||||
if flavor_msvc:
|
||||
return [
|
||||
@@ -2381,7 +2386,7 @@
|
||||
"-lstatic=%s" % get_lib_name(artifact),
|
||||
@@ -2346,7 +2353,7 @@
|
||||
])
|
||||
elif include_link_flags:
|
||||
get_lib_name = get_lib_name_for_windows if flavor_msvc else get_lib_name_default
|
||||
- ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc))
|
||||
+ ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc, use_direct_driver = use_direct_driver))
|
||||
- ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc))
|
||||
+ ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = True, flavor_msvc = flavor_msvc, use_direct_driver = use_direct_driver))
|
||||
|
||||
# Windows toolchains can inherit POSIX defaults like -pthread from C deps,
|
||||
# which fails to link with the MinGW/LLD toolchain. Drop them here.
|
||||
@@ -2453,14 +2483,21 @@
|
||||
@@ -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)
|
||||
+ if toolchain.target_os == "windows" and use_direct_link_driver:
|
||||
+ runtime_libs = depset([
|
||||
+ runtime_lib
|
||||
+ for runtime_lib in runtime_libs.to_list()
|
||||
+ if runtime_lib.basename.endswith(".lib")
|
||||
+ ])
|
||||
args.add_all(
|
||||
- cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration),
|
||||
+ runtime_libs,
|
||||
@@ -79,11 +76,18 @@
|
||||
- map_each = get_lib_name,
|
||||
- format_each = "-lstatic=%s",
|
||||
- )
|
||||
+ args.add_all(
|
||||
+ runtime_libs,
|
||||
+ map_each = get_lib_name,
|
||||
+ format_each = "-lstatic=%s",
|
||||
+ )
|
||||
+ if toolchain.target_os == "windows" 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")
|
||||
+ 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",
|
||||
+ )
|
||||
|
||||
def _get_dirname(file):
|
||||
"""A helper function for `_add_native_link_flags`.
|
||||
|
||||
Reference in New Issue
Block a user