meta-rust-bin icon indicating copy to clipboard operation
meta-rust-bin copied to clipboard

Install tools in SDK

Open nastevens opened this issue 6 years ago • 2 comments

Right now neither rustc nor cargo are being installed as part of the SDK build - this would probably be quite useful, especially for cross-compiling projects with mixed C/Rust environments.

I made the dumb-simple effort of trying to add BBCLASSEXTEND = "nativesdk" to the recipes, but there were errors from that, so opening this issue to track some more research into the reasons.

nastevens avatar Apr 05 '18 17:04 nastevens

I'd like to see this too, and I'm currently in a position to help test this, should someone be able to give some pointers on how to go about this.

I've seen mention of TOOLCHAIN_HOST_TASK but I'm not sure what to set it to...

DavidAntliff avatar Feb 26 '24 02:02 DavidAntliff

For what it's worth, I was able to get cargo to use the SDK toolchain (created from Yocto Langdale) with commit 019e3b0073510e6f39fac23d9a3c2dd6d793a2fe of meta-rust-bin.

Prerequisite - have a working meta-rust-bin layer and a recipe using the cargo_bin class.

Set up a Cargo config for the target architecture (I'm building for an ARM / AArch64 CortexA53 CPU):

$ rustup target install target.aarch64-unknown-linux-gnu
$ rustup target add target.aarch64-unknown-linux-gnu

Modify ~/.cargo/config:

[target.aarch64-unknown-linux-gnu]
linker="aarch64-xilinx-linux-gcc"
rustflags = [
    "-C", "link-arg=--sysroot=/path/to/sdk/sysroots/cortexa72-cortexa53-xilinx-linux",
]

To then build with this toolchain, the Yocto environment must be active:

$ source /path/to/sdk/environment-setup-cortexa72-cortexa53-xilinx-linux

To build:

$ cargo build --target=aarch64-unknown-linux-gnu

One thing I haven't yet figured out though is why the binary produced by this (even with the build --release flag) is a good 30% slower in execution time, for a CPU-bounded task, than the one that Yocto builds & deploys when creating the root filesystem image. Perhaps Yocto's release build is more aggressive than the default for cargo's --release flag?

DavidAntliff avatar Mar 03 '24 01:03 DavidAntliff