mirror of
https://github.com/openai/codex.git
synced 2026-09-09 15:58:47 +00:00
bazel: shard selected rust tests
Use the merged hermeticbuild rules_rust sharding support and configure the generated core, app-server, and tui test targets that benefit from sharding for eight shards. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
28
MODULE.bazel
28
MODULE.bazel
@@ -94,10 +94,20 @@ single_version_override(
|
||||
)
|
||||
|
||||
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.patch(
|
||||
|
||||
bazel_dep(name = "rules_rust", version = "0.69.0")
|
||||
|
||||
# `rules_rs` 0.0.43 pins an older hermeticbuild/rules_rust commit. Override the
|
||||
# extension-created repo so Codex can use rust_test sharding from #13 without
|
||||
# updating the entire rules_rs module.
|
||||
#
|
||||
# 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.
|
||||
archive_override(
|
||||
module_name = "rules_rust",
|
||||
integrity = "sha256-q37yA5WS3++LIgdkThIhxsQkoZ5F/+DD4GhTWkY1rkE=",
|
||||
patch_strip = 1,
|
||||
patches = [
|
||||
"//patches:rules_rust_windows_gnullvm_build_script.patch",
|
||||
"//patches:rules_rust_windows_exec_msvc_build_script_env.patch",
|
||||
@@ -108,11 +118,15 @@ 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,
|
||||
strip_prefix = "rules_rust-10825e1a40b8f6d979c51bc795c9d3fa7f78cc6f",
|
||||
urls = ["https://github.com/hermeticbuild/rules_rust/archive/10825e1a40b8f6d979c51bc795c9d3fa7f78cc6f.tar.gz"],
|
||||
)
|
||||
|
||||
override_repo(
|
||||
rules_rust,
|
||||
rules_rust = "rules_rust",
|
||||
)
|
||||
use_repo(rules_rust, "rules_rust")
|
||||
|
||||
nightly_rust = use_extension(
|
||||
"@rules_rs//rs/experimental:rules_rust_reexported_extensions.bzl",
|
||||
|
||||
100
MODULE.bazel.lock
generated
100
MODULE.bazel.lock
generated
@@ -579,6 +579,106 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@@rules_rust+//crate_universe/private:internal_extensions.bzl%cu_nr": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "YV5ZvFobnzzG7RyMyMrpyFy8ePYoBcGOM4VVSd9AmVw=",
|
||||
"usagesDigest": "qhmy4zrnFb6knNQRx2XBCVfHObom0vnflm+sibd7SA0=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:bazel_features+,bazel_features_globals bazel_features++version_extension+bazel_features_globals",
|
||||
"REPO_MAPPING:bazel_features+,bazel_features_version bazel_features++version_extension+bazel_features_version",
|
||||
"REPO_MAPPING:rules_cc+,bazel_skylib bazel_skylib+",
|
||||
"REPO_MAPPING:rules_cc+,bazel_tools bazel_tools",
|
||||
"REPO_MAPPING:rules_cc+,cc_compatibility_proxy rules_cc++compatibility_proxy+cc_compatibility_proxy",
|
||||
"REPO_MAPPING:rules_cc+,platforms platforms",
|
||||
"REPO_MAPPING:rules_cc+,rules_cc rules_cc+",
|
||||
"REPO_MAPPING:rules_cc++compatibility_proxy+cc_compatibility_proxy,rules_cc rules_cc+",
|
||||
"REPO_MAPPING:rules_rust+,bazel_features bazel_features+",
|
||||
"REPO_MAPPING:rules_rust+,bazel_skylib bazel_skylib+",
|
||||
"REPO_MAPPING:rules_rust+,bazel_tools bazel_tools",
|
||||
"REPO_MAPPING:rules_rust+,cargo_bazel_bootstrap rules_rust++cu_nr+cargo_bazel_bootstrap",
|
||||
"REPO_MAPPING:rules_rust+,cui rules_rust++cu+cui",
|
||||
"REPO_MAPPING:rules_rust+,rrc rules_rust++i2+rrc",
|
||||
"REPO_MAPPING:rules_rust+,rules_cc rules_cc+",
|
||||
"REPO_MAPPING:rules_rust+,rules_rust rules_rust+"
|
||||
],
|
||||
"generatedRepoSpecs": {
|
||||
"cargo_bazel_bootstrap": {
|
||||
"repoRuleId": "@@rules_rust+//cargo/private:cargo_bootstrap.bzl%cargo_bootstrap_repository",
|
||||
"attributes": {
|
||||
"srcs": [
|
||||
"@@rules_rust+//crate_universe:src/api.rs",
|
||||
"@@rules_rust+//crate_universe:src/api/lockfile.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli/generate.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli/query.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli/render.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli/splice.rs",
|
||||
"@@rules_rust+//crate_universe:src/cli/vendor.rs",
|
||||
"@@rules_rust+//crate_universe:src/config.rs",
|
||||
"@@rules_rust+//crate_universe:src/context.rs",
|
||||
"@@rules_rust+//crate_universe:src/context/crate_context.rs",
|
||||
"@@rules_rust+//crate_universe:src/context/platforms.rs",
|
||||
"@@rules_rust+//crate_universe:src/lib.rs",
|
||||
"@@rules_rust+//crate_universe:src/lockfile.rs",
|
||||
"@@rules_rust+//crate_universe:src/main.rs",
|
||||
"@@rules_rust+//crate_universe:src/metadata.rs",
|
||||
"@@rules_rust+//crate_universe:src/metadata/cargo_bin.rs",
|
||||
"@@rules_rust+//crate_universe:src/metadata/cargo_tree_resolver.rs",
|
||||
"@@rules_rust+//crate_universe:src/metadata/cargo_tree_rustc_wrapper.bat",
|
||||
"@@rules_rust+//crate_universe:src/metadata/cargo_tree_rustc_wrapper.sh",
|
||||
"@@rules_rust+//crate_universe:src/metadata/dependency.rs",
|
||||
"@@rules_rust+//crate_universe:src/metadata/metadata_annotation.rs",
|
||||
"@@rules_rust+//crate_universe:src/rendering.rs",
|
||||
"@@rules_rust+//crate_universe:src/rendering/template_engine.rs",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/module_bzl.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/partials/header.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/partials/module/aliases_map.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/partials/module/deps_map.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/partials/module/repo_git.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/partials/module/repo_http.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/templates/vendor_module.j2",
|
||||
"@@rules_rust+//crate_universe:src/rendering/verbatim/alias_rules.bzl",
|
||||
"@@rules_rust+//crate_universe:src/select.rs",
|
||||
"@@rules_rust+//crate_universe:src/splicing.rs",
|
||||
"@@rules_rust+//crate_universe:src/splicing/cargo_config.rs",
|
||||
"@@rules_rust+//crate_universe:src/splicing/crate_index_lookup.rs",
|
||||
"@@rules_rust+//crate_universe:src/splicing/splicer.rs",
|
||||
"@@rules_rust+//crate_universe:src/test.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/glob.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/label.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/select.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/select_dict.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/select_list.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/select_scalar.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/select_set.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/serialize.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/starlark/target_compatible_with.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/symlink.rs",
|
||||
"@@rules_rust+//crate_universe:src/utils/target_triple.rs"
|
||||
],
|
||||
"binary": "cargo-bazel",
|
||||
"cargo_lockfile": "@@rules_rust+//crate_universe:Cargo.lock",
|
||||
"cargo_toml": "@@rules_rust+//crate_universe:Cargo.toml",
|
||||
"version": "1.94.1",
|
||||
"timeout": 900,
|
||||
"rust_toolchain_cargo_template": "@rust_host_tools//:bin/{tool}",
|
||||
"rust_toolchain_rustc_template": "@rust_host_tools//:bin/{tool}",
|
||||
"compressed_windows_toolchain_names": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"moduleExtensionMetadata": {
|
||||
"explicitRootModuleDirectDeps": [
|
||||
"cargo_bazel_bootstrap"
|
||||
],
|
||||
"explicitRootModuleDirectDevDeps": [],
|
||||
"useAllRepos": "NO",
|
||||
"reproducible": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"facts": {
|
||||
|
||||
@@ -4,5 +4,9 @@ codex_rust_crate(
|
||||
name = "app-server",
|
||||
crate_name = "codex_app_server",
|
||||
integration_test_timeout = "long",
|
||||
test_shard_counts = {
|
||||
"app-server-all-test": 8,
|
||||
"app-server-unit-tests": 8,
|
||||
},
|
||||
test_tags = ["no-sandbox"],
|
||||
)
|
||||
|
||||
@@ -47,6 +47,10 @@ codex_rust_crate(
|
||||
# succeeds without this workaround.
|
||||
"//:AGENTS.md",
|
||||
],
|
||||
test_shard_counts = {
|
||||
"core-all-test": 8,
|
||||
"core-unit-tests": 8,
|
||||
},
|
||||
test_tags = ["no-sandbox"],
|
||||
unit_test_timeout = "long",
|
||||
extra_binaries = [
|
||||
|
||||
@@ -19,6 +19,9 @@ codex_rust_crate(
|
||||
"src/**/*.rs",
|
||||
"src/**/snapshots/**",
|
||||
]) + ["//codex-rs/core:model_availability_nux_fixtures"],
|
||||
test_shard_counts = {
|
||||
"tui-unit-tests": 8,
|
||||
},
|
||||
integration_compile_data_extra = ["src/test_backend.rs"],
|
||||
extra_binaries = [
|
||||
"//codex-rs/cli:codex",
|
||||
|
||||
31
defs.bzl
31
defs.bzl
@@ -140,6 +140,7 @@ def codex_rust_crate(
|
||||
integration_test_args = [],
|
||||
integration_test_timeout = None,
|
||||
test_data_extra = [],
|
||||
test_shard_counts = {},
|
||||
test_tags = [],
|
||||
unit_test_timeout = None,
|
||||
extra_binaries = []):
|
||||
@@ -174,6 +175,10 @@ def codex_rust_crate(
|
||||
integration_test_timeout: Optional Bazel timeout for integration test
|
||||
targets generated from `tests/*.rs`.
|
||||
test_data_extra: Extra runtime data for tests.
|
||||
test_shard_counts: Mapping from generated test target name to Bazel
|
||||
shard count. Matching `rust_test` targets opt into the rules_rust
|
||||
libtest sharding wrapper. For unit tests, use the outer target
|
||||
name, such as `core-unit-tests`.
|
||||
test_tags: Tags applied to unit + integration test targets.
|
||||
Typically used to disable the sandbox, but see https://bazel.build/reference/be/common-definitions#common.tags
|
||||
unit_test_timeout: Optional Bazel timeout for the unit-test target
|
||||
@@ -246,7 +251,9 @@ def codex_rust_crate(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
unit_test_name = name + "-unit-tests"
|
||||
unit_test_binary = name + "-unit-tests-bin"
|
||||
unit_test_sharding_kwargs = _test_sharding_kwargs(test_shard_counts, unit_test_name)
|
||||
rust_test(
|
||||
name = unit_test_binary,
|
||||
crate = name,
|
||||
@@ -265,14 +272,17 @@ def codex_rust_crate(
|
||||
rustc_env = rustc_env,
|
||||
data = test_data_extra,
|
||||
tags = test_tags + ["manual"],
|
||||
**unit_test_sharding_kwargs
|
||||
)
|
||||
|
||||
unit_test_kwargs = {}
|
||||
if unit_test_timeout:
|
||||
unit_test_kwargs["timeout"] = unit_test_timeout
|
||||
if "shard_count" in unit_test_sharding_kwargs:
|
||||
unit_test_kwargs["shard_count"] = unit_test_sharding_kwargs["shard_count"]
|
||||
|
||||
workspace_root_test(
|
||||
name = name + "-unit-tests",
|
||||
name = unit_test_name,
|
||||
env = test_env,
|
||||
test_bin = ":" + unit_test_binary,
|
||||
workspace_root_marker = "//codex-rs/utils/cargo-bin:repo_root.marker",
|
||||
@@ -318,6 +328,10 @@ def codex_rust_crate(
|
||||
if not test_name.endswith("-test"):
|
||||
test_name += "-test"
|
||||
|
||||
test_kwargs = {}
|
||||
test_kwargs.update(integration_test_kwargs)
|
||||
test_kwargs.update(_test_sharding_kwargs(test_shard_counts, test_name))
|
||||
|
||||
rust_test(
|
||||
name = test_name,
|
||||
crate_name = test_crate_name,
|
||||
@@ -339,5 +353,18 @@ def codex_rust_crate(
|
||||
# execute from the repo root and can misplace integration snapshots.
|
||||
env = cargo_env,
|
||||
tags = test_tags,
|
||||
**integration_test_kwargs
|
||||
**test_kwargs
|
||||
)
|
||||
|
||||
def _test_sharding_kwargs(test_shard_counts, test_name):
|
||||
shard_count = test_shard_counts.get(test_name)
|
||||
if shard_count == None:
|
||||
return {}
|
||||
|
||||
if shard_count < 1:
|
||||
fail("test_shard_counts[{}] must be a positive integer".format(test_name))
|
||||
|
||||
return {
|
||||
"experimental_enable_sharding": True,
|
||||
"shard_count": shard_count,
|
||||
}
|
||||
|
||||
@@ -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,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(
|
||||
@@ -4,7 +4,90 @@
|
||||
# The toolchain sysroot must therefore carry both stdlib trees so rustc can
|
||||
# resolve the correct one for each `--target`.
|
||||
|
||||
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
|
||||
index ad8aea481..341ed70bb 100644
|
||||
--- a/rust/private/repository_utils.bzl
|
||||
+++ b/rust/private/repository_utils.bzl
|
||||
@@ -342,6 +342,7 @@ rust_toolchain(
|
||||
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 @@ def BUILD_for_rust_toolchain(
|
||||
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 @@ def BUILD_for_rust_toolchain(
|
||||
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 @@ def BUILD_for_rust_toolchain(
|
||||
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/repositories.bzl b/rust/repositories.bzl
|
||||
index e4bd37f4c..66bd95bde 100644
|
||||
--- a/rust/repositories.bzl
|
||||
+++ b/rust/repositories.bzl
|
||||
@@ -574,6 +574,18 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
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 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
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 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
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,
|
||||
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
index 10465b5a7..6e322535c 100644
|
||||
--- a/rust/toolchain.bzl
|
||||
+++ b/rust/toolchain.bzl
|
||||
@@ -209,6 +209,7 @@ def _generate_sysroot(
|
||||
@@ -15,16 +98,15 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = None,
|
||||
rustfmt = None,
|
||||
linker = None):
|
||||
@@ -312,7 +313,15 @@ def _generate_sysroot(
|
||||
|
||||
@@ -313,6 +314,14 @@ def _generate_sysroot(
|
||||
# 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))
|
||||
+
|
||||
@@ -71,7 +153,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(
|
||||
@@ -804,6 +817,10 @@ rust_toolchain = rule(
|
||||
doc = "The Rust standard library.",
|
||||
mandatory = True,
|
||||
),
|
||||
@@ -82,100 +164,3 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
"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
|
||||
@@ -341,6 +341,7 @@ rust_toolchain(
|
||||
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},
|
||||
@@ -384,6 +385,7 @@ def BUILD_for_rust_toolchain(
|
||||
include_llvm_tools,
|
||||
include_linker,
|
||||
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(
|
||||
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.
|
||||
@@ -453,6 +456,7 @@ def BUILD_for_rust_toolchain(
|
||||
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
|
||||
@@ -1011,7 +1011,10 @@ def construct_arguments(
|
||||
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
|
||||
@@ -536,6 +536,18 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
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(":")
|
||||
@@ -552,6 +564,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
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,
|
||||
@@ -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,
|
||||
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)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
index 11d97aaa3..ef6ebd61d 100644
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -501,11 +501,41 @@
|
||||
@@ -501,11 +501,25 @@ def get_linker_and_args(ctx, crate_type, toolchain, cc_toolchain, feature_config
|
||||
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":
|
||||
@@ -26,37 +28,48 @@
|
||||
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
|
||||
@@ -2265,8 +2279,10 @@ def portable_link_flags(
|
||||
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:
|
||||
@@ -2319,6 +2335,11 @@ def portable_link_flags(
|
||||
):
|
||||
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),
|
||||
@@ -2355,7 +2376,15 @@ def _make_link_flags_windows(make_link_flags_args, flavor_msvc, use_direct_drive
|
||||
])
|
||||
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 @@
|
||||
@@ -2531,14 +2560,21 @@ def _add_native_link_flags(
|
||||
else:
|
||||
# For all other crate types we want to link C++ runtime library statically
|
||||
# (for example libstdc++.a or libc++.a).
|
||||
@@ -74,16 +87,9 @@
|
||||
format_each = "-Lnative=%s",
|
||||
)
|
||||
if include_link_flags:
|
||||
- args.add_all(
|
||||
args.add_all(
|
||||
- cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration),
|
||||
- map_each = get_lib_name,
|
||||
- format_each = "-lstatic=%s",
|
||||
- )
|
||||
+ 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`.
|
||||
map_each = get_lib_name,
|
||||
format_each = "-lstatic=%s",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user