aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Lipsitz <elipsitz@google.com>2023-02-01 00:01:36 +0000
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-01 00:01:36 +0000
commitb5f05fbb0869ab2833e8b843f6c75c32931c4e67 (patch)
tree5b7e54cf218e794794d27032bd6d921b7916fbdc
parent3865a74f02bb4983ae3fc9b0398b7c6c70dc32d5 (diff)
downloadpigweed-b5f05fbb0869ab2833e8b843f6c75c32931c4e67.tar.gz
pw_rust: Make rust_bin tool definition more robust
The existing rust_bin tool definition in the generate_toolchain template is missing a few critical pieces: 1) depfile generation -- without this, Ninja won't recompile Rust targets when a module (rather than the main.rs or lib.rs) changes. 2) Unused GN rust_bin toolchain arguments. rustenv, crate_name, crate_type, rustflags, rustdeps, externs all are provided by GN for Rust targets and are necessary to get proper compilation, dependencies, flags, etc. This commit adds the missing pieces. The depfile arguments to rustc look a little bit arbitrary, but they're just what's required to get rustc to output depfiles that Ninja can understand (borrowed from Fuchsia). Tested: Set some rustflags in a target, verified they're set properly. Added a Rust target that depends on a module in another file, verified that without this change, changes to that module do not cause a rebuild, and after this change, they do. Change-Id: Ifc4cd5a4d099fada960dae9e0b663c47bd51cec2 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/127013 Reviewed-by: Erik Gilling <konkers@google.com> Commit-Queue: Eli Lipsitz <elipsitz@google.com>
-rw-r--r--pw_toolchain/generate_toolchain.gni9
1 files changed, 9 insertions, 0 deletions
diff --git a/pw_toolchain/generate_toolchain.gni b/pw_toolchain/generate_toolchain.gni
index 336566ea3..223553975 100644
--- a/pw_toolchain/generate_toolchain.gni
+++ b/pw_toolchain/generate_toolchain.gni
@@ -377,13 +377,22 @@ template("generate_toolchain") {
_outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
description = "rustc {{output}}"
+ depfile = "{{output}}.d"
command =
string_join(" ",
[
# TODO(b/234872510): Ensure this works with Windows.
"RUST_BACKTRACE=1",
+ "{{rustenv}}",
invoker.rustc,
"{{source}}",
+ "--crate-name {{crate_name}}",
+ "--crate-type {{crate_type}}",
+ "{{rustflags}}",
+ "{{rustdeps}}",
+ "{{externs}}",
+ "--emit=dep-info=$depfile,link",
+ "-Zdep-info-omit-d-target",
"-o $_outfile",
"--color always",
"-D warnings",