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