Skip to contentSkip to conversation

rust-common: Fix use of target definitions for SDK generation

PATCH Superseded Otavio Salvador 3 participants 6 messages Jul 7, 2022 – Jul 9, 2022 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 rust-common: Fix use of target definitions for SDK generation

We need full target passed for build so we changed the rust-cross-canadian to use same code used in regular rust recipes and added support to use specific llvm-target for the building host.

Fixes ef566af964 ("rust: fix issue building cross-canadian tools for aarch64 on x86_64")
Fixes bd36593ba3 ("rust-common: Drop LLVM_TARGET and simplify")
Fixes 8ed000debb ("rust-common: Fix for target definitions returning 'NoneType' for arm")

---

 meta/recipes-devtools/rust/rust-common.inc    | 21 ++++++++++++------
 .../rust/rust-cross-canadian-common.inc       | 22 ++++++++++++++++---
 2 files changed, 33 insertions(+), 10 deletions(-)
meta/recipes-devtools/rust/rust-common.inc +14 -7
index ef70c48d0f..f8d365ecf8 100644
@@ -119,12 +119,12 @@ def llvm_features(d):
 
 
 ## arm-unknown-linux-gnueabihf
-DATA_LAYOUT[arm] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
-TARGET_ENDIAN[arm] = "little"
-TARGET_POINTER_WIDTH[arm] = "32"
-TARGET_C_INT_WIDTH[arm] = "32"
-MAX_ATOMIC_WIDTH[arm] = "64"
-FEATURES[arm] = "+v6,+vfp2"
+DATA_LAYOUT[arm-eabi] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+TARGET_ENDIAN[arm-eabi] = "little"
+TARGET_POINTER_WIDTH[arm-eabi] = "32"
+TARGET_C_INT_WIDTH[arm-eabi] = "32"
+MAX_ATOMIC_WIDTH[arm-eabi] = "64"
+FEATURES[arm-eabi] = "+v6,+vfp2"
 
 ## armv7-unknown-linux-gnueabihf
 DATA_LAYOUT[armv7-eabi] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
@@ -304,12 +304,19 @@ def rust_gen_target(d, thing, wd, features, cpu, arch, abi=""):
     else:
         arch_abi = rust_arch
 
+    # When building for the building system we need to return the HOST target
+    # or wrong flags are used.
+    if thing is "BUILD":
+        llvm_target = d.getVar('RUST_HOST_SYS', arch_abi)
+    else:
+        llvm_target = d.getVar('RUST_TARGET_SYS', arch_abi)
+
     features = features or d.getVarFlag('FEATURES', arch_abi) or ""
     features = features.strip()
 
     # build tspec
     tspec = {}
-    tspec['llvm-target'] = d.getVar('RUST_TARGET_SYS', arch_abi)
+    tspec['llvm-target'] = llvm_target
     tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch_abi)
     tspec['max-atomic-width'] = int(d.getVarFlag('MAX_ATOMIC_WIDTH', arch_abi))
     tspec['target-pointer-width'] = d.getVarFlag('TARGET_POINTER_WIDTH', arch_abi)
meta/recipes-devtools/rust/rust-cross-canadian-common.inc +19 -3
index 1f21c8af26..eff9212648 100644
@@ -27,9 +27,23 @@ DEBUG_PREFIX_MAP = "-fdebug-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDP
 
 python do_rust_gen_targets () {
     wd = d.getVar('WORKDIR') + '/targets/'
-    rust_gen_target(d, 'TARGET', wd, d.getVar('TARGET_LLVM_FEATURES') or "", d.getVar('TARGET_LLVM_CPU'), d.getVar('TARGET_ARCH'))
-    rust_gen_target(d, 'HOST', wd, "", "generic", d.getVar('HOST_ARCH'))
-    rust_gen_target(d, 'BUILD', wd, "", "generic", d.getVar('BUILD_ARCH'))
+    # It is important 'TARGET' is last here so that it overrides our less
+    # informed choices for BUILD & HOST if TARGET happens to be the same as
+    # either of them.
+    for thing in ['BUILD', 'HOST', 'TARGET']:
+        bb.debug(1, "rust_gen_target for " + thing)
+        features = ""
+        cpu = "generic"
+        arch = d.getVar('{}_ARCH'.format(thing))
+        abi = ""
+        if thing is "TARGET":
+            abi = d.getVar('ABIEXTENSION')
+            # arm and armv7 have different targets in llvm
+            if arch == "arm" and target_is_armv7(d):
+                arch = 'armv7'
+            features = d.getVar('TARGET_LLVM_FEATURES') or ""
+            cpu = d.getVar('TARGET_LLVM_CPU')
+        rust_gen_target(d, thing, wd, features, cpu, arch, abi)
 }
 
 INHIBIT_DEFAULT_RUST_DEPS = "1"
@@ -45,6 +59,8 @@ python do_configure:prepend() {
     hosts = ["{}-unknown-linux-gnu".format(d.getVar("HOST_ARCH", True))]
 }
 
+INSANE_SKIP:${PN} = "libdir"
+
 INSANE_SKIP:${RUSTLIB_TARGET_PN} = "file-rdeps arch ldflags"
 SKIP_FILEDEPS:${RUSTLIB_TARGET_PN} = "1"
 
Signature · 1 line
2.36.1
#1 lore raw

PATCH 2/2 cargo-cross-canadian: Use SDK's flags during target linking

---

 .../cargo/cargo-cross-canadian.inc            | 20 ++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
meta/recipes-devtools/cargo/cargo-cross-canadian.inc +19 -1
index 7fc22a4128..01ba151d0a 100644
@@ -39,6 +39,18 @@ do_compile:prepend () {
 	PKG_CONFIG_PATH="${RECIPE_SYSROOT_NATIVE}/usr/lib/pkgconfig:${PKG_CONFIG_PATH}"
 }
 
+create_sdk_wrapper () {
+        file="$1"
+        shift
+
+        cat <<- EOF > "${file}"
+		#!/bin/sh
+		\$$1 \$@
+		EOF
+
+        chmod +x "$file"
+}
+
 do_install () {
     SYS_BINDIR=$(dirname ${D}${bindir})
     install -d "${SYS_BINDIR}"
@@ -47,6 +59,9 @@ do_install () {
 	chrpath -r "\$ORIGIN/../lib" ${i}
     done
 
+    # Uses SDK's CC as linker so linked binaries works out of box.
+    create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld" "CC"
+
     ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
     mkdir "${ENV_SETUP_DIR}"
     ENV_SETUP_SH="${ENV_SETUP_DIR}/cargo.sh"
@@ -58,7 +73,10 @@ do_install () {
 		touch "\$CARGO_HOME/config"
 		echo "[build]" >> "\$CARGO_HOME/config"
 		echo 'target = "'${TARGET_SYS}'"' >> "\$CARGO_HOME/config"
-        fi
+		echo '# TARGET_SYS' >> "\$CARGO_HOME/config"
+		echo '[target.'${TARGET_SYS}']' >> "\$CARGO_HOME/config"
+		echo 'linker = "target-rust-ccld"' >> "\$CARGO_HOME/config"
+    fi
 
 	# Keep the below off as long as HTTP/2 is disabled.
 	export CARGO_HTTP_MULTIPLEXING=false
Signature · 1 line
2.36.1
#2 lore raw

PATCH 1/1 Linux 5.4.202

In reply to Otavio Salvador

From: Greg Kroah-Hartman <[email protected]>

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index ae9156f804e5..021878dc23f9 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 VERSION = 5
 PATCHLEVEL = 4
-SUBLEVEL = 201
+SUBLEVEL = 202
 EXTRAVERSION =
 NAME = Kleptomaniac Octopus
 
Signature · 1 line
2.36.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [OE-core] [PATCH] Linux 5.4.202

My mistake, sorry.

Em qui., 7 de jul. de 2022 às 14:19, Otavio Salvador via lists.openembedded.org <[email protected]> escreveu:

Quoted 43 lines

From: Greg Kroah-Hartman <[email protected]>

Link:
https://lore.kernel.org/r/[email protected]

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -2
index ae9156f804e5..021878dc23f9 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 VERSION = 5
 PATCHLEVEL = 4
-SUBLEVEL = 201
+SUBLEVEL = 202
 EXTRAVERSION =
 NAME = Kleptomaniac Octopus
 
--

2.36.1

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

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854          Mobile: +1 (347) 903-9750
#5 lore raw
In reply to Otavio Salvador
Quoted 8 lines · Otavio Salvador

We need full target passed for build so we changed the rust-cross-canadian to use same code used in regular rust recipes and added support to use specific llvm-target for the building host.

Fixes ef566af964 ("rust: fix issue building cross-canadian tools for aarch64 on x86_64")
Fixes bd36593ba3 ("rust-common: Drop LLVM_TARGET and simplify")
Fixes 8ed000debb ("rust-common: Fix for target definitions returning 'NoneType' for arm")
Quoted 5 lines

---

 meta/recipes-devtools/rust/rust-common.inc    | 21 ++++++++++++------
 .../rust/rust-cross-canadian-common.inc       | 22 ++++++++++++++++---
 2 files changed, 33 insertions(+), 10 deletions(-)

I ran these through the autobuilder:

https://autobuilder.yoctoproject.org/typhoon/#/builders/87/builds/3809/steps/14/logs/stdio

seems there is some syntax that recent python doesn't like. I do need to look at the patches in more detail but wanted to share the autobuilder results.

Cheers,

Richard

#6 lore raw

Em sáb., 9 de jul. de 2022 às 10:14, Richard Purdie < [email protected]> escreveu:

Quoted 17 lines · Otavio Salvador
Quoted 5 lines

We need full target passed for build so we changed the rust-cross-canadian to use same code used in regular rust recipes and added support to use specific llvm-target for the building host.

Fixes ef566af964 ("rust: fix issue building cross-canadian tools for

aarch64 on x86_64")

Quoted 2 lines
Fixes bd36593ba3 ("rust-common: Drop LLVM_TARGET and simplify")
Fixes 8ed000debb ("rust-common: Fix for target definitions returning

'NoneType' for arm")

Quoted 6 lines

---

 meta/recipes-devtools/rust/rust-common.inc    | 21 ++++++++++++------
 .../rust/rust-cross-canadian-common.inc       | 22 ++++++++++++++++---
 2 files changed, 33 insertions(+), 10 deletions(-)
Quoted 9 lines

I ran these through the autobuilder:

https://autobuilder.yoctoproject.org/typhoon/#/builders/87/builds/3809/steps/14/logs/stdio

seems there is some syntax that recent python doesn't like. I do need to look at the patches in more detail but wanted to share the autobuilder results.

I will fix and send a v2.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854          Mobile: +1 (347) 903-9750