From 8e6c6271fcc82e4241e9b6c8d9cf10073686ef1d Mon Sep 17 00:00:00 2001 From: Johan Anderholm Date: Thu, 5 Jul 2018 15:59:19 +0200 Subject: [PATCH] Handle env and llvm-target for musl Further changes needed for musl to work. env needs to be set to "musl" for unwinding work properly. Also the llvm target should end with "-musl" and not "-gnu". --- classes/rust-common.bbclass | 23 +++++++++++++++++++++-- recipes-devtools/rust/rust.inc | 25 ++++++++++++++----------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/classes/rust-common.bbclass b/classes/rust-common.bbclass index ca3a136..63b340b 100644 --- a/classes/rust-common.bbclass +++ b/classes/rust-common.bbclass @@ -11,8 +11,27 @@ RUSTLIB_DEP ?= "libstd-rs" RUST_TARGET_PATH = "${STAGING_LIBDIR_NATIVE}/rustlib" RUST_PANIC_STRATEGY ?= "unwind" -# Responsible for taking Yocto triples and converting it to Rust triples +# Native builds are not effected by TCLIBC. Without this, rust-native +# thinks it's "target" (i.e. x86_64-linux) is a musl target. +RUST_LIBC = "${TCLIBC}" +RUST_LIBC_class-native = "glibc" +def determine_libc(d, thing): + '''Determine which libc something should target''' + + # BUILD is never musl, TARGET may be musl or glibc, + # HOST could be musl, but only if a compiler is built to be run on + # target in which case HOST_SYS != BUILD_SYS. + if thing == 'TARGET': + libc = d.getVar('RUST_LIBC') + elif thing == 'BUILD' and (d.getVar('HOST_SYS') != d.getVar('BUILD_SYS')): + libc = d.getVar('RUST_LIBC') + else: + libc = d.getVar('RUST_LIBC_class-native') + + return libc + +# Responsible for taking Yocto triples and converting it to Rust triples def rust_base_triple(d, thing): ''' Mangle bitbake's *_SYS into something that rust might support (see @@ -25,7 +44,7 @@ def rust_base_triple(d, thing): # All the Yocto targets are Linux and are 'unknown' vendor = "-unknown" os = d.getVar('{}_OS'.format(thing)) - libc = d.getVar('TCLIBC') + libc = determine_libc(d, thing) # Prefix with a dash and convert glibc -> gnu if libc == "glibc": diff --git a/recipes-devtools/rust/rust.inc b/recipes-devtools/rust/rust.inc index 0d6d733..d4981a9 100644 --- a/recipes-devtools/rust/rust.inc +++ b/recipes-devtools/rust/rust.inc @@ -142,39 +142,39 @@ TARGET_C_INT_WIDTH[arm] = "32" MAX_ATOMIC_WIDTH[arm] = "64" FEATURES[arm] = "+v6,+vfp2" -## aarch64-unknown-linux-gnu +## aarch64-unknown-linux-{gnu, musl} DATA_LAYOUT[aarch64] = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -LLVM_TARGET[aarch64] = "aarch64-unknown-linux-gnu" +LLVM_TARGET[aarch64] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[aarch64] = "little" TARGET_POINTER_WIDTH[aarch64] = "64" TARGET_C_INT_WIDTH[aarch64] = "32" MAX_ATOMIC_WIDTH[aarch64] = "128" -## x86_64-unknown-linux-gnu +## x86_64-unknown-linux-{gnu, musl} DATA_LAYOUT[x86_64] = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" -LLVM_TARGET[x86_64] = "x86_64-unknown-linux-gnu" +LLVM_TARGET[x86_64] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[x86_64] = "little" TARGET_POINTER_WIDTH[x86_64] = "64" TARGET_C_INT_WIDTH[x86_64] = "32" MAX_ATOMIC_WIDTH[x86_64] = "64" -## i686-unknown-linux-gnu +## i686-unknown-linux-{gnu, musl} DATA_LAYOUT[i686] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" -LLVM_TARGET[i686] = "i686-unknown-linux-gnu" +LLVM_TARGET[i686] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[i686] = "little" TARGET_POINTER_WIDTH[i686] = "32" TARGET_C_INT_WIDTH[i686] = "32" MAX_ATOMIC_WIDTH[i686] = "64" -## XXX: a bit of a hack so qemux86 builds, clone of i686-unknown-linux-gnu above +## XXX: a bit of a hack so qemux86 builds, clone of i686-unknown-linux-{gnu, musl} above DATA_LAYOUT[i586] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" -LLVM_TARGET[i586] = "i586-unknown-linux-gnu" +LLVM_TARGET[i586] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[i586] = "little" TARGET_POINTER_WIDTH[i586] = "32" TARGET_C_INT_WIDTH[i586] = "32" MAX_ATOMIC_WIDTH[i586] = "64" -## mips-unknown-linux-gnu +## mips-unknown-linux-{gnu, musl} DATA_LAYOUT[mips] = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" LLVM_TARGET[mips] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[mips] = "big" @@ -182,7 +182,7 @@ TARGET_POINTER_WIDTH[mips] = "32" TARGET_C_INT_WIDTH[mips] = "32" MAX_ATOMIC_WIDTH[mips] = "32" -## mipsel-unknown-linux-gnu +## mipsel-unknown-linux-{gnu, musl} DATA_LAYOUT[mipsel] = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" LLVM_TARGET[mipsel] = "${RUST_TARGET_SYS}" TARGET_ENDIAN[mipsel] = "little" @@ -267,7 +267,10 @@ def rust_gen_target(d, thing, wd): tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch) tspec['arch'] = arch_to_rust_target_arch(arch) tspec['os'] = "linux" - tspec['env'] = "gnu" + if "musl" in tspec['llvm-target']: + tspec['env'] = "musl" + else: + tspec['env'] = "gnu" tspec['vendor'] = "unknown" tspec['target-family'] = "unix" tspec['linker'] = "{}{}gcc".format(d.getVar('CCACHE'), prefix)