On 2022-12-08 06:26, Sundeep KOKKONDA via lists.openembedded.org wrote:
Rust code compilation on qemu failed with with below error.
error: Error loading target specification: Could not find specification for target 
"x86_64-poky-linux-gnu". Run `rustc --print target-list` for a list of built-in 
targets.

This patch fix the issue by adding the missing json file to the image.

Signed-off-by: Sundeep KOKKONDA <[email protected]>
---
  meta/recipes-devtools/rust/files/target.json | 39 ++++++++++++++++++++

When I fixed this manually, I just copied this file from:

tmp/work/core2-64-poky-linux/rust/1.65.0-r0/rustc-1.65.0-src/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json

so I'm puzzled about why you didn't take that file, or better still a non-test source of that file,
and perhaps sed out the  'has-elf-tls' line that generates the warning.

Also, this looks like it would only work for x86-64 due to:

data-layout":
+"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",


Perhaps the target.json isn't really what's needed since I
I don't see such a file in my desktop install that I installed using rustup.

Back to the drawing board....

Oh, in the rust git repo:
$ grep -B 4 -A 2 target.json RELEASES.md
Compiler
-----------------------

- [Rustc will now search for custom JSON targets in
  `/lib/rustlib/<target-triple>/target.json` where `/` is the "sysroot"
  directory.][83800] You can find your sysroot directory by running
  `rustc --print sysroot`.

so maybe looking at the commit log for that change will get you heading in the right direction.

../Randy

  meta/recipes-devtools/rust/rust.inc          |  9 +++++
  meta/recipes-devtools/rust/rust_1.65.0.bb    |  2 +
  3 files changed, 50 insertions(+)
  create mode 100644 meta/recipes-devtools/rust/files/target.json

diff --git a/meta/recipes-devtools/rust/files/target.json 
b/meta/recipes-devtools/rust/files/target.json
new file mode 100644
index 0000000000..69dbbaa9f9
--- /dev/null
+++ b/meta/recipes-devtools/rust/files/target.json
@@ -0,0 +1,39 @@
+{
+   "arch": "x86_64",
+   "cpu": "x86-64",
+   "crt-static-respected": true,
+   "data-layout":
+"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
+   "dynamic-linking": true,
+   "env": "gnu",
+   "executables": true,
+   "has-rpath": true,
+   "linker-is-gnu": true,
+   "llvm-target": "x86_64-unknown-linux-gnu",
+   "max-atomic-width": 64,
+   "os": "linux",
+   "position-independent-executables": true,
+   "pre-link-args": {
+     "gcc": [
+       "-m64"
+     ]
+   },
+   "relro-level": "full",
+   "stack-probes": {
+     "kind": "inline-or-call",
+     "min-llvm-version-for-inline": [
+       11,
+       0,
+       1
+     ]
+   },
+   "supported-sanitizers": [
+     "address",
+     "leak",
+     "memory",
+     "thread"
+   ],
+   "target-family": "unix",
+   "target-pointer-width": "64"
+}
+
diff --git a/meta/recipes-devtools/rust/rust.inc 
b/meta/recipes-devtools/rust/rust.inc
index 956301023a..75473f967b 100644
--- a/meta/recipes-devtools/rust/rust.inc
+++ b/meta/recipes-devtools/rust/rust.inc
@@ -13,6 +13,10 @@ DEPENDS:append:class-nativesdk = " nativesdk-rust-llvm"
S = "${RUSTSRC}" +SRC_URI += "\
+     file://target.json \
+"
+
  export FORCE_CRATE_HASH="${BB_TASKHASH}"
RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
@@ -217,3 +221,8 @@ rust_do_install () {
  do_install () {
      rust_do_install
  }
+
+FILE_${PN} += " \
+       ${WORKDIR}/target.json \
+"
+
diff --git a/meta/recipes-devtools/rust/rust_1.65.0.bb 
b/meta/recipes-devtools/rust/rust_1.65.0.bb
index dbf74cec8f..afef72e45c 100644
--- a/meta/recipes-devtools/rust/rust_1.65.0.bb
+++ b/meta/recipes-devtools/rust/rust_1.65.0.bb
@@ -68,6 +68,8 @@ rust_do_install:class-target() {
          chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
      done
+ cp ${WORKDIR}/target.json ${D}${libdir}/rustlib/${RUST_TARGET_SYS}
+
      chown root:root ${D}/ -R
      rm ${D}${libdir}/rustlib/uninstall.sh
      rm ${D}${libdir}/rustlib/install.log




--
# Randy MacLeod
# Wind River Linux

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#174407): 
https://lists.openembedded.org/g/openembedded-core/message/174407
Mute This Topic: https://lists.openembedded.org/mt/95535785/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to