Skip to content

[RUST] Use official target list

We have a rust project which involves the compilation of the crate openssl-sys. During the compilation we face the following error:

| error: failed to run custom build command for openssl-sys v0.9.72 | | Caused by: | process didn't exit successfully: /home/yoctouser/workdir/yocto/build_test/tmp/work/cortexa9t2hf-neon-poky-linux- gnueabi/edgehog-device-runtime/1.0.AUTOINC+c4dc72298e-r0/build/target/debug/ build/openssl-sys-c132bfcc587ec45f/build-script-main (exit status: 101) | --- stdout | cargo:rustc-cfg=const_fn | cargo:rerun-if-env-changed=ARM_POKY_LINUX_GNUEABI_OPENSSL_NO_VENDOR | ARM_POKY_LINUX_GNUEABI_OPENSSL_NO_VENDOR unset | cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR | OPENSSL_NO_VENDOR unset | | --- stderr | warning: target json file contains unused fields: has-elf-tls | | warning: target json file contains unused fields: has-elf-tls | | thread 'main' panicked at 'don't know how to configure OpenSSL for arm-poky-linux-gnueabi', /home/yoctouser/workdir/yocto/build_test/tmp/work/cortexa9t2hf-neon-poky-linux- gnueabi/edgehog-device-runtime/1.0.AUTOINC+c4dc72298e-r0/cargo_home/bitbake/ openssl-src-111.18.0+1.1.1n/src/lib.rs:283:18

This happens because in the file <rust project's yocto folder>/cargo_home/bitbake/openssl-src-111.18.0+1.1.1n/src/lib.rs there is the following code snippet

let os = match target {
        "aarch64-apple-darwin" => "darwin64-arm64-cc",
        // Note that this, and all other android targets, aren't using the
        // `android64-aarch64` (or equivalent) builtin target. That
        // apparently has a crazy amount of build logic in OpenSSL 1.1.1
        // that bypasses basically everything `cc` does, so let's just cop
        // out and say it's linux and hope it works.
        "aarch64-linux-android" => "linux-aarch64",
        "aarch64-unknown-freebsd" => "BSD-generic64",
        "aarch64-unknown-linux-gnu" => "linux-aarch64",
        "aarch64-unknown-linux-musl" => "linux-aarch64",
        "aarch64-pc-windows-msvc" => "VC-WIN64-ARM",
        "arm-linux-androideabi" => "linux-armv4",
        "armv7-linux-androideabi" => "linux-armv4",
        ...
        _ => panic!("don't know how to configure OpenSSL for {}", target),
    };

In practice, there is a check about the usage of the target among the official ones. Since Yocto creates a custom target starting from HOST_SYS environment variable this crate will be never compiled.

The proposed patch replaces the usage of the target created via HOST_SYS with an official target created with an already present function which builds the target's name analyzing the TUNEFEATURE environment variable of Yocto. This replacement starts from rust-common class:

USE_RUST_PLATFORM = "1" RUST_PLATFORM = "${@['${HOST_SYS}', '${RUST_TARGET_SYS}'][d.getVar('USE_RUST_PLATFORM') == '1']}" RUST_TARGET = "${@['${HOST_SYS}', '${RUST_TARGET_SYS}'][d.getVar('USE_RUST_PLATFORM') == '1']}"

where the USE_RUST_PLATFORM has a default set in order to use the newest target convention. Putting these to 1 the system will use the HOST_SYS's content as the target. RUST_PLATFORM and RUST_TARGET replace the occurrences of HOST_SYS and TARGET_SYS variables (this include also the recipe of libstd-rs in order to preserve the coherency during the compilation)

Edited by Tobias Kahlki

Merge request reports