Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindgen/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _rust_bindgen_impl(ctx):

# Configure Bindgen Arguments
args.add_all(ctx.attr.bindgen_flags)
args.add(header.path)
args.add(header)
args.add("--output", output)

# Vanilla usage of bindgen produces formatted output, here we do the same if we have `rustfmt` in our toolchain.
Expand Down
23 changes: 11 additions & 12 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,17 @@ def _cargo_build_script_impl(ctx):
# See https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages
# for details.
args = ctx.actions.args()
args.add_all([
script.path,
links,
out_dir.path,
env_out.path,
flags_out.path,
link_flags.path,
link_search_paths.path,
dep_env_out.path,
streams.stdout.path,
streams.stderr.path,
])
args.add(script)
args.add(links)
args.add(out_dir.path)
args.add(env_out)
args.add(flags_out)
args.add(link_flags)
args.add(link_search_paths)
args.add(dep_env_out)
args.add(streams.stdout)
args.add(streams.stderr)

build_script_inputs = []
for dep in ctx.attr.link_deps:
if rust_common.dep_info in dep and dep[rust_common.dep_info].dep_env:
Expand Down
4 changes: 2 additions & 2 deletions proto/protobuf/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def rust_generate_proto(
# so we create an empty grpc module in the other case.
tools.append(proto_toolchain.grpc_plugin)
tools.append(ctx.executable._optional_output_wrapper)
args.add_all([f.path for f in grpc_files])
args.add_all(grpc_files)
args.add_all([
"--",
proto_toolchain.protoc.path,
proto_toolchain.protoc,
"--plugin=protoc-gen-grpc-rust=" + proto_toolchain.grpc_plugin.path,
"--grpc-rust_out=" + output_directory,
])
Expand Down
4 changes: 2 additions & 2 deletions rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _clippy_aspect_impl(target, ctx):
# or rustc may fail to create intermediate output files because the directory does not exist.
if ctx.attr._capture_output[CaptureClippyOutputInfo].capture_output:
clippy_out = ctx.actions.declare_file(ctx.label.name + ".clippy.out", sibling = crate_info.output)
args.process_wrapper_flags.add("--stderr-file", clippy_out.path)
args.process_wrapper_flags.add("--stderr-file", clippy_out)

if clippy_flags:
fail("""Combining @rules_rust//:clippy_flags with @rules_rust//:capture_clippy_output=true is currently not supported.
Expand All @@ -150,7 +150,7 @@ See https://github.com/bazelbuild/rules_rust/pull/1264#discussion_r853241339 for
# A marker file indicating clippy has executed successfully.
# This file is necessary because "ctx.actions.run" mandates an output.
clippy_out = ctx.actions.declare_file(ctx.label.name + ".clippy.ok", sibling = crate_info.output)
args.process_wrapper_flags.add("--touch-file", clippy_out.path)
args.process_wrapper_flags.add("--touch-file", clippy_out)

if clippy_flags:
args.rustc_flags.add_all(clippy_flags)
Expand Down
45 changes: 20 additions & 25 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ def construct_arguments(
rustc_flags.set_param_file_format("multiline")
rustc_flags.use_param_file("@%s", use_always = False)
rustc_flags.add(crate_info.root)
rustc_flags.add("--crate-name=" + crate_info.name)
rustc_flags.add("--crate-type=" + crate_info.type)
rustc_flags.add(crate_info.name, format = "--crate-name=%s")
rustc_flags.add(crate_info.type, format = "--crate-type=%s")

error_format = "human"
if hasattr(attr, "_error_format"):
Expand All @@ -921,15 +921,15 @@ def construct_arguments(
# If the os is not windows, we can get colorized output.
json.append("diagnostic-rendered-ansi")

rustc_flags.add("--json=" + ",".join(json))
rustc_flags.add_joined(json, format_joined = "--json=%s", join_with = ",")

error_format = "json"

if build_metadata:
# Configure process_wrapper to terminate rustc when metadata are emitted
process_wrapper_flags.add("--rustc-quit-on-rmeta", "true")

rustc_flags.add("--error-format=" + error_format)
rustc_flags.add(error_format, format = "--error-format=%s")

# Mangle symbols to disambiguate crates with the same name. This could
# happen only for non-final artifacts where we compute an output_hash,
Expand All @@ -939,37 +939,33 @@ def construct_arguments(
# Bazel, such as rust_binary, rust_static_library and rust_shared_library,
# where output_hash is None we don't need to add these flags.
if output_hash:
extra_filename = "-" + output_hash
rustc_flags.add("--codegen=metadata=" + extra_filename)
rustc_flags.add("--codegen=extra-filename=" + extra_filename)
rustc_flags.add(output_hash, format = "--codegen=metadata=-%s")
rustc_flags.add(output_hash, format = "--codegen=extra-filename=-%s")

if output_dir:
rustc_flags.add("--out-dir=" + output_dir)
rustc_flags.add(output_dir, format = "--out-dir=%s")

compilation_mode = get_compilation_mode_opts(ctx, toolchain)
rustc_flags.add("--codegen=opt-level=" + compilation_mode.opt_level)
rustc_flags.add("--codegen=debuginfo=" + compilation_mode.debug_info)
rustc_flags.add(compilation_mode.opt_level, format = "--codegen=opt-level=%s")
rustc_flags.add(compilation_mode.debug_info, format = "--codegen=debuginfo=%s")

# For determinism to help with build distribution and such
if remap_path_prefix != None:
rustc_flags.add("--remap-path-prefix=${{pwd}}={}".format(remap_path_prefix))

if emit:
rustc_flags.add("--emit=" + ",".join(emit_with_paths))
rustc_flags.add_joined(emit_with_paths, format_joined = "--emit=%s", join_with = ",")
if error_format != "json":
# Color is not compatible with json output.
rustc_flags.add("--color=always")
rustc_flags.add("--target=" + toolchain.target_flag_value)
rustc_flags.add(toolchain.target_flag_value, format = "--target=%s")
if hasattr(attr, "crate_features"):
rustc_flags.add_all(getattr(attr, "crate_features"), before_each = "--cfg", format_each = 'feature="%s"')
if linker_script:
rustc_flags.add(linker_script.path, format = "--codegen=link-arg=-T%s")
rustc_flags.add(linker_script, format = "--codegen=link-arg=-T%s")

# Gets the paths to the folders containing the standard library (or libcore)
rust_std_paths = toolchain.rust_std_paths.to_list()

# Tell Rustc where to find the standard library
rustc_flags.add_all(rust_std_paths, before_each = "-L", format_each = "%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(rust_flags)

# Gather data path from crate_info since it is inherited from real crate for rust_doc and rust_test
Expand All @@ -995,12 +991,12 @@ def construct_arguments(
use_pic = _should_use_pic(cc_toolchain, feature_configuration, crate_info.type, compilation_mode)
rpaths = _compute_rpaths(toolchain, output_dir, dep_info, use_pic)
else:
rpaths = depset([])
rpaths = depset()

ld, link_args, link_env = get_linker_and_args(ctx, attr, crate_info.type, cc_toolchain, feature_configuration, rpaths, rustdoc)

env.update(link_env)
rustc_flags.add("--codegen=linker=" + ld)
rustc_flags.add(ld, format = "--codegen=linker=%s")
rustc_flags.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s")

_add_native_link_flags(rustc_flags, dep_info, linkstamp_outs, ambiguous_libs, crate_info.type, toolchain, cc_toolchain, feature_configuration, compilation_mode)
Expand Down Expand Up @@ -1067,7 +1063,7 @@ def construct_arguments(
rustc_flags.add_all(ctx.attr._extra_exec_rustc_flag[ExtraExecRustcFlagsInfo].extra_exec_rustc_flags)

if _is_no_std(ctx, toolchain, crate_info):
rustc_flags.add_all(['--cfg=feature="no_std"'])
rustc_flags.add('--cfg=feature="no_std"')

# Create a struct which keeps the arguments separate so each may be tuned or
# replaced where necessary
Expand Down Expand Up @@ -1590,7 +1586,7 @@ def add_edition_flags(args, crate):
crate (CrateInfo): A CrateInfo provider
"""
if crate.edition != "2015":
args.add("--edition={}".format(crate.edition))
args.add(crate.edition, format = "--edition=%s")

def _create_extra_input_args(build_info, dep_info):
"""Gather additional input arguments from transitive dependencies
Expand Down Expand Up @@ -1928,12 +1924,11 @@ def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate
# If there are ambiguous libs, the disambiguation symlinks to them are
# all created in the same directory. Add it to the library search path.
ambiguous_libs_dirname = ambiguous_libs.values()[0].dirname
args.add("-Lnative={}".format(ambiguous_libs_dirname))
args.add(ambiguous_libs_dirname, format = "-Lnative=%s")

args.add_all(args_and_pic_and_ambiguous_libs, map_each = make_link_flags)

for linkstamp_out in linkstamp_outs:
args.add_all(["-C", "link-arg=%s" % linkstamp_out.path])
args.add_all(linkstamp_outs, before_each = "-C", format_each = "link-args=%s")

if crate_type in ["dylib", "cdylib"]:
# For shared libraries we want to link C++ runtime library dynamically
Expand Down
2 changes: 1 addition & 1 deletion rust/private/rustdoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def rustdoc_compile_action(

# `rustdoc` does not support the SYSROOT environment variable. To account
# for this, the flag must be explicitly passed to the `rustdoc` binary.
args.rustc_flags.add("--sysroot=${{pwd}}/{}".format(toolchain.sysroot_short_path))
args.rustc_flags.add(toolchain.sysroot_short_path, format = "--sysroot=${{pwd}}/%s")

return struct(
executable = ctx.executable._process_wrapper,
Expand Down
9 changes: 3 additions & 6 deletions rust/private/rustfmt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ def _perform_check(edition, srcs, ctx):
marker = ctx.actions.declare_file(ctx.label.name + ".rustfmt.ok")

args = ctx.actions.args()
args.add("--touch-file")
args.add(marker)
args.add("--touch-file", marker)
args.add("--")
args.add(rustfmt_toolchain.rustfmt)
args.add("--config-path")
args.add(config)
args.add("--edition")
args.add(edition)
args.add("--config-path", config)
args.add("--edition", edition)
args.add("--check")
args.add_all(srcs)

Expand Down
10 changes: 5 additions & 5 deletions test/process_wrapper/process_wrapper_tester.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ def _impl(ctx):
if combined or ctx.attr.test_config == "stdout":
stdout_output = ctx.actions.declare_file(ctx.label.name + ".stdout")
outputs.append(stdout_output)
args.add("--stdout-file", stdout_output.path)
args.add("--stdout-file", stdout_output)

if combined or ctx.attr.test_config == "stderr":
stderr_output = ctx.actions.declare_file(ctx.label.name + ".stderr")
outputs.append(stderr_output)
args.add("--stderr-file", stderr_output.path)
args.add("--stderr-file", stderr_output)

if combined or (ctx.attr.test_config != "stdout" and ctx.attr.test_config != "stderr"):
touch_output = ctx.actions.declare_file(ctx.label.name + ".touch")
outputs.append(touch_output)
args.add("--touch-file", touch_output.path)
args.add("--touch-file", touch_output)
if ctx.attr.test_config == "copy-output":
copy_output = ctx.actions.declare_file(ctx.label.name + ".touch.copy")
outputs.append(copy_output)
args.add_all("--copy-output", [touch_output.path, copy_output.path])
args.add_all("--copy-output", [touch_output, copy_output])

if combined or ctx.attr.test_config == "env-files":
args.add_all(ctx.files.env_files, before_each = "--env-file")
Expand All @@ -53,7 +53,7 @@ def _impl(ctx):

args.add("--")

args.add(ctx.executable._process_wrapper_tester.path)
args.add(ctx.executable._process_wrapper_tester)
args.add(ctx.attr.test_config)
args.add("--current-dir", "${pwd}")
args.add("--test-subst", "subst key to ${key}")
Expand Down