rust: Fix powerpc64le support
v2 cover rust: Fix powerpc64le support
Hello,
Here's v2 of what was previously an RFC series where I just slashed my way through trying to get rust going out of the box on powerpc64le.
Thanks to some pointers from Alex that effort has been significantly cleaned up.
v2 is no-longer RFC as I think I have a decent understanding of what's going on now. The RFC series can be found here:
https://lore.kernel.org/openembedded-core/[email protected]/
The changes in v2 include:
* Drop the incorrect attempts at refactoring
* Drop the (now unnecessary) install hack for libstd-rs
* Drop the patch that tried to avoid duplicate toml sections by instead fixing the build configuration
The bits that survived since the RFC were:
* The introduction of RUST_BUILD_ARCH to handle the snapshot artifacts
* The introduction of arch_to_rust_arch() in a new python library for rust
arch_to_rust_arch() is not just a rename of arch_to_rust_target_arch() as it was in the RFC. arch_to_rust_target_arch() stays for its existing job - arch_to_rust_arch() appears alongside to do arch translations earlier in the process. I'm not wedded to 'arch_to_rust_arch()' as a name, if someone has a better color for the bikeshed then suggest away.
Finally, I've re-posted the patch adding the snapshot checksums for powerpc64le in case there is any enthusiasm for applying it. It's okay if not, we can maintain that in e.g. OpenBMC in a bbappend if necessary.
Please review!
Andrew Jeffery (3):
rust: Introduce arch_to_rust_arch()
rust: Introduce RUST_BUILD_ARCH
rust: Add snapshot checksums for powerpc64le
meta/classes/base.bbclass | 2 +- meta/classes/rust-common.bbclass | 6 +++++- meta/lib/oe/rust.py | 5 +++++ meta/recipes-devtools/rust/rust-common.inc | 8 +++++--- meta/recipes-devtools/rust/rust-snapshot.inc | 16 ++++++++++------ meta/recipes-devtools/rust/rust.inc | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 meta/lib/oe/rust.py
Signature · 1 line
2.32.0
PATCH v2 1/3 rust: Introduce arch_to_rust_arch()
On modern Power systems uname -m yields 'ppc64le' while the toolchain knows the architecture as 'powerpc64le'. Provide a mapping from one to the other to integrate with the existing architecture configuration flags.
arch_to_rust_arch() only exists to map the OE *_ARCH variables before any further processing, unlike arch_to_rust_target_arch() which is specific to the internal triple handling of rust.
On Linux ppc64le systems the changes give the following config:
```
$ cat ./tmp/work/ppc64le-linux/rust-native/1.58.0-r0/targets/ppc64le-linux.json
{
"llvm-target": "powerpc64le-unknown-linux-gnu",
"data-layout": "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512",
"max-atomic-width": 64,
"target-pointer-width": "64",
"target-c-int-width": "64",
"target-endian": "little",
"arch": "powerpc64",
"os": "linux",
"env": "gnu",
"vendor": "unknown",
"target-family": "unix",
"linker": "gcc",
"cpu": "generic",
"dynamic-linking": true,
"executables": true,
"linker-is-gnu": true,
"linker-flavor": "gcc",
"has-rpath": true,
"has-elf-tls": true,
"position-independent-executables": true,
"panic-strategy": "unwind"
}
```--- meta/classes/base.bbclass | 2 +- meta/classes/rust-common.bbclass | 2 +- meta/lib/oe/rust.py | 5 +++++ meta/recipes-devtools/rust/rust-common.inc | 8 +++++--- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 meta/lib/oe/rust.py
meta/classes/base.bbclass +1 -1
@@ -12,7 +12,7 @@ inherit logging OE_EXTRA_IMPORTS ?= "" -OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible ${OE_EXTRA_IMPORTS}" +OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible oe.rust ${OE_EXTRA_IMPORTS}" OE_IMPORTS[type] = "list" PACKAGECONFIG_CONFARGS ??= ""
meta/classes/rust-common.bbclass +1 -1
@@ -65,7 +65,7 @@ def rust_base_triple(d, thing): if thing == "TARGET" and target_is_armv7(d): arch = "armv7" else: - arch = d.getVar('{}_ARCH'.format(thing)) + arch = oe.rust.arch_to_rust_arch(d.getVar('{}_ARCH'.format(thing))) # All the Yocto targets are Linux and are 'unknown' vendor = "-unknown"
meta/lib/oe/rust.py new file +5 -0
@@ -0,0 +1,5 @@ +# Handle mismatches between `uname -m`-style output and Rust's arch names +def arch_to_rust_arch(arch): + if arch == "ppc64le": + return "powerpc64le" + return arch
meta/recipes-devtools/rust/rust-common.inc +5 -3
@@ -313,10 +313,12 @@ def rust_gen_target(d, thing, wd, features, cpu, arch, abi=""): sys = sys_for(d, thing) prefix = prefix_for(d, thing) + rust_arch = oe.rust.arch_to_rust_arch(arch) + if abi: - arch_abi = "{}-{}".format(arch, abi) + arch_abi = "{}-{}".format(rust_arch, abi) else: - arch_abi = arch + arch_abi = rust_arch features = features or d.getVarFlag('FEATURES', arch_abi) or "" features = features.strip()
@@ -329,7 +331,7 @@ def rust_gen_target(d, thing, wd, features, cpu, arch, abi=""): tspec['target-pointer-width'] = d.getVarFlag('TARGET_POINTER_WIDTH', arch_abi) tspec['target-c-int-width'] = d.getVarFlag('TARGET_C_INT_WIDTH', arch_abi) tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch_abi) - tspec['arch'] = arch_to_rust_target_arch(arch) + tspec['arch'] = arch_to_rust_target_arch(rust_arch) tspec['os'] = "linux" if "musl" in tspec['llvm-target']: tspec['env'] = "musl"
Signature · 1 line
2.32.0
PATCH v2 2/3 rust: Introduce RUST_BUILD_ARCH
In reply to Andrew JefferyRUST_BUILD_ARCH contains the arch_to_rust_arch()-translated value of BUILD_ARCH. This is necessary to acquire the correct snapshot artifacts under Linux where uname -m reports "ppc64le" rather than "powerpc64le".
--- meta/classes/rust-common.bbclass | 4 ++++ meta/recipes-devtools/rust/rust-snapshot.inc | 12 ++++++------ meta/recipes-devtools/rust/rust.inc | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
meta/classes/rust-common.bbclass +4 -0
@@ -89,6 +89,10 @@ def rust_base_triple(d, thing): libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d) return arch + vendor + '-' + os + libc + +# In some cases uname and the toolchain differ on their idea of the arch name +RUST_BUILD_ARCH = "${@oe.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}" + # Naming explanation # Yocto # - BUILD_SYS - Yocto triple of the build environment
meta/recipes-devtools/rust/rust-snapshot.inc +6 -6
@@ -15,11 +15,11 @@ SRC_URI[rustc-snapshot-aarch64.sha256sum] = "f26811e48d03c56c125de03d389e1ae7c6d SRC_URI[cargo-snapshot-aarch64.sha256sum] = "6d11cd94618d80cda273eeeae7285980445f61a49ebacc616777b482a41cbf3f" SRC_URI += " \ - https://static.rust-lang.org/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${BUILD_ARCH};subdir=rust-snapshot-components \ - https://static.rust-lang.org/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${BUILD_ARCH};subdir=rust-snapshot-components \ - https://static.rust-lang.org/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${BUILD_ARCH};subdir=rust-snapshot-components \ + https://static.rust-lang.org/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ + https://static.rust-lang.org/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ + https://static.rust-lang.org/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ " -RUST_STD_SNAPSHOT = "rust-std-${RS_VERSION}-${BUILD_ARCH}-unknown-linux-gnu" -RUSTC_SNAPSHOT = "rustc-${RS_VERSION}-${BUILD_ARCH}-unknown-linux-gnu" -CARGO_SNAPSHOT = "cargo-${CARGO_VERSION}-${BUILD_ARCH}-unknown-linux-gnu" +RUST_STD_SNAPSHOT = "rust-std-${RS_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu" +RUSTC_SNAPSHOT = "rustc-${RS_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu" +CARGO_SNAPSHOT = "cargo-${CARGO_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
meta/recipes-devtools/rust/rust.inc +1 -1
@@ -27,7 +27,7 @@ CARGO_DISABLE_BITBAKE_VENDORING = "1" # We can't use RUST_BUILD_SYS here because that may be "musl" if # TCLIBC="musl". Snapshots are always -unknown-linux-gnu -SNAPSHOT_BUILD_SYS = "${BUILD_ARCH}-unknown-linux-gnu" +SNAPSHOT_BUILD_SYS = "${RUST_BUILD_ARCH}-unknown-linux-gnu" setup_cargo_environment () { # The first step is to build bootstrap and some early stage tools, # these are build for the same target as the snapshot, e.g.
Signature · 1 line
2.32.0
PATCH v2 3/3 rust: Add snapshot checksums for powerpc64le
In reply to Andrew Jeffery--- meta/recipes-devtools/rust/rust-snapshot.inc | 4 ++++ 1 file changed, 4 insertions(+)
meta/recipes-devtools/rust/rust-snapshot.inc +4 -0
@@ -14,6 +14,10 @@ SRC_URI[rust-std-snapshot-aarch64.sha256sum] = "3618da916a0f92f241cf1d67d04bb578 SRC_URI[rustc-snapshot-aarch64.sha256sum] = "f26811e48d03c56c125de03d389e1ae7c6df36990953c1670c6a5676bc12d4cb" SRC_URI[cargo-snapshot-aarch64.sha256sum] = "6d11cd94618d80cda273eeeae7285980445f61a49ebacc616777b482a41cbf3f" +SRC_URI[rust-std-snapshot-powerpc64le.sha256sum] = "fc07eb3e9f3d227428cc5b53ca868e3de375bc198ce4dce7b87a9246e6fec81a" +SRC_URI[rustc-snapshot-powerpc64le.sha256sum] = "f43cb99109c3438c77c7079cdce4673df3320e310158e0b4d949c1babc4300fc" +SRC_URI[cargo-snapshot-powerpc64le.sha256sum] = "599cf1b5a8cdbf76d591621bc9222aefa60e2f5fd378ae71c4dcf4514c47122e" + SRC_URI += " \ https://static.rust-lang.org/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ https://static.rust-lang.org/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \
Signature · 1 line
2.32.0
Re: [PATCH v2 3/3] rust: Add snapshot checksums for powerpc64le
The final call is Richard's but I would still prefer to have this in core if there is at least one other consumer of it, other than openbmc.
The downside of .bbappend is that there'll be inevitably a breakage window where the .bbappend needs to be updated.
Alex
Quoted 24 lines · Andrew Jeffery
Signed-off-by Andrew Jeffery <[email protected]>--- meta/recipes-devtools/rust/rust-snapshot.inc | 4 ++++ 1 file changed, 4 insertions(+)meta/recipes-devtools/rust/rust-snapshot.inc +4
-1@@ -14,6 +14,10 @@ SRC_URI[rust-std-snapshot-aarch64.sha256sum] = "3618da916a0f92f241cf1d67d04bb578 SRC_URI[rustc-snapshot-aarch64.sha256sum] = "f26811e48d03c56c125de03d389e1ae7c6df36990953c1670c6a5676bc12d4cb" SRC_URI[cargo-snapshot-aarch64.sha256sum] = "6d11cd94618d80cda273eeeae7285980445f61a49ebacc616777b482a41cbf3f" +SRC_URI[rust-std-snapshot-powerpc64le.sha256sum] = "fc07eb3e9f3d227428cc5b53ca868e3de375bc198ce4dce7b87a9246e6fec81a" +SRC_URI[rustc-snapshot-powerpc64le.sha256sum] = "f43cb99109c3438c77c7079cdce4673df3320e310158e0b4d949c1babc4300fc" +SRC_URI[cargo-snapshot-powerpc64le.sha256sum] = "599cf1b5a8cdbf76d591621bc9222aefa60e2f5fd378ae71c4dcf4514c47122e" + SRC_URI += " \ https://static.rust-lang.org/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ https://static.rust-lang.org/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \ --2.32.0