summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorAnton Antonov <anton.antonov@arm.com>2023-01-03 14:36:39 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-26 23:39:06 +0000
commit76142331c4d83d6fa57fa5444a5081edf2f37380 (patch)
treeec8f2d70c7cd93de3e491324c05362ef326c38f4 /meta
parentd2b253072bc29286de687f0626b76297b66d8eae (diff)
downloadpoky-76142331c4d83d6fa57fa5444a5081edf2f37380.tar.gz
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>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes-recipe/rust-common.bbclass28
-rw-r--r--meta/classes-recipe/rust-target-config.bbclass16
2 files changed, 35 insertions, 9 deletions
diff --git a/meta/classes-recipe/rust-common.bbclass b/meta/classes-recipe/rust-common.bbclass
index 93bf6c8be6..5e70007377 100644
--- a/meta/classes-recipe/rust-common.bbclass
+++ b/meta/classes-recipe/rust-common.bbclass
@@ -94,7 +94,7 @@ RUST_BUILD_ARCH = "${@oe.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}"
94# Rust additionally will use two additional cases: 94# Rust additionally will use two additional cases:
95# - undecorated (e.g. CC) - equivalent to TARGET 95# - undecorated (e.g. CC) - equivalent to TARGET
96# - triple suffix (e.g. CC:x86_64_unknown_linux_gnu) - both 96# - triple suffix (e.g. CC:x86_64_unknown_linux_gnu) - both
97# see: https://github.com/alexcrichton/gcc-rs 97# see: https://github.com/rust-lang/cc-rs
98# The way that Rust's internal triples and Yocto triples are mapped together 98# The way that Rust's internal triples and Yocto triples are mapped together
99# its likely best to not use the triple suffix due to potential confusion. 99# its likely best to not use the triple suffix due to potential confusion.
100 100
@@ -125,12 +125,22 @@ create_wrapper_rust () {
125 shift 125 shift
126 extras="$1" 126 extras="$1"
127 shift 127 shift
128 crate_cc_extras="$1"
129 shift
128 130
129 cat <<- EOF > "${file}" 131 cat <<- EOF > "${file}"
130 #!/usr/bin/env python3 132 #!/usr/bin/env python3
131 import os, sys 133 import os, sys
132 orig_binary = "$@" 134 orig_binary = "$@"
133 extras = "${extras}" 135 extras = "${extras}"
136
137 # Apply a required subset of CC crate compiler flags
138 # when we build a target recipe for a non-bare-metal target.
139 # https://github.com/rust-lang/cc-rs/blob/main/src/lib.rs#L1614
140 if "CRATE_CC_NO_DEFAULTS" in os.environ.keys() and \
141 "TARGET" in os.environ.keys() and not "-none-" in os.environ["TARGET"]:
142 orig_binary += "${crate_cc_extras}"
143
134 binary = orig_binary.split()[0] 144 binary = orig_binary.split()[0]
135 args = orig_binary.split() + sys.argv[1:] 145 args = orig_binary.split() + sys.argv[1:]
136 if extras: 146 if extras:
@@ -154,22 +164,22 @@ do_rust_create_wrappers () {
154 mkdir -p "${WRAPPER_DIR}" 164 mkdir -p "${WRAPPER_DIR}"
155 165
156 # Yocto Build / Rust Host C compiler 166 # Yocto Build / Rust Host C compiler
157 create_wrapper_rust "${RUST_BUILD_CC}" "" "${BUILD_CC}" 167 create_wrapper_rust "${RUST_BUILD_CC}" "" "${CRATE_CC_FLAGS}" "${BUILD_CC}"
158 # Yocto Build / Rust Host C++ compiler 168 # Yocto Build / Rust Host C++ compiler
159 create_wrapper_rust "${RUST_BUILD_CXX}" "" "${BUILD_CXX}" 169 create_wrapper_rust "${RUST_BUILD_CXX}" "" "${CRATE_CC_FLAGS}" "${BUILD_CXX}"
160 # Yocto Build / Rust Host linker 170 # Yocto Build / Rust Host linker
161 create_wrapper_rust "${RUST_BUILD_CCLD}" "" "${BUILD_CCLD}" "${BUILD_LDFLAGS}" 171 create_wrapper_rust "${RUST_BUILD_CCLD}" "" "" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
162 # Yocto Build / Rust Host archiver 172 # Yocto Build / Rust Host archiver
163 create_wrapper_rust "${RUST_BUILD_AR}" "" "${BUILD_AR}" 173 create_wrapper_rust "${RUST_BUILD_AR}" "" "" "${BUILD_AR}"
164 174
165 # Yocto Target / Rust Target C compiler 175 # Yocto Target / Rust Target C compiler
166 create_wrapper_rust "${RUST_TARGET_CC}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}" 176 create_wrapper_rust "${RUST_TARGET_CC}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}"
167 # Yocto Target / Rust Target C++ compiler 177 # Yocto Target / Rust Target C++ compiler
168 create_wrapper_rust "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CXX}" "${CXXFLAGS}" 178 create_wrapper_rust "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CXX}" "${CXXFLAGS}"
169 # Yocto Target / Rust Target linker 179 # Yocto Target / Rust Target linker
170 create_wrapper_rust "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_EXTRALD}" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}" 180 create_wrapper_rust "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_EXTRALD}" "" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
171 # Yocto Target / Rust Target archiver 181 # Yocto Target / Rust Target archiver
172 create_wrapper_rust "${RUST_TARGET_AR}" "" "${WRAPPER_TARGET_AR}" 182 create_wrapper_rust "${RUST_TARGET_AR}" "" "" "${WRAPPER_TARGET_AR}"
173 183
174} 184}
175 185
diff --git a/meta/classes-recipe/rust-target-config.bbclass b/meta/classes-recipe/rust-target-config.bbclass
index 2710b4325d..9158b1918e 100644
--- a/meta/classes-recipe/rust-target-config.bbclass
+++ b/meta/classes-recipe/rust-target-config.bbclass
@@ -401,3 +401,19 @@ python do_rust_gen_targets () {
401addtask rust_gen_targets after do_patch before do_compile 401addtask rust_gen_targets after do_patch before do_compile
402do_rust_gen_targets[dirs] += "${RUST_TARGETS_DIR}" 402do_rust_gen_targets[dirs] += "${RUST_TARGETS_DIR}"
403 403
404# For building target C dependecies use only compiler parameters defined in OE
405# and ignore the CC crate defaults which conflicts with OE ones in some cases.
406# https://github.com/rust-lang/cc-rs#external-configuration-via-environment-variables
407# Some CC crate compiler flags are still required.
408# We apply them conditionally in rust wrappers.
409
410CRATE_CC_FLAGS:class-native = ""
411CRATE_CC_FLAGS:class-nativesdk = ""
412CRATE_CC_FLAGS:class-target = " -ffunction-sections -fdata-sections -fPIC"
413
414do_compile:prepend:class-target() {
415 export CRATE_CC_NO_DEFAULTS=1
416}
417do_install:prepend:class-target() {
418 export CRATE_CC_NO_DEFAULTS=1
419}