rustyoctobitbake

Force cargo version with Yocto


I am trying to use rust with bitbake/yocto using the meta-rust layer.

Within the layer itself I can see that a recipe for cargo version 1.58.0 was recently added. Unfortunately when I try and build any rust code Using BitBake I get the following error:

NOTE: Executing Tasks
ERROR: echo-server-0.1.0.AUTOINC+c37d3bb2f3-r0 do_compile: ExecutionError('./tmp/work/corei7-64-poky-linux/echo-server/0.1.0.AUTOINC+c37d3bb2f3-r0/temp/run.do_compile.391773', 101, None, None)
ERROR: Logfile of failure stored in: ./tmp/work/corei7-64-poky-linux/echo-server/0.1.0.AUTOINC+c37d3bb2f3-r0/temp/log.do_compile.391773
Log data follows:
| DEBUG: Executing shell function do_compile
| NOTE: cargo = build/tmp/work/corei7-64-poky-linux/echo-server/0.1.0.AUTOINC+c37d3bb2f3-r0/recipe-sysroot-native/usr/bin/cargo
| NOTE: rustc =
| NOTE: cargo build -v --target x86_64-poky-linux --release --manifest-path=./build/tmp/work/corei7-64-poky-linux/echo-server/0.1.0.AUTOINC+c37d3bb2f3-r0/git//Cargo.toml
| error: failed to parse manifest at ./build/tmp/work/corei7-64-poky-linux/echo-server/0.1.0.AUTOINC+c37d3bb2f3-r0/git/Cargo.toml
|
| Caused by:
|   feature `edition2021` is required
|
|   consider adding `cargo-features = ["edition2021"]` to the manifest
| WARNING: exit code 101 from a shell command.

The rust code builds fine on the local system and I believe the error is because the version of cargo being used by yocto is 1.54

tmp/work/corei7-64-poky-linux/libstd-rs/1.54.0-r0/recipe-sysroot-native/usr/bin/cargo --version

cargo 1.54.0

How do I get yocto to use the later version of cargo? The recipe exists in meta-rust and I can see yocto knows about it via

bitbake -s | grep cargo

cargo                                              :1.58.1-r0
cargo-cross-canadian-x86-64                        :1.58.1-r0
cargo-native                                       :1.58.1-r0                :1.54.0-r0
nativesdk-cargo                                    :1.58.1-r0

Note if set RUSTVERSION ?= "1.58" I get the following warnings:

WARNING: preferred version 1.58 of cargo-native not available (for item cargo-native)
WARNING: versions of cargo-native available: 1.54.0
WARNING: preferred version 1.58 of libstd-rs not available (for item libstd-rs)
WARNING: versions of libstd-rs available: 1.54.0
WARNING: preferred version 1.58 of libstd-rs not available (for item libstd-rs)
WARNING: versions of libstd-rs available: 1.54.0
WARNING: preferred version 1.58 of libstd-rs not available (for item libstd-rs-dev)
WARNING: versions of libstd-rs available: 1.54.0
WARNING: preferred version 1.58 of rust-native not available (for item rust-native)
WARNING: versions of rust-native available: 1.54.0
WARNING: preferred version 1.58 of rust-llvm-native not available (for item rust-llvm-native)
WARNING: versions of rust-llvm-native available: 1.54.0

Which indicates it is defaulting to version 1.54.0

Note: bitbake -c cleanall rust cargo produces the following errors:

ERROR: Nothing PROVIDES 'rust'
rust was skipped: Rust recipe doesn't work for target builds at this time. Fixes welcome.

Solution

  • It seems that meta-rust is no longer maintained since it has been merged into oe-core. Use the rust included with oe-core, or if you want to use a newer version of rust on an older Yocto release, see meta-lts-mixins.

    Source: the following issues from meta-rust:

    rust-native fails in do_compile with poky mickeldore #427

    ...

    Unfortunately meta-rust does not work with Mickledore at the moment because bitbake's classes directory was split up into classes-global, classes-recipe, and classes. The rust recipes in openembedded-core are in classes-recipe and are thus always found before the rust recipes in meta-rust that are supposed to override them, as they are there located in classes.

    ...

    The way forward is to use Rust from oe core or maybe also https://github.com/rust-embedded/meta-rust-bin .

    and Layer does not support Scarthgap #451

    For the purpose of backporting newer rust onto older Yocto releases (including scarthgap), the official place for such work is https://git.yoctoproject.org/meta-lts-mixins/

    I'd suggest everyone to focus their efforts there, and mark this layer as deprecated and no longer maintained for anything reasonably recent.

    For projects already utilizing meta-rust

    ah008a correctly noted in a comment that you must include rust_versions.inc, in addition to setting RUST_VERSION. This file sets a default value and then propagates the rust version to other rust tools like cargo:

    # include this in your distribution to easily switch between versions
    # just by changing RUST_VERSION variable
    
    RUST_VERSION ?= "1.78.0"
    
    PREFERRED_VERSION_cargo ?= "${RUST_VERSION}"
    PREFERRED_VERSION_cargo-cross-canadian-${TARGET_ARCH} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_cargo-native ?= "${RUST_VERSION}"
    PREFERRED_VERSION_nativesdk-cargo ?= "${RUST_VERSION}"
    PREFERRED_VERSION_libstd-rs ?= "${RUST_VERSION}"
    PREFERRED_VERSION_nativesdk-libstd-rs ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-cross-canadian-${TARGET_ARCH} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-tools-cross-canadian-${TARGET_ARCH} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-cross-${TARGET_ARCH} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-cross-${DEFAULTTUNE}-${TCLIBC} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-crosssdk-${SDK_ARCH}-${TCLIBC} ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-llvm ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-llvm-native ?= "${RUST_VERSION}"
    PREFERRED_VERSION_rust-native ?= "${RUST_VERSION}"
    

    Override the RUST_VERSION in your distro.conf or local.conf and then include or require it:

    RUST_VERSION = "1.58.0"
    require ${SRC_DIR}/meta-rust/conf/distro/include/rust_versions.inc
    

    of course changing the path as necessary.