From: Yash.Shinde@windriver.com
To: openembedded-core@lists.openembedded.org
Cc: Randy.MacLeod@windriver.com, Umesh.Kallapa@windriver.com,
Naveen.Gowda@windriver.com, Sundeep.Kokkonda@windriver.com,
Shivaprasad.Moodalappa@windriver.com, Yash.Shinde@windriver.com
Subject: [PATCH v2 2/5] rust: detect user-specified custom targets in compiletest
Date: Fri, 19 Jan 2024 07:09:04 -0800 [thread overview]
Message-ID: <20240119150907.3840110-2-Yash.Shinde@windriver.com> (raw)
In-Reply-To: <20240119150907.3840110-1-Yash.Shinde@windriver.com>
From: Yash Shinde <Yash.Shinde@windriver.com>
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.
Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
---
.../rust/files/custom-target-cfg.patch | 90 +++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 meta/recipes-devtools/rust/files/custom-target-cfg.patch
diff --git a/meta/recipes-devtools/rust/files/custom-target-cfg.patch b/meta/recipes-devtools/rust/files/custom-target-cfg.patch
new file mode 100644
index 0000000000..15a7f252cc
--- /dev/null
+++ b/meta/recipes-devtools/rust/files/custom-target-cfg.patch
@@ -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,
+
--
2.43.0
next prev parent reply other threads:[~2024-01-19 15:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 15:09 [PATCH v2 1/5] rust: Fetch cargo from rust-snapshot dir Yash.Shinde
2024-01-19 15:09 ` Yash.Shinde [this message]
2024-01-19 15:09 ` [PATCH v2 3/5] rust: Enable RUSTC_BOOTSTRAP to use nightly features during rust oe-selftest Yash.Shinde
2024-01-19 15:09 ` [PATCH v2 4/5] rust: Fix assertion failure error on oe-selftest Yash.Shinde
2024-01-19 15:09 ` [PATCH v2 5/5] rust: Enable rust oe-selftest Yash.Shinde
2024-01-20 17:01 ` Randy MacLeod
2024-01-22 10:59 ` Yash Shinde
2024-01-22 11:01 ` Shinde, Yash
2024-01-20 8:42 ` [OE-core] [PATCH v2 1/5] rust: Fetch cargo from rust-snapshot dir Richard Purdie
[not found] ` <17AC01A476481111.16230@lists.openembedded.org>
2024-01-20 8:49 ` Richard Purdie
2024-01-20 10:46 ` Yash Shinde
2024-01-20 17:03 ` Randy MacLeod
2024-01-22 10:58 ` Yash Shinde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240119150907.3840110-2-Yash.Shinde@windriver.com \
--to=yash.shinde@windriver.com \
--cc=Naveen.Gowda@windriver.com \
--cc=Randy.MacLeod@windriver.com \
--cc=Shivaprasad.Moodalappa@windriver.com \
--cc=Sundeep.Kokkonda@windriver.com \
--cc=Umesh.Kallapa@windriver.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox