summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/rust-common.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/rust-common.bbclass')
-rw-r--r--meta/classes-recipe/rust-common.bbclass55
1 files changed, 37 insertions, 18 deletions
diff --git a/meta/classes-recipe/rust-common.bbclass b/meta/classes-recipe/rust-common.bbclass
index 93bf6c8be6..6940093e59 100644
--- a/meta/classes-recipe/rust-common.bbclass
+++ b/meta/classes-recipe/rust-common.bbclass
@@ -14,10 +14,10 @@ FILES:${PN}-dev += "${rustlibdir}/*.rlib ${rustlibdir}/*.rmeta"
FILES:${PN}-dbg += "${rustlibdir}/.debug"
RUSTLIB = "-L ${STAGING_DIR_HOST}${rustlibdir}"
-RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
+RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=${TARGET_DBGSRC_DIR}"
RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
-RUSTLIB_DEP ?= "libstd-rs"
-RUST_PANIC_STRATEGY ?= "unwind"
+RUSTLIB_DEP ??= "libstd-rs"
+RUST_PANIC_STRATEGY ??= "unwind"
def target_is_armv7(d):
'''Determine if target is armv7'''
@@ -53,12 +53,9 @@ def rust_base_triple(d, thing):
else:
arch = oe.rust.arch_to_rust_arch(d.getVar('{}_ARCH'.format(thing)))
- # When bootstrapping rust-native, BUILD must be the same as upstream snapshot tarballs
- bpn = d.getVar('BPN')
- if thing == "BUILD" and bpn in ["rust"]:
- return arch + "-unknown-linux-gnu"
-
- vendor = d.getVar('{}_VENDOR'.format(thing))
+ # Substituting "unknown" when vendor is empty will match rust's standard
+ # targets when building native recipes (including rust-native itself)
+ vendor = d.getVar('{}_VENDOR'.format(thing)) or "-unknown"
# Default to glibc
libc = "-gnu"
@@ -66,9 +63,17 @@ def rust_base_triple(d, 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 os == "linux-gnux32" or os == "linux-muslx32":
+ libc = ""
elif "musl" in os:
libc = "-musl"
os = "linux"
+ elif "elf" in os:
+ libc = "-elf"
+ os = "none"
+ elif "eabi" in os:
+ libc = "-eabi"
+ os = "none"
return arch + vendor + '-' + os + libc
@@ -94,7 +99,7 @@ RUST_BUILD_ARCH = "${@oe.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}"
# Rust additionally will use two additional cases:
# - undecorated (e.g. CC) - equivalent to TARGET
# - triple suffix (e.g. CC:x86_64_unknown_linux_gnu) - both
-# see: https://github.com/alexcrichton/gcc-rs
+# see: https://github.com/rust-lang/cc-rs
# The way that Rust's internal triples and Yocto triples are mapped together
# its likely best to not use the triple suffix due to potential confusion.
@@ -125,12 +130,22 @@ create_wrapper_rust () {
shift
extras="$1"
shift
+ crate_cc_extras="$1"
+ shift
cat <<- EOF > "${file}"
#!/usr/bin/env python3
import os, sys
orig_binary = "$@"
extras = "${extras}"
+
+ # Apply a required subset of CC crate compiler flags
+ # when we build a target recipe for a non-bare-metal target.
+ # https://github.com/rust-lang/cc-rs/blob/main/src/lib.rs#L1614
+ if "CRATE_CC_NO_DEFAULTS" in os.environ.keys() and \
+ "TARGET" in os.environ.keys() and not "-none-" in os.environ["TARGET"]:
+ orig_binary += "${crate_cc_extras}"
+
binary = orig_binary.split()[0]
args = orig_binary.split() + sys.argv[1:]
if extras:
@@ -145,6 +160,10 @@ WRAPPER_TARGET_CXX = "${CXX}"
WRAPPER_TARGET_CCLD = "${CCLD}"
WRAPPER_TARGET_LDFLAGS = "${LDFLAGS}"
WRAPPER_TARGET_EXTRALD = ""
+# see recipes-devtools/gcc/gcc/0018-Add-ssp_nonshared-to-link-commandline-for-musl-targe.patch
+# we need to link with ssp_nonshared on musl to avoid "undefined reference to `__stack_chk_fail_local'"
+# when building MACHINE=qemux86 for musl
+WRAPPER_TARGET_EXTRALD:libc-musl = "-lssp_nonshared"
WRAPPER_TARGET_AR = "${AR}"
# compiler is used by gcc-rs
@@ -154,22 +173,22 @@ do_rust_create_wrappers () {
mkdir -p "${WRAPPER_DIR}"
# Yocto Build / Rust Host C compiler
- create_wrapper_rust "${RUST_BUILD_CC}" "" "${BUILD_CC}"
+ create_wrapper_rust "${RUST_BUILD_CC}" "" "${CRATE_CC_FLAGS}" "${BUILD_CC}"
# Yocto Build / Rust Host C++ compiler
- create_wrapper_rust "${RUST_BUILD_CXX}" "" "${BUILD_CXX}"
+ create_wrapper_rust "${RUST_BUILD_CXX}" "" "${CRATE_CC_FLAGS}" "${BUILD_CXX}"
# Yocto Build / Rust Host linker
- create_wrapper_rust "${RUST_BUILD_CCLD}" "" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
+ create_wrapper_rust "${RUST_BUILD_CCLD}" "" "" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
# Yocto Build / Rust Host archiver
- create_wrapper_rust "${RUST_BUILD_AR}" "" "${BUILD_AR}"
+ create_wrapper_rust "${RUST_BUILD_AR}" "" "" "${BUILD_AR}"
# Yocto Target / Rust Target C compiler
- create_wrapper_rust "${RUST_TARGET_CC}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}"
+ create_wrapper_rust "${RUST_TARGET_CC}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}"
# Yocto Target / Rust Target C++ compiler
- create_wrapper_rust "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CXX}" "${CXXFLAGS}"
+ create_wrapper_rust "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CXX}" "${CXXFLAGS}"
# Yocto Target / Rust Target linker
- create_wrapper_rust "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
+ create_wrapper_rust "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_EXTRALD}" "" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
# Yocto Target / Rust Target archiver
- create_wrapper_rust "${RUST_TARGET_AR}" "" "${WRAPPER_TARGET_AR}"
+ create_wrapper_rust "${RUST_TARGET_AR}" "" "" "${WRAPPER_TARGET_AR}"
}