diff mbox series

rust-cross-canadian: set CC_<triple> for nativesdk

Message ID 20250114082128.903105-1-sean@geanix.com
State Accepted, archived
Commit 3c8fedd6e5a3251b7a7a73cc92b153d8e68cb8e5
Headers show
Series rust-cross-canadian: set CC_<triple> for nativesdk | expand

Commit Message

Sean Nyekjaer Jan. 14, 2025, 8:21 a.m. UTC
This fixes build errors when building rust bindings for C dependencies
for the sdk host.
This will allow us to build and run rust programs on the sdk host.

Before:
% cargo build --target x86_64-oesdk-linux-gnu -vv
[...]
   Compiling zstd-sys v2.0.13+zstd.1.5.6 (zstd-rs/zstd-safe/zstd-sys)
[zstd-sys 2.0.13+zstd.1.5.6] CC_x86_64-oesdk-linux-gnu = None
[zstd-sys 2.0.13+zstd.1.5.6] CC = Some(arm-oe-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/usr/local/sdk/sysroots/cortexa7t2hf-neon-oe-linux-gnueabi)
[zstd-sys 2.0.13+zstd.1.5.6] cargo:warning=ToolExecError: Command LC_ALL="C" "arm-oe-linux-gnueabi-gcc" "-mthumb" "-mfpu=neon" "-mfloat-abi=hard" "-mcpu=cortex-a7" "-D_TIME_BITS=64" "-D_FILE_OFFSET_BITS=64" "--sysroot=/usr/local/cc-sdk/sysroots/cortexa7t2hf-neon-oe-linux-gnueabi" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-I" "zstd/lib/legacy" "-O2" "-pipe" "-g" "-feliminate-unused-debug-types" "-flto" "-ffat-lto-objects" "-fuse-linker-plugin" "-fvisibility=hidden" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZDICTLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-DZSTD_LEGACY_SUPPORT=1" "-o" "zstd-rs/target/x86_64-oesdk-linux-gnu/debug/build/zstd-sys-b2560022e172eec3/out/44ff4c55aa9e5133-debug.o" "-c" "zstd/lib/common/debug.c" with args arm-oe-linux-gnueabi-gcc did not execute successfully (status code exit status: 1).cargo:warning=arm-oe-linux-gnueabi-gcc: error: unrecognized command-line option '-m64'

After:
% cargo build --target x86_64-oesdk-linux-gnu -vv
[...]
   Compiling zstd-sys v2.0.13+zstd.1.5.6 (zstd-rs/zstd-safe/zstd-sys)
[zstd-sys 2.0.13+zstd.1.5.6] CC_x86_64_oesdk_linux_gnu = Some(x86_64-oesdk-linux-gcc)
[...]
   Compiling zstd v0.13.2 (zstd-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 14.67s

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
 meta/recipes-devtools/rust/rust-cross-canadian.inc | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ross Burton Jan. 22, 2025, 1:37 p.m. UTC | #1
Hi Sean,

> On 14 Jan 2025, at 08:21, Sean Nyekjaer via lists.openembedded.org <sean=geanix.com@lists.openembedded.org> wrote:
> 
> This fixes build errors when building rust bindings for C dependencies
> for the sdk host.
> This will allow us to build and run rust programs on the sdk host.

Can you also add a test case to exercise this, to ensure it doesn’t regress in the future?  meta/lib/oeqa/sdk/cases/rust.py has some minimal testing already so adding more there would be great.

> --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
> +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
> @@ -58,11 +58,13 @@ do_install () {
> 
>     RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
>     RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
> +    RUST_HOST_CC=`echo ${RUST_HOST_SYS} | sed 's/-/_/g'`
>     SDKLOADER=${@bb.utils.contains('SDK_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'i686', 'ld-linux.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'aarch64', 'ld-linux-aarch64.so.1', '', d)}${@bb.utils.contains('SDK_ARCH', 'ppc64le', 'ld64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'riscv64', 'ld-linux-riscv64-lp64d.so.1', '', d)}
> 
>     cat <<- EOF > "${RUST_ENV_SETUP_SH}"
> export CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
> export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
> + export CC_$RUST_HOST_CC="${CCACHE}${HOST_PREFIX}gcc"
> export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib”
> EOF

There’s another series on the list that rewrites this (https://lore.kernel.org/openembedded-core/20250116134833.1838212-1-Harish.Sadineni@windriver.com/) and moves some assignments to an environment file in rust.bb.  I suspect the same needs to happen here, so can you rebase on top of that patch (or wait for that to be merged and rebase).

Thanks,
Ross
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc
index c34b839d159..c334bc8890f 100644
--- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
@@ -58,11 +58,13 @@  do_install () {
 
     RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
     RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
+    RUST_HOST_CC=`echo ${RUST_HOST_SYS} | sed 's/-/_/g'`
     SDKLOADER=${@bb.utils.contains('SDK_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'i686', 'ld-linux.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'aarch64', 'ld-linux-aarch64.so.1', '', d)}${@bb.utils.contains('SDK_ARCH', 'ppc64le', 'ld64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'riscv64', 'ld-linux-riscv64-lp64d.so.1', '', d)}
 
     cat <<- EOF > "${RUST_ENV_SETUP_SH}"
 	export CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
 	export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
+	export CC_$RUST_HOST_CC="${CCACHE}${HOST_PREFIX}gcc"
 	export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
 	EOF