From d7fcaef689c728904c769c3f383ed899263b3049 Mon Sep 17 00:00:00 2001 From: Jiacheng Lu Date: Wed, 18 Dec 2024 09:08:29 -0800 Subject: [PATCH] pw_rust: Allow override proc_macro toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Lint: Lint 🤖 Pigweed-Auto-Submit: Jiacheng Lu Docs-Not-Needed: Jiacheng Lu Reviewed-by: Erik Gilling Presubmit-Verified: CQ Bot Account --- pw_build/rust_proc_macro.gni | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pw_build/rust_proc_macro.gni b/pw_build/rust_proc_macro.gni index 0220eceba..2eae0abf0 100644 --- a/pw_build/rust_proc_macro.gni +++ b/pw_build/rust_proc_macro.gni @@ -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, "*") @@ -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.") } }