diff options
author | Matt <msta@google.com> | 2024-02-16 22:21:33 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 11:21:33 +0000 |
commit | a4b1a1b8f3877763d30cbc78d786a8d21ea06998 (patch) | |
tree | 8f65a0f5cfc38457134308ba37d70f7a912b5d5f | |
parent | 8fd0904a58d1256a531a89ecdb774ba970049185 (diff) | |
download | bazelbuild-rules_rust-a4b1a1b8f3877763d30cbc78d786a8d21ea06998.tar.gz |
Use a path instead of a string for emit in rustc command-line arguments. (#2445)
This can improve the cache hit rate, as it will work with path mapping.
Also generate the emit path unconditionally, as this works better with
the `binary_ext` parameter better (as it guarantees that you won't get
an error where the file names don't match).
-rw-r--r-- | rust/private/rustc.bzl | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 81dab3d7..ef70c1f8 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -889,23 +889,6 @@ def construct_arguments( if out_dir != None: env["OUT_DIR"] = "${pwd}/" + out_dir - # Handle that the binary name and crate name may be different. - # - # If a target name contains a - then cargo (and rules_rust) will generate a - # crate name with _ instead. Accordingly, rustc will generate a output - # file (executable, or rlib, or whatever) with _ not -. But when cargo - # puts a binary in the target/${config} directory, and sets environment - # variables like `CARGO_BIN_EXE_${binary_name}` it will use the - version - # not the _ version. So we rename the rustc-generated file (with _s) to - # have -s if needed. - emit_with_paths = emit - if crate_info.type == "bin" and crate_info.output != None: - generated_file = crate_info.name + toolchain.binary_ext - src = "/".join([crate_info.output.dirname, generated_file]) - dst = crate_info.output.path - if src != dst: - emit_with_paths = [("link=" + dst if val == "link" else val) for val in emit] - # Arguments for launching rustc from the process wrapper rustc_path = ctx.actions.args() rustc_path.add("--") @@ -974,8 +957,15 @@ def construct_arguments( if remap_path_prefix != None: rustc_flags.add("--remap-path-prefix=${{pwd}}={}".format(remap_path_prefix)) - if emit: - rustc_flags.add_joined(emit_with_paths, format_joined = "--emit=%s", join_with = ",") + emit_without_paths = [] + for kind in emit: + if kind == "link" and crate_info.type == "bin" and crate_info.output != None: + rustc_flags.add(crate_info.output, format = "--emit=link=%s") + else: + emit_without_paths.append(kind) + + if emit_without_paths: + rustc_flags.add_joined(emit_without_paths, format_joined = "--emit=%s", join_with = ",") if error_format != "json": # Color is not compatible with json output. rustc_flags.add("--color=always") |