Rust project development for target (missing std)
Hi!
I’m building a custom image for a controller I’d like to use in my irrigation system. I managed to create a custom distro and successfully built a base image.
Now I’d like to use the standard SDK to develop a Rust app for the controller. I hit a roadblock unfortunately. I can’t figure out how to include the Rust Standard Library for the target device in the SDK. I saw you were involved in the development of the rust-cross-canadian recipe, so that’s why I’m reaching out to you.
Here’s the error I’m getting:
cargo build --target armv7-zeus-linux-gnueabihf
Compiling hello-rust v0.1.0 (/home/tamas/hello-rust)
error[E0463]: can't find crate for std
|
= note: the armv7-zeus-linux-gnueabihf target may not be installed
= help: consider downloading the target with rustup target add armv7-zeus-linux-gnueabihf
error: cannot find macro println in this scope
--> src/ main.rs ( http://main.rs/ ) :2:5
|
2 | println!("Hello, world!");
| ^^^^^^^
error: requires sized lang_item
For more information about this error, try rustc --explain E0463.
error: could not compile hello-rust (bin "hello-rust") due to 3 previous errors
And indeed libstd for the target isn’t found anywhere inside the SDK’s sysroot. Building the app for the host target x86_64-pokysdk-linux-gnu works just fine, since there’s a libstd in the sysroot for it. Here’s the toolchain config from my image’s recipe as well:
RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}" TOOLCHAIN_HOST_TASK:append = " \
${@all_multilib_tune_values(d, 'RUST')} \
nativesdk-libstd-rs \
nativesdk-binutils \
nativesdk-gcc \
nativesdk-glibc-dev \
nativesdk-libgcc-dev \
nativesdk-rust \
nativesdk-cargo \
nativesdk-rust-tools-clippy \
nativesdk-rust-tools-rustfmt \
“
I’m on the latest version of Yocto Scarthgap.
Additionally here are my env vars after running the SDK environment setup script, at least the ones I found important:
SHELL=/bin/bash
OECORE_TUNE_CCARGS= -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8
BB_ENV_PASSTHROUGH_ADDITIONS= SSL_CERT_DIR SSL_CERT_FILE
OECORE_SDK_VERSION=0.1.0
PKG_CONFIG_PATH=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi/usr/lib/pkgconfig:/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi/usr/share/pkgconfig
GDB=arm-zeus-linux-gnueabi-gdb
SDKTARGETSYSROOT=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
OECORE_BASELIB=lib
CPP=arm-zeus-linux-gnueabi-gcc -E -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
TARGET_PREFIX=arm-zeus-linux-gnueabi-
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=
PWD=/home/tamas/hello-rust
OECORE_TARGET_OS=linux-gnueabi
CXX=arm-zeus-linux-gnueabi-g++ -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types
CARGO_TARGET_X86_64_POKYSDK_LINUX_GNU_RUNNER=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2
OECORE_NATIVE_SYSROOT=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux
LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now
HOME=/home/tamas
LANG=C.UTF-8
OPENSSL_CONF=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/lib/ssl-3/openssl.cnf
SSL_CERT_DIR=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/lib/ssl-3/certs
KCFLAGS=--sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
OECORE_TARGET_SYSROOT=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
CARGO_HTTP_CAINFO=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt
CPPFLAGS=
OPENSSL_MODULES=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/lib/ossl-modules/
LD=arm-zeus-linux-gnueabi-ld --sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
READELF=arm-zeus-linux-gnueabi-readelf
CARGO_HTTP_MULTIPLEXING=false
AR=arm-zeus-linux-gnueabi-ar
ARCH=arm
AS=arm-zeus-linux-gnueabi-as
NM=arm-zeus-linux-gnueabi-nm
OECORE_TARGET_ARCH=arm
SSL_CERT_FILE=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/lib/ssl-3/certs/ca-certificates.crt
OECORE_DISTRO_VERSION=0.1.0
PKG_CONFIG_SYSROOT_DIR=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
OECORE_ACLOCAL_OPTS=-I /home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/share/aclocal
OBJCOPY=arm-zeus-linux-gnueabi-objcopy
STRIP=arm-zeus-linux-gnueabi-strip
OBJDUMP=arm-zeus-linux-gnueabi-objdumpCONFIG_SITE=/home/tamas/sdk/zeus/0.1.0/site-config-cortexa8t2hf-neon-zeus-linux-gnueabi PATH=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/bin:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/sbin:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/bin:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/sbin:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/../x86_64-pokysdk-linux/bin:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-zeus-linux-gnueabi:/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-zeus-linux-musl:/home/tamas/.local/bin:/home/tamas/.nvm/versions/node/v20.17.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/snap/bin:/home/tamas/.local/bin:/usr/local/bin:/usr/local/go/bin:/home/tamas/.local/bin:/usr/local/bin CC=arm-zeus-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types
CROSS_COMPILE=arm-zeus-linux-gnueabi-
CONFIGURE_FLAGS=--target=arm-zeus-linux-gnueabi --host=arm-zeus-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
CARGO_TARGET_ARMV7_ZEUS_LINUX_GNUEABIHF_RUSTFLAGS=--sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi/usr -C link-arg=--sysroot=/home/tamas/sdk/zeus/0.1.0/sysroots/cortexa8t2hf-neon-zeus-linux-gnueabi
RANLIB=arm-zeus-linux-gnueabi-ranlib
RUST_TARGET_PATH=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/lib/arm-zeus-linux-gnueabi/rustlib
OLDPWD=/home/tamas
CMAKE_TOOLCHAIN_FILE=/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
I hope this is enough context. Maybe I’m just missing another package or I have to set some environment variable, but I couldn’t figure it out.
Kind regards,
Tamás
Quoted 45 lines · Tamás Soós via lists.yoctoproject.org
Hi!
I’m building a custom image for a controller I’d like to use in my irrigation system. I managed to create a custom distro and successfully built a base image.
Now I’d like to use the standard SDK to develop a Rust app for the controller. I hit a roadblock unfortunately. I can’t figure out how to include the Rust Standard Library for the target device in the SDK.
I saw you were involved in the development of the rust-cross-canadian recipe, so that’s why I’m reaching out to you.
Here’s the error I’m getting:cargo build --target armv7-zeus-linux-gnueabihf
Compiling hello-rust v0.1.0 (/home/tamas/hello-rust) error[E0463]: can't find crate forstd
|
= note: thearmv7-zeus-linux-gnueabihftarget may not be installed
= help: consider downloading the target withrustup target add armv7-zeus-linux-gnueabihf
error: cannot find macroprintlnin this scope
-->src/main.rs:2:5
|
2 | println!("Hello, world!");
| ^^^^^^^
error: requiressizedlang_item
For more information about this error, tryrustc --explain E0463.
error: could not compilehello-rust(bin "hello-rust") due to 3 previous errors
And indeed libstd for the target isn’t found anywhere inside the SDK’s sysroot. Building the app for the host target x86_64-pokysdk- linux-gnu works just fine, since there’s a libstd in the sysroot for it.
Here’s the toolchain config from my image’s recipe as well:
Quoted 15 lines
RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}" TOOLCHAIN_HOST_TASK:append = " \
${@all_multilib_tune_values(d, 'RUST')} \
nativesdk-libstd-rs \
nativesdk-binutils \
nativesdk-gcc \
nativesdk-glibc-dev \
nativesdk-libgcc-dev \
nativesdk-rust \
nativesdk-cargo \
nativesdk-rust-tools-clippy \
nativesdk-rust-tools-rustfmt \
“
I’m on the latest version of Yocto Scarthgap.
Did you try adding libstd-rs to TOOLCHAIN_TARGET_TASK?
Cheers,
Richard
I think I misinterpreted at first what TOOLCHAIN_TARGET_TASK is supposed to mean. Now it makes sense, of course I need it there as
libstd-rs would be compiled for the target, but used on the SDK host. I actually had to remove nativesdk-libst-rs from TOOLCHAIN_HOST_TASK.
It created two extra libstd.so <http://libstd.so/> files for the x86_64-pokysdk-linux-gnu target, but there was already a libstd.rlib in there. Not sure which package creates the rlib. This caused rustc to panic. I also added rust to SDK_TOOLCHAIN_LANGS. I’m not sure what this does exactly.
The end of my image file now looks like this:
RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}" SDK_TOOLCHAIN_LANGS += 'rust'
TOOLCHAIN_HOST_TASK:append = " \
${@all_multilib_tune_values(d, 'RUST')} \
nativesdk-binutils \
nativesdk-gcc \
nativesdk-glibc-dev \
nativesdk-libgcc-dev \
nativesdk-rust \
nativesdk-cargo \
nativesdk-rust-tools-clippy \
nativesdk-rust-tools-rustfmt \"
TOOLCHAIN_TARGET_TASK:append = " \
libstd-rs \"
The build for the SDK host is working:
tamas@zeus-ws01:~/hello-rust$ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
tamas@zeus-ws01:~/hello-rust$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so <http://ld-linux-x86-64.so/>.2 target/debug/hello-rust`
Hello, world!The target also builds, but to actually run it takes a bit more persuasion.
tamas@zeus-ws01:~/hello-rust$ cargo build --target armv7-zeus-linux-gnueabihf
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
tamas@zeus-ws01:~/hello-rust$ file target/armv7-zeus-linux-gnueabihf/debug/hello-rust
target/armv7-zeus-linux-gnueabihf/debug/hello-rust: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so <http://ld-linux.so/>.3, BuildID[sha1]=847fa94846fd717fe3126f4d3423357eccd683cd, for GNU/Linux 5.15.0, with debug_info, not strippedAs you can see it’s linked with /lib/ld-linux.so <http://ld-linux.so/>.3, but only /lib/ld-linux-armhf.so <http://ld-linux-armhf.so/>.3 is present on the board. What’s the best way to fix this? Using patchelf works, but it’s kind of annoying. Maybe adding a symlink during build is the easiest. I don’t know how to modify I used patchelf this time which lead to the second problem. libgcc_s.so <http://libgcc_s.so/>.1 was missing. This was expected, and I just had to add libgcc to IMAGE_INSTALL.
Finally this got it working on the target as well:
phyboard-regor-am335x-1:~$ ./hello-rust Hello, world!
Thank you so much!
Now I just need to figure out the best way to deal with the interpreter.
Quoted 69 lines · Richard Purdie
Quoted 57 lines · Tamás Soós via lists.yoctoproject.org
Hi!
I’m building a custom image for a controller I’d like to use in my irrigation system. I managed to create a custom distro and successfully built a base image.
Now I’d like to use the standard SDK to develop a Rust app for the controller. I hit a roadblock unfortunately. I can’t figure out how to include the Rust Standard Library for the target device in the SDK.
I saw you were involved in the development of the rust-cross-canadian recipe, so that’s why I’m reaching out to you.Here’s the error I’m getting:
cargo build --target armv7-zeus-linux-gnueabihf
Compiling hello-rust v0.1.0 (/home/tamas/hello-rust)
error[E0463]: can't find crate forstd
|
= note: thearmv7-zeus-linux-gnueabihftarget may not be
installed
= help: consider downloading the target with `rustup target add
armv7-zeus-linux-gnueabihf`error: cannot find macro
printlnin this scope
-->src/main.rs:2:5| 2 | println!("Hello, world!"); | ^^^^^^^error: requires
sizedlang_itemFor more information about this error, try
rustc --explain E0463.
error: could not compilehello-rust(bin "hello-rust") due to 3 previous errorsAnd indeed libstd for the target isn’t found anywhere inside the SDK’s sysroot. Building the app for the host target x86_64-pokysdk- linux-gnu works just fine, since there’s a libstd in the sysroot for it.
Here’s the toolchain config from my image’s recipe as well:RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"
TOOLCHAIN_HOST_TASK:append = " \ ${@all_multilib_tune_values(d, 'RUST')} \ nativesdk-libstd-rs \ nativesdk-binutils \ nativesdk-gcc \ nativesdk-glibc-dev \ nativesdk-libgcc-dev \ nativesdk-rust \ nativesdk-cargo \ nativesdk-rust-tools-clippy \ nativesdk-rust-tools-rustfmt \Quoted 3 lines
“
I’m on the latest version of Yocto Scarthgap.
Did you try adding libstd-rs to
TOOLCHAIN_TARGET_TASK?Cheers,
Richard
I decided to edit the linker flags passed to rustc. I created a bbappend file for rust-cross-canadian that looks like this:
do_install:append() {
sed -ri 's:^(export CARGO_TARGET_'"${RUST_TARGET_TRIPLE}"'_RUSTFLAGS)="(.*)":\1="\2 -C link-arg=-Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3":' ${RUST_ENV_SETUP_SH}
}Quoted 122 lines · Tamás Soós
I think I misinterpreted at first what
TOOLCHAIN_TARGET_TASKis supposed to mean. Now it makes sense, of course I need it there as
libstd-rs would be compiled for the target, but used on the SDK host. I actually had to remove nativesdk-libst-rs fromTOOLCHAIN_HOST_TASK.
It created two extra libstd.so <http://libstd.so/> files for the x86_64-pokysdk-linux-gnu target, but there was already a libstd.rlib in there. Not sure which package creates the rlib. This caused rustc to panic. I also added rust toSDK_TOOLCHAIN_LANGS. I’m not sure what this does exactly.The end of my image file now looks like this:
RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"SDK_TOOLCHAIN_LANGS+= 'rust'TOOLCHAIN_HOST_TASK:append = " \ ${@all_multilib_tune_values(d, 'RUST')} \ nativesdk-binutils \ nativesdk-gcc \ nativesdk-glibc-dev \ nativesdk-libgcc-dev \ nativesdk-rust \ nativesdk-cargo \ nativesdk-rust-tools-clippy \ nativesdk-rust-tools-rustfmt \"
TOOLCHAIN_TARGET_TASK:append = " \ libstd-rs \"
The build for the SDK host is working:
tamas@zeus-ws01:~/hello-rust$ cargo build Finished dev [unoptimized + debuginfo] target(s) in 0.01s tamas@zeus-ws01:~/hello-rust$ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.01s Running `/home/tamas/sdk/zeus/0.1.0/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so <http://ld-linux-x86-64.so/>.2 target/debug/hello-rust` Hello, world!The target also builds, but to actually run it takes a bit more persuasion.
tamas@zeus-ws01:~/hello-rust$ cargo build --target armv7-zeus-linux-gnueabihf Finished dev [unoptimized + debuginfo] target(s) in 0.00s tamas@zeus-ws01:~/hello-rust$ file target/armv7-zeus-linux-gnueabihf/debug/hello-rust target/armv7-zeus-linux-gnueabihf/debug/hello-rust: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so <http://ld-linux.so/>.3, BuildID[sha1]=847fa94846fd717fe3126f4d3423357eccd683cd, for GNU/Linux 5.15.0, with debug_info, not strippedAs you can see it’s linked with
/lib/ld-linux.so<http://ld-linux.so/>.3, but only/lib/ld-linux-armhf.so<http://ld-linux-armhf.so/>.3 is present on the board. What’s the best way to fix this? Using patchelf works, but it’s kind of annoying. Maybe adding a symlink during build is the easiest. I don’t know how to modify I used patchelf this time which lead to the second problem. libgcc_s.so <http://libgcc_s.so/>.1 was missing. This was expected, and I just had to add libgcc toIMAGE_INSTALL.Finally this got it working on the target as well:
phyboard-regor-am335x-1:~$ ./hello-rust Hello, world!Thank you so much!
Now I just need to figure out the best way to deal with the interpreter.
Quoted 69 lines · Richard Purdie
Quoted 57 lines · Tamás Soós via lists.yoctoproject.org
Hi!
I’m building a custom image for a controller I’d like to use in my irrigation system. I managed to create a custom distro and successfully built a base image.
Now I’d like to use the standard SDK to develop a Rust app for the controller. I hit a roadblock unfortunately. I can’t figure out how to include the Rust Standard Library for the target device in the SDK.
I saw you were involved in the development of the rust-cross-canadian recipe, so that’s why I’m reaching out to you.Here’s the error I’m getting:
cargo build --target armv7-zeus-linux-gnueabihf
Compiling hello-rust v0.1.0 (/home/tamas/hello-rust)
error[E0463]: can't find crate forstd
|
= note: thearmv7-zeus-linux-gnueabihftarget may not be
installed
= help: consider downloading the target with `rustup target add
armv7-zeus-linux-gnueabihf`error: cannot find macro
printlnin this scope
-->src/main.rs:2:5| 2 | println!("Hello, world!"); | ^^^^^^^error: requires
sizedlang_itemFor more information about this error, try
rustc --explain E0463.
error: could not compilehello-rust(bin "hello-rust") due to 3 previous errorsAnd indeed libstd for the target isn’t found anywhere inside the SDK’s sysroot. Building the app for the host target x86_64-pokysdk- linux-gnu works just fine, since there’s a libstd in the sysroot for it.
Here’s the toolchain config from my image’s recipe as well:RUST = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"
TOOLCHAIN_HOST_TASK:append = " \ ${@all_multilib_tune_values(d, 'RUST')} \ nativesdk-libstd-rs \ nativesdk-binutils \ nativesdk-gcc \ nativesdk-glibc-dev \ nativesdk-libgcc-dev \ nativesdk-rust \ nativesdk-cargo \ nativesdk-rust-tools-clippy \ nativesdk-rust-tools-rustfmt \Quoted 3 lines
“
I’m on the latest version of Yocto Scarthgap.
Did you try adding libstd-rs to
TOOLCHAIN_TARGET_TASK?Cheers,
Richard