Message ID | 20230928081035.604380-2-sean@geanix.com |
---|---|
State | New |
Headers | show |
Series | [RFC,1/2] rust-cross-canadian: set CARGO_TARGET_<triple>_RUSTFLAGS | expand |
This seems like a good change (being able to easily run items built with c/c++ tolchains in yocto SDKs is a problem no one has satisfactorily resolved, and it's nice that rust got this right), but can you expand the test in meta/lib/oeqa/sdk/cases/rust.py to cover possible target options such as this one? Alex On Thu, 28 Sept 2023 at 10:10, Sean Nyekjaer <sean@geanix.com> wrote: > > This will enable us to build and run rust programs on the sdk host. > > % cargo run --target x86_64-oesdk-linux-gnu -vv > Fresh hello v0.1.0 (~/development/hello) > Finished dev [unoptimized + debuginfo] target(s) in 0.02s > Running `/usr/local/sdk/sysroots/x86_64-oesdk-linux/lib/ld-linux-x86-64.so.2 target/x86_64-oesdk-linux-gnu/debug/hello` > Hello, world > > Signed-off-by: Sean Nyekjaer <sean@geanix.com> > --- > meta/recipes-devtools/rust/rust-cross-canadian.inc | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc > index d25646237c..5b89216658 100644 > --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc > +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc > @@ -55,9 +55,12 @@ do_install () { > RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" > > 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'` > + SDKARCH=`echo ${SDK_ARCH} | sed 's/_/-/g'` > > 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/ld-linux-${SDKARCH}.so.2" > export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" > EOF > > -- > 2.42.0 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#188370): https://lists.openembedded.org/g/openembedded-core/message/188370 > Mute This Topic: https://lists.openembedded.org/mt/101633983/1686489 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- >
Hi Alexander I am in the same team as Sean, and we really like the way it is solved in Rust/Cargo. However, we have the issue also for C++, and as you state there is no obvious solution. We are using cmaake for our C+++ projects and are discussing if a solution is to try to make a cmake toolchain file for the oesdk environment as well. If you have any experience/input it would be highly appreciated. Br Kasper On September 28, 2023 at 2:47:27 pm +02:00, Alexander Kanavin <alex.kanavin@gmail.com> wrote: > This seems like a good change (being able to easily run items built > with c/c++ tolchains in yocto SDKs is a problem no one has > satisfactorily resolved, and it's nice that rust got this right), but > can you expand the test in meta/lib/oeqa/sdk/cases/rust.py to cover > possible target options such as this one? > > Alex > > On Thu, 28 Sept 2023 at 10:10, Sean Nyekjaer <<sean@geanix.com>> wrote: > > > > > This will enable us to build and run rust programs on the sdk host. > > > > % cargo run --target x86_64-oesdk-linux-gnu -vv > > Fresh hello v0.1.0 (~/development/hello) > > Finished dev [unoptimized + debuginfo] target(s) in 0.02s > > Running `/usr/local/sdk/sysroots/x86_64-oesdk-linux/lib/ld-linux-x86-64.so.2 target/x86_64-oesdk-linux-gnu/debug/hello` > > Hello, world > > > > Signed-off-by: Sean Nyekjaer <<sean@geanix.com>> > > --- > > meta/recipes-devtools/rust/rust-cross-canadian.inc | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc > > index d25646237c..5b89216658 100644 > > --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc > > +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc > > @@ -55,9 +55,12 @@ do_install () { > > RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" > > > > 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'` > > + SDKARCH=`echo ${SDK_ARCH} | sed 's/_/-/g'` > > > > 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/ld-linux-${SDKARCH}.so.2" > > export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" > > EOF > > > > -- > > 2.42.0 > > > > > > > >
I think Adrian made the most progress in addressing this problem, so you should discuss/cooperate with him. Alex On Mon, 2 Oct 2023 at 13:12, Kasper <kasper@krinvent.dk> wrote: > > Hi Alexander > > I am in the same team as Sean, and we really like the way it is solved in Rust/Cargo. > However, we have the issue also for C++, and as you state there is no obvious solution. > We are using cmaake for our C+++ projects and are discussing if a solution is to try to make > a cmake toolchain file for the oesdk environment as well. > If you have any experience/input it would be highly appreciated. > > Br > Kasper > > On September 28, 2023 at 2:47:27 pm +02:00, Alexander Kanavin <alex.kanavin@gmail.com> wrote: > > This seems like a good change (being able to easily run items built > with c/c++ tolchains in yocto SDKs is a problem no one has > satisfactorily resolved, and it's nice that rust got this right), but > can you expand the test in meta/lib/oeqa/sdk/cases/rust.py to cover > possible target options such as this one? > > Alex > > On Thu, 28 Sept 2023 at 10:10, Sean Nyekjaer <sean@geanix.com> wrote: > > > This will enable us to build and run rust programs on the sdk host. > > % cargo run --target x86_64-oesdk-linux-gnu -vv > Fresh hello v0.1.0 (~/development/hello) > Finished dev [unoptimized + debuginfo] target(s) in 0.02s > Running `/usr/local/sdk/sysroots/x86_64-oesdk-linux/lib/ld-linux-x86-64.so.2 target/x86_64-oesdk-linux-gnu/debug/hello` > Hello, world > > Signed-off-by: Sean Nyekjaer <sean@geanix.com> > --- > meta/recipes-devtools/rust/rust-cross-canadian.inc | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc > index d25646237c..5b89216658 100644 > --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc > +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc > @@ -55,9 +55,12 @@ do_install () { > RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" > > 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'` > + SDKARCH=`echo ${SDK_ARCH} | sed 's/_/-/g'` > > 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/ld-linux-${SDKARCH}.so.2" > export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" > EOF > > -- > 2.42.0 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#188370): https://lists.openembedded.org/g/openembedded-core/message/188370 > Mute This Topic: https://lists.openembedded.org/mt/101633983/1686489 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- > >
Hi Kasper, hi Sean Yes, I did some trials with C/C++. There are 3 different approaches which I investigated into. All come with pros and cons. 1. compiling for the SDK (native) is easy and running the resulting binaries on the host also works. It is also relatively easy to create an tool-chain environment file that can be used to use the host toolchain with the native Yocto sysroots. I guess that's the proposed approach here. The downside to this idea is that it is not really reproducible. Compiling for the host uses the compiler and other tools provided by the host distribution. Since these may be different, the result and errors may also be different. Also, all recipes involved must be patched with the line BBCLASSEXTEND = "native nativesdk", which cannot be mainlined unless it makes sense to use a recipe as a native recipe in general. As far as I know, the Yocto project rejects such only partially implementable ideas for good reasons. 2. Stick to cross-compiling also for this use case, but compile for a MACHINE (e.g. Qemu) with the same CPU architecture as the host has can work as well. The build part is solved acc. the concepts of Yocto. But executing the binaries on the host is not that straight forward. For example this does not work even if xz is compiled for the same ARCH as the host has: ./build/tmp/work/corei7-64-ccp-linux/xz/5.2.6-r0/image/usr/bin/xz -- help bash: ./build/tmp/work/corei7-64-ccp-linux/xz/5.2.6- r0/image/usr/bin/xz: cannot execute: required file not found With a little trick (using the correct linker) it works: LD_LIBRARY_PATH="./build/tmp/work/corei7-64-ccp-linux/xz/5.2.6- r0/recipe-sysroot/lib:./build/tmp/work/corei7-64-ccp-linux/xz/5.2.6- r0/recipe-sysroot/usr/lib" ./build/tmp/work/corei7-64-ccp- linux/xz/5.2.6-r0/recipe-sysroot/lib/ld-linux-x86-64.so.2 ./build/tmp/work/corei7-64-ccp-linux/xz/5.2.6-r0/image/usr/bin/xz -- help Usage: ./projects/ccp-sd-virt/tmp/work/corei7-64-ccp-linux/xz/5.2.6- r0/image/usr/bin/xz [OPTION]... [FILE]... Compress or decompress FILEs in the .xz format. ... 3. Use Qemu to execute the binaries. This approach is transparently implemented with my SDK here: https://git.yoctoproject.org/poky-contrib/log/?h=adrianf/devtool-ide If for example the unit tests are executed in VSCode they just run even if they have a different architecture than the host has. This is fully supported by meson and by cmake. The disadvantage of this approach is that Qemu is not transparent when it comes to debugging and probably other use cases. Regards, Adrian
diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc index d25646237c..5b89216658 100644 --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc @@ -55,9 +55,12 @@ do_install () { RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" 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'` + SDKARCH=`echo ${SDK_ARCH} | sed 's/_/-/g'` 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/ld-linux-${SDKARCH}.so.2" export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" EOF
This will enable us to build and run rust programs on the sdk host. % cargo run --target x86_64-oesdk-linux-gnu -vv Fresh hello v0.1.0 (~/development/hello) Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running `/usr/local/sdk/sysroots/x86_64-oesdk-linux/lib/ld-linux-x86-64.so.2 target/x86_64-oesdk-linux-gnu/debug/hello` Hello, world Signed-off-by: Sean Nyekjaer <sean@geanix.com> --- meta/recipes-devtools/rust/rust-cross-canadian.inc | 3 +++ 1 file changed, 3 insertions(+)