mirror of
https://git.yoctoproject.org/poky
synced 2026-04-23 00:32:12 +02:00
rust: detect user-specified custom targets in compiletest
Fixes: thread 'main' panicked at 'failed to gather the target spec
for '<arch>-unknown-linux-gnu', synthetic_targets.rs:66:9
Detect and fetch custom target configurations when rustc is
bootstrapped in rust oe-selftest.
(From OE-Core rev: fdd9385d9845d628e10179598fc42d29519c5dfd)
Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
357651377f
commit
0a066f7526
90
meta/recipes-devtools/rust/files/custom-target-cfg.patch
Normal file
90
meta/recipes-devtools/rust/files/custom-target-cfg.patch
Normal file
@@ -0,0 +1,90 @@
|
||||
Detect and fetch custom target configurations when rustc is
|
||||
bootstrapped in rust oe-selftest.
|
||||
|
||||
Upstream-Status: Backport [https://github.com/rust-lang/rust/pull/119619/commits/26c71cbcf1a9bce6ceb962d753c467d098f63cf6]
|
||||
|
||||
Signed-off-by: onur-ozkan <work@onurozkan.dev>
|
||||
Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
|
||||
---
|
||||
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
|
||||
index e85f6319936..c45c0b3c652 100644
|
||||
--- a/src/tools/compiletest/src/common.rs
|
||||
+++ b/src/tools/compiletest/src/common.rs
|
||||
@@ -479,6 +479,7 @@ fn new(config: &Config) -> TargetCfgs {
|
||||
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output(
|
||||
config,
|
||||
&["--print=all-target-specs-json", "-Zunstable-options"],
|
||||
+ Default::default(),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
@@ -491,16 +492,33 @@ fn new(config: &Config) -> TargetCfgs {
|
||||
let mut all_families = HashSet::new();
|
||||
let mut all_pointer_widths = HashSet::new();
|
||||
|
||||
- // Handle custom target specs, which are not included in `--print=all-target-specs-json`.
|
||||
- if config.target.ends_with(".json") {
|
||||
- targets.insert(
|
||||
- config.target.clone(),
|
||||
- serde_json::from_str(&rustc_output(
|
||||
- config,
|
||||
- &["--print=target-spec-json", "-Zunstable-options", "--target", &config.target],
|
||||
- ))
|
||||
- .unwrap(),
|
||||
- );
|
||||
+ // If current target is not included in the `--print=all-target-specs-json` output,
|
||||
+ // we check whether it is a custom target from the user or a synthetic target from bootstrap.
|
||||
+ if !targets.contains_key(&config.target) {
|
||||
+ let mut envs: HashMap<String, String> = HashMap::new();
|
||||
+
|
||||
+ if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
|
||||
+ envs.insert("RUST_TARGET_PATH".into(), t);
|
||||
+ }
|
||||
+
|
||||
+ // This returns false only when the target is neither a synthetic target
|
||||
+ // nor a custom target from the user, indicating it is most likely invalid.
|
||||
+ if config.target.ends_with(".json") || !envs.is_empty() {
|
||||
+ targets.insert(
|
||||
+ config.target.clone(),
|
||||
+ serde_json::from_str(&rustc_output(
|
||||
+ config,
|
||||
+ &[
|
||||
+ "--print=target-spec-json",
|
||||
+ "-Zunstable-options",
|
||||
+ "--target",
|
||||
+ &config.target,
|
||||
+ ],
|
||||
+ envs,
|
||||
+ ))
|
||||
+ .unwrap(),
|
||||
+ );
|
||||
+ }
|
||||
}
|
||||
|
||||
for (target, cfg) in targets.iter() {
|
||||
@@ -545,7 +563,9 @@ fn get_current_target_config(
|
||||
// code below extracts them from `--print=cfg`: make sure to only override fields that can
|
||||
// actually be changed with `-C` flags.
|
||||
for config in
|
||||
- rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
|
||||
+ rustc_output(config, &["--print=cfg", "--target", &config.target], Default::default())
|
||||
+ .trim()
|
||||
+ .lines()
|
||||
{
|
||||
let (name, value) = config
|
||||
.split_once("=\"")
|
||||
@@ -624,11 +644,12 @@ pub enum Endian {
|
||||
Big,
|
||||
}
|
||||
|
||||
-fn rustc_output(config: &Config, args: &[&str]) -> String {
|
||||
+fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
|
||||
let mut command = Command::new(&config.rustc_path);
|
||||
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
|
||||
command.args(&config.target_rustcflags).args(args);
|
||||
command.env("RUSTC_BOOTSTRAP", "1");
|
||||
+ command.envs(envs);
|
||||
|
||||
let output = match command.output() {
|
||||
Ok(output) => output,
|
||||
|
||||
Reference in New Issue
Block a user