]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
rust-common: Simplify libc handling
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 5 Aug 2022 12:34:42 +0000 (13:34 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 8 Aug 2022 14:41:36 +0000 (15:41 +0100)
The current libc handling code is simply wrong in many cases. Simplify it
to a check of the triplet for musl handling which is much simpler and less
error prone when handling things like nativesdk targets.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/rust-common.bbclass

index 7c432ed131bd696da369e3a92ab37f8c099c28be..516b258c15e7f30c587a939e004fbe6ded7fbf47 100644 (file)
@@ -13,27 +13,6 @@ RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
 RUSTLIB_DEP ?= "libstd-rs"
 RUST_PANIC_STRATEGY ?= "unwind"
 
-# 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-crosssdk = "glibc"
-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
-
 def target_is_armv7(d):
     '''Determine if target is armv7'''
     # TUNE_FEATURES may include arm* even if the target is not arm
@@ -73,26 +52,18 @@ def rust_base_triple(d, thing):
     if thing == "BUILD" and bpn in ["rust"]:
         return arch + "-unknown-linux-gnu"
 
-    # All the Yocto targets are Linux and are 'unknown'
-    vendor = "-unknown"
-    os = d.getVar('{}_OS'.format(thing))
-    libc = determine_libc(d, thing)
-
-    # Prefix with a dash and convert glibc -> gnu
-    if libc == "glibc":
-        libc = "-gnu"
-    elif libc == "musl":
-        libc = "-musl"
-
-    # Don't double up musl (only appears to be the case on aarch64)
-    if os == "linux-musl":
-        if libc != "-musl":
-            bb.fatal("{}_OS was '{}' but TCLIBC was not 'musl'".format(thing, os))
-        os = "linux"
+    vendor = d.getVar('{}_VENDOR'.format(thing))
 
+    # Default to glibc
+    libc = "-gnu"
+    os = d.getVar('{}_OS'.format(thing))
     # This catches ARM targets and appends the necessary hard float bits
     if os == "linux-gnueabi" or os == "linux-musleabi":
         libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d)
+    elif "musl" in os:
+        libc = "-musl"
+        os = "linux"
+
     return arch + vendor + '-' + os + libc