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

Message ID 20220707171904.338441-1-otavio@ossystems.com.br
State New
Headers show
Series [1/2] rust-common: Fix use of target definitions for SDK generation | expand

Commit Message

Otavio Salvador July 7, 2022, 5:19 p.m. UTC
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")
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---

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

Comments

Otavio Salvador July 7, 2022, 5:21 p.m. UTC | #1
My mistake, sorry.

Em qui., 7 de jul. de 2022 às 14:19, Otavio Salvador via
lists.openembedded.org <otavio.salvador=gmail.com@lists.openembedded.org>
escreveu:

> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> Link:
> https://lore.kernel.org/r/20220627111927.641837068@linuxfoundation.org
> Tested-by: Jon Hunter <jonathanh@nvidia.com>
> Tested-by: Florian Fainelli <f.fainelli@gmail.com>
> Tested-by: Shuah Khan <skhan@linuxfoundation.org>
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> Tested-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
> Tested-by: Hulk Robot <hulkrobot@huawei.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index ae9156f804e5..021878dc23f9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> otavio.salvador@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Richard Purdie July 9, 2022, 1:14 p.m. UTC | #2
On Thu, 2022-07-07 at 14:19 -0300, Otavio Salvador wrote:
> 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")
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> ---
> 
>  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
Otavio Salvador July 9, 2022, 4 p.m. UTC | #3
Em sáb., 9 de jul. de 2022 às 10:14, Richard Purdie <
richard.purdie@linuxfoundation.org> escreveu:

> On Thu, 2022-07-07 at 14:19 -0300, Otavio Salvador wrote:
> > 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")
> > Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> > ---
> >
> >  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.
>

I will fix and send a v2.

Patch

diff --git a/meta/recipes-devtools/rust/rust-common.inc b/meta/recipes-devtools/rust/rust-common.inc
index ef70c48d0f..f8d365ecf8 100644
--- a/meta/recipes-devtools/rust/rust-common.inc
+++ b/meta/recipes-devtools/rust/rust-common.inc
@@ -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)
diff --git a/meta/recipes-devtools/rust/rust-cross-canadian-common.inc b/meta/recipes-devtools/rust/rust-cross-canadian-common.inc
index 1f21c8af26..eff9212648 100644
--- a/meta/recipes-devtools/rust/rust-cross-canadian-common.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian-common.inc
@@ -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"