Skip to content

Commit

Permalink
pw_rust: Allow override proc_macro toolchain
Browse files Browse the repository at this point in the history
Prefer toolchain from `rustc_macro_toolchain_name` even if the current
toolchain is a host toolchain.

It is useful for x86 32 bits targets. proc_macro compiled with i686
target cannot work with 64bits rustc. Issue can be solved by setting
proc_macro toolchain to 64bits for 32bits host toolchain.

Test: Cross compiling for QEMU target works
Change-Id: I40cac9ee00f239fe891c63a84859cc7398be5564
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/255392
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: Jiacheng Lu <lujc@google.com>
Docs-Not-Needed: Jiacheng Lu <lujc@google.com>
Reviewed-by: Erik Gilling <konkers@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
Jason0214 authored and CQ Bot Account committed Dec 18, 2024
1 parent 8fddf43 commit d7fcaef
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pw_build/rust_proc_macro.gni
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ import("$dir_pw_toolchain/toolchain_args.gni")
# For more information on the features provided by this template, see the full
# docs at https://pigweed.dev/pw_build/?highlight=pw_rust_proc_macro.
template("pw_rust_proc_macro") {
if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
pw_toolchain_SCOPE.is_host_toolchain) {
if (defined(pw_toolchain_SCOPE.rustc_macro_toolchain_name)) {
group(target_name) {
public_deps =
[ ":$target_name(${pw_toolchain_SCOPE.rustc_macro_toolchain_name})" ]
}
not_needed(invoker, "*")
} else if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
pw_toolchain_SCOPE.is_host_toolchain) {
pw_rust_library(target_name) {
forward_variables_from(invoker, "*")

Expand All @@ -50,14 +56,9 @@ template("pw_rust_proc_macro") {
}
} else {
assert(
defined(pw_toolchain_SCOPE.rustc_macro_toolchain_name),
"Rust macro crates are compiled with host toolchain. Please provided " +
"a `rustc_macro_toolchain_name` for this device toolchain.")

toolchain_name = pw_toolchain_SCOPE.rustc_macro_toolchain_name
group(target_name) {
public_deps = [ ":$target_name($toolchain_name)" ]
}
not_needed(invoker, "*")
false,
"proc_macro target ${target_name}(${pw_toolchain_SCOPE.name}) is not " +
"a host target, please specify a host toolchain through " +
"`rustc_macro_toolchain_name` for it to be compiled.")
}
}

0 comments on commit d7fcaef

Please sign in to comment.