mirror of
https://git.yoctoproject.org/poky
synced 2026-02-20 08:29:42 +01:00
rust: Do not use default compiler flags defined in CC crate
Rust crates build dependecy C libraries using "CC" crate. This crate adds some default compiler parameters depending on target arch. For some targets these parameters conflict with the parameters defined by OE. Warnings/errors like this can be seen in the case: cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror] Lets use only the OE parameters by exporting CRATE_CC_NO_DEFAULTS. https://github.com/rust-lang/cc-rs#external-configuration-via-environment-variables This patch fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=14947 (From OE-Core rev: 94939f608c6984e3a92999a384a03a35c2b34ed6) Signed-off-by: Anton Antonov <Anton.Antonov@arm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0c07089bdf7e0d7d8f37552db0bcd75f860979d9) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
d2b253072b
commit
76142331c4
@@ -94,7 +94,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 +125,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:
|
||||
@@ -154,22 +164,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}"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -401,3 +401,19 @@ python do_rust_gen_targets () {
|
||||
addtask rust_gen_targets after do_patch before do_compile
|
||||
do_rust_gen_targets[dirs] += "${RUST_TARGETS_DIR}"
|
||||
|
||||
# For building target C dependecies use only compiler parameters defined in OE
|
||||
# and ignore the CC crate defaults which conflicts with OE ones in some cases.
|
||||
# https://github.com/rust-lang/cc-rs#external-configuration-via-environment-variables
|
||||
# Some CC crate compiler flags are still required.
|
||||
# We apply them conditionally in rust wrappers.
|
||||
|
||||
CRATE_CC_FLAGS:class-native = ""
|
||||
CRATE_CC_FLAGS:class-nativesdk = ""
|
||||
CRATE_CC_FLAGS:class-target = " -ffunction-sections -fdata-sections -fPIC"
|
||||
|
||||
do_compile:prepend:class-target() {
|
||||
export CRATE_CC_NO_DEFAULTS=1
|
||||
}
|
||||
do_install:prepend:class-target() {
|
||||
export CRATE_CC_NO_DEFAULTS=1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user