Skip to content

Commit d1e9c55

Browse files
authored
Merge branch 'main' into ci
2 parents b9db62d + 0346cc4 commit d1e9c55

File tree

13 files changed

+95
-129
lines changed

13 files changed

+95
-129
lines changed

cargo/cargo_build_script.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _build_script_impl(ctx):
9292
# Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version).
9393
# We hope that the linker env is sufficient for the whole cc_toolchain.
9494
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
95-
_, _, linker_env = get_linker_and_args(ctx, cc_toolchain, feature_configuration, None)
95+
_, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
9696
env.update(**linker_env)
9797

9898
# MSVC requires INCLUDE to be set

proto/proto.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
220220

221221
return rustc_compile_action(
222222
ctx = ctx,
223+
attr = ctx.attr,
223224
toolchain = find_toolchain(ctx),
224225
crate_info = rust_common.create_crate_info(
225226
name = crate_name,

rust/defs.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ load(
3333
_rust_shared_library = "rust_shared_library",
3434
_rust_static_library = "rust_static_library",
3535
_rust_test = "rust_test",
36-
_rust_test_binary = "rust_test_binary",
3736
_rust_test_suite = "rust_test_suite",
3837
)
3938
load(
@@ -77,9 +76,6 @@ rust_binary = _rust_binary
7776
rust_test = _rust_test
7877
# See @rules_rust//rust/private:rust.bzl for a complete description.
7978

80-
rust_test_binary = _rust_test_binary
81-
# See @rules_rust//rust/private:rust.bzl for a complete description.
82-
8379
rust_test_suite = _rust_test_suite
8480
# See @rules_rust//rust/private:rust.bzl for a complete description.
8581

rust/private/clippy.bzl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ def _clippy_aspect_impl(target, ctx):
8080
clippy_marker = ctx.actions.declare_file(ctx.label.name + ".clippy.ok")
8181

8282
args, env = construct_arguments(
83-
ctx,
84-
ctx.rule.attr,
85-
ctx.file,
86-
toolchain,
87-
toolchain.clippy_driver.path,
88-
cc_toolchain,
89-
feature_configuration,
90-
crate_info,
91-
dep_info,
83+
ctx = ctx,
84+
attr = ctx.rule.attr,
85+
file = ctx.file,
86+
toolchain = toolchain,
87+
tool_path = toolchain.clippy_driver.path,
88+
cc_toolchain = cc_toolchain,
89+
feature_configuration = feature_configuration,
90+
crate_info = crate_info,
91+
dep_info = dep_info,
9292
output_hash = determine_output_hash(crate_info.root),
9393
rust_flags = [],
9494
out_dir = out_dir,

rust/private/rust.bzl

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def _rust_library_common(ctx, crate_type):
252252

253253
return rustc_compile_action(
254254
ctx = ctx,
255+
attr = ctx.attr,
255256
toolchain = toolchain,
256257
crate_info = rust_common.create_crate_info(
257258
name = crate_name,
@@ -287,6 +288,7 @@ def _rust_binary_impl(ctx):
287288

288289
return rustc_compile_action(
289290
ctx = ctx,
291+
attr = ctx.attr,
290292
toolchain = toolchain,
291293
crate_info = rust_common.create_crate_info(
292294
name = crate_name,
@@ -447,6 +449,7 @@ def _rust_test_common(ctx, toolchain, output):
447449

448450
providers = rustc_compile_action(
449451
ctx = ctx,
452+
attr = ctx.attr,
450453
toolchain = toolchain,
451454
crate_info = crate_info,
452455
rust_flags = ["--test"] if ctx.attr.use_libtest_harness else ["--cfg", "test"],
@@ -1127,32 +1130,6 @@ rust_test = rule(
11271130
"""),
11281131
)
11291132

1130-
rust_test_binary = rule(
1131-
implementation = _rust_test_impl,
1132-
provides = _common_providers,
1133-
attrs = dict(_common_attrs.items() +
1134-
_rust_test_attrs.items()),
1135-
executable = True,
1136-
fragments = ["cpp"],
1137-
host_fragments = ["cpp"],
1138-
toolchains = [
1139-
str(Label("//rust:toolchain")),
1140-
"@bazel_tools//tools/cpp:toolchain_type",
1141-
],
1142-
incompatible_use_toolchain_transition = True,
1143-
doc = dedent("""\
1144-
Builds a Rust test binary, without marking this rule as a Bazel test.
1145-
1146-
**Warning**: This rule is currently experimental.
1147-
1148-
This should be used when you want to run the test binary from a different test
1149-
rule (such as [`sh_test`](https://docs.bazel.build/versions/master/be/shell.html#sh_test)),
1150-
and know that running the test binary directly will fail.
1151-
1152-
See `rust_test` for example usage.
1153-
"""),
1154-
)
1155-
11561133
def rust_test_suite(name, srcs, **kwargs):
11571134
"""A rule for creating a test suite for a set of `rust_test` targets.
11581135

rust/private/rustc.bzl

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ def get_cc_user_link_flags(ctx):
185185
"""
186186
return ctx.fragments.cpp.linkopts
187187

188-
def get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths):
188+
def get_linker_and_args(ctx, attr, cc_toolchain, feature_configuration, rpaths):
189189
"""Gathers cc_common linker information
190190
191191
Args:
192192
ctx (ctx): The current target's context object
193+
attr (struct): Attributes to use in gathering linker args
193194
cc_toolchain (CcToolchain): cc_toolchain for which we are creating build variables.
194195
feature_configuration (FeatureConfiguration): Feature configuration to be queried.
195196
rpaths (depset): Depset of directories where loader will look for libraries at runtime.
196197
198+
197199
Returns:
198200
tuple: A tuple of the following items:
199201
- (str): The tool path for given action.
@@ -204,7 +206,7 @@ def get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths):
204206

205207
# Add linkopt's from dependencies. This includes linkopts from transitive
206208
# dependencies since they get merged up.
207-
for dep in ctx.attr.deps:
209+
for dep in getattr(attr, "deps", []):
208210
if CcInfo in dep and dep[CcInfo].linking_context:
209211
for linker_input in dep[CcInfo].linking_context.linker_inputs.to_list():
210212
for flag in linker_input.user_link_flags:
@@ -482,7 +484,7 @@ def construct_arguments(
482484
# linker since it won't understand.
483485
if toolchain.target_arch != "wasm32":
484486
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
485-
ld, link_args, link_env = get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths)
487+
ld, link_args, link_env = get_linker_and_args(ctx, attr, cc_toolchain, feature_configuration, rpaths)
486488
env.update(link_env)
487489
rustc_flags.add("--codegen=linker=" + ld)
488490
rustc_flags.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s")
@@ -528,6 +530,7 @@ def construct_arguments(
528530

529531
def rustc_compile_action(
530532
ctx,
533+
attr,
531534
toolchain,
532535
crate_info,
533536
output_hash = None,
@@ -537,6 +540,7 @@ def rustc_compile_action(
537540
538541
Args:
539542
ctx (ctx): The rule's context object
543+
attr (struct): Attributes to use for the rust compile action
540544
toolchain (rust_toolchain): The current `rust_toolchain`
541545
crate_info (CrateInfo): The CrateInfo provider for the current target.
542546
output_hash (str, optional): The hashed path of the crate root. Defaults to None.
@@ -559,35 +563,35 @@ def rustc_compile_action(
559563
)
560564

561565
compile_inputs, out_dir, build_env_files, build_flags_files = collect_inputs(
562-
ctx,
563-
ctx.file,
564-
ctx.files,
565-
toolchain,
566-
cc_toolchain,
567-
crate_info,
568-
dep_info,
569-
build_info,
566+
ctx = ctx,
567+
file = ctx.file,
568+
files = ctx.files,
569+
toolchain = toolchain,
570+
cc_toolchain = cc_toolchain,
571+
crate_info = crate_info,
572+
dep_info = dep_info,
573+
build_info = build_info,
570574
)
571575

572576
args, env = construct_arguments(
573-
ctx,
574-
ctx.attr,
575-
ctx.file,
576-
toolchain,
577-
toolchain.rustc.path,
578-
cc_toolchain,
579-
feature_configuration,
580-
crate_info,
581-
dep_info,
582-
output_hash,
583-
rust_flags,
584-
out_dir,
585-
build_env_files,
586-
build_flags_files,
577+
ctx = ctx,
578+
attr = attr,
579+
file = ctx.file,
580+
toolchain = toolchain,
581+
tool_path = toolchain.rustc.path,
582+
cc_toolchain = cc_toolchain,
583+
feature_configuration = feature_configuration,
584+
crate_info = crate_info,
585+
dep_info = dep_info,
586+
output_hash = output_hash,
587+
rust_flags = rust_flags,
588+
out_dir = out_dir,
589+
build_env_files = build_env_files,
590+
build_flags_files = build_flags_files,
587591
)
588592

589-
if hasattr(ctx.attr, "version") and ctx.attr.version != "0.0.0":
590-
formatted_version = " v{}".format(ctx.attr.version)
593+
if hasattr(attr, "version") and attr.version != "0.0.0":
594+
formatted_version = " v{}".format(attr.version)
591595
else:
592596
formatted_version = ""
593597

@@ -613,9 +617,9 @@ def rustc_compile_action(
613617
collect_data = True,
614618
)
615619

616-
out_binary = False
617-
if hasattr(ctx.attr, "out_binary"):
618-
out_binary = getattr(ctx.attr, "out_binary")
620+
# TODO: Remove after some resolution to
621+
# https://github.com/bazelbuild/rules_rust/issues/771
622+
out_binary = getattr(attr, "out_binary", False)
619623

620624
providers = [
621625
crate_info,
@@ -628,18 +632,19 @@ def rustc_compile_action(
628632
),
629633
]
630634
if toolchain.target_arch != "wasm32":
631-
providers += establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configuration)
635+
providers += establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration)
632636

633637
return providers
634638

635639
def _is_dylib(dep):
636640
return not bool(dep.static_library or dep.pic_static_library)
637641

638-
def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configuration):
642+
def establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration):
639643
"""If the produced crate is suitable yield a CcInfo to allow for interop with cc rules
640644
641645
Args:
642646
ctx (ctx): The rule's context object
647+
attr (struct): Attributes to use in gathering CcInfo
643648
crate_info (CrateInfo): The CrateInfo provider of the target crate
644649
toolchain (rust_toolchain): The current `rust_toolchain`
645650
cc_toolchain (CcToolchainInfo): The current `CcToolchainInfo`
@@ -649,7 +654,17 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur
649654
list: A list containing the CcInfo provider
650655
"""
651656

652-
if crate_info.is_test or crate_info.type not in ("staticlib", "cdylib", "rlib", "lib") or getattr(ctx.attr, "out_binary", False):
657+
# A test will not need to produce CcInfo as nothing can depend on test targets
658+
if crate_info.is_test:
659+
return []
660+
661+
# Only generate CcInfo for particular crate types
662+
if crate_info.type not in ("staticlib", "cdylib", "rlib", "lib"):
663+
return []
664+
665+
# TODO: Remove after some resolution to
666+
# https://github.com/bazelbuild/rules_rust/issues/771
667+
if getattr(attr, "out_binary", False):
653668
return []
654669

655670
if crate_info.type == "staticlib":
@@ -698,7 +713,7 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur
698713
)
699714

700715
cc_infos = [CcInfo(linking_context = linking_context)]
701-
for dep in ctx.attr.deps:
716+
for dep in getattr(attr, "deps", []):
702717
if CcInfo in dep:
703718
cc_infos.append(dep[CcInfo])
704719

rust/rust.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ load(
3131
_rust_shared_library = "rust_shared_library",
3232
_rust_static_library = "rust_static_library",
3333
_rust_test = "rust_test",
34-
_rust_test_binary = "rust_test_binary",
3534
)
3635
load("//rust/settings:incompatible.bzl", "fail_when_enabled")
3736

@@ -70,9 +69,6 @@ rust_binary = _rust_binary
7069
rust_test = _rust_test
7170
# See @rules_rust//rust/private:rust.bzl for a complete description.
7271

73-
rust_test_binary = _rust_test_binary
74-
# See @rules_rust//rust/private:rust.bzl for a complete description.
75-
7672
rust_benchmark = _rust_benchmark
7773
# See @rules_rust//rust/private:rust.bzl for a complete description.
7874

test/rust_test_binary/BUILD.bazel

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/rust_test_binary/scripts/exec_with_test_env.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/rust_test_binary/tests/rust_test_that_requires_wrapping.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tools/rustfmt/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
load("//rust:defs.bzl", "rust_binary", "rust_clippy", "rust_library")
2+
load(":rustfmt_utils.bzl", "aspect_repository")
23

34
package(default_visibility = ["//visibility:public"])
45

5-
exports_files(["rustfmt.toml"])
6+
exports_files([
7+
"rustfmt.toml",
8+
"rustfmt_utils.bzl",
9+
])
610

711
rust_library(
812
name = "rustfmt_lib",
@@ -30,6 +34,9 @@ rust_binary(
3034
"//:rustfmt.toml",
3135
],
3236
edition = "2018",
37+
rustc_env = {
38+
"ASPECT_REPOSITORY": aspect_repository(),
39+
},
3340
deps = [
3441
":rustfmt_lib",
3542
"//util/label",

0 commit comments

Comments
 (0)