You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Yocto交叉编译依赖Rocket的ARM平台Rust Nightly应用及排错

在OpenEmbedded中交叉编译使用Rocket的Rust Nightly应用问题排查

背景

我想在自定义meta层中编译使用Rocket web服务器的myRustApp。OpenEmbedded原生不支持Rocket所需的Rust Nightly版本,试过meta-rust层但只支持原生构建,最终选择带预构建Nightly工具链的meta-rust-bin层,执行./build-new-version.sh nightly成功构建了Nightly版本,但用bitbake构建recipe时出现错误。

错误信息

WARNING: /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross_1.59.0.bb: Exception during build_dependencies for TARGET_LLVM_FEATURES
WARNING: /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross_1.59.0.bb: Error during finalise of /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross_1.59.0.bb
ERROR: ExpansionError during parsing /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross_1.59.0.bb
Traceback (most recent call last):
  File "Var <TARGET_LLVM_FEATURES>", line 1, in <module>
  File "/home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-common.inc", line 117, in llvm_features(d=<bb.data_smart.DataSmart object at 0x7fe03b341f60>):
         return ','.join(llvm_features_from_tune(d) +
    >                    llvm_features_from_cc_arch(d) +
                         llvm_features_from_target_fpu(d))
  File "/home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-common.inc", line 36, in llvm_features_from_tune(d=<bb.data_smart.DataSmart object at 0x7fe03b341f60>):

    >    if target_is_armv7(d):
             f.append('+v7')
bb.data_smart.ExpansionError: Failure expanding variable TARGET_LLVM_FEATURES, expression was ${@llvm_features(d)} which triggered exception NameError: name 'target_is_armv7' is not defined
The variable dependency chain for the failure is: TARGET_LLVM_FEATURES

ERROR: Parsing halted due to errors, see error messages above
WARNING: /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross-canadian_1.59.0.bb: Exception during build_dependencies for TARGET_LLVM_FEATURES
WARNING: /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross-canadian_1.59.0.bb: Error during finalise of /home/jonas/project/sources/openembedded-core/meta/recipes-devtools/rust/rust-cross-canadian_1.59.0.bb

问题

  1. 该错误的成因是什么?如何修复?
  2. 是否有人尝试过交叉编译Rust Nightly应用?是否存在相关示例?

相关配置

Cargo.toml

[package]
name = "MyRustApp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = "0.4.10"
rocket_cors = "0.5.1"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"

[dependencies.rocket_contrib]
version = "0.4.10"
default-features = false
features = ["json"]

[profile.release]
strip = true
opt-level = "z" 
lto = true

cargo-bitbake生成的recipe

# Auto-Generated by cargo-bitbake 0.3.16
#
inherit cargo

# If this is git based prefer versioned ones if they exist
# DEFAULT_PREFERENCE = "-1"

# how to get strain-webserver could be as easy as but default to a git checkout:
# SRC_URI += "crate://crates.io/MyRustApp/0.1.0"
SRC_URI += "git://git@bitbucket.org/work/MyRustApp.git;protocol=ssh;nobranch=1;branch=main"
SRCREV = "xxx"
S = "${WORKDIR}/git"
CARGO_SRC_DIR = ""
PV:append = ".AUTOINC+d2562d3c92"

# please note if you have entries that do not begin with crate://
# you must change them to how that package can be fetched
SRC_URI += " 
    crate://crates.io/aead/0.3.2 
    crate://crates.io/aes-gcm/0.8.0 
    crate://crates.io/aes-soft/0.6.4 
    crate://crates.io/aes/0.6.0 
    crate://crates.io/aesni/0.10.0 
    crate://crates.io/aho-corasick/0.7.20 
    crate://crates.io/atty/0.2.14 
    crate://crates.io/autocfg/1.1.0 
    crate://crates.io/base64/0.13.1 
    crate://crates.io/base64/0.9.3 
    crate://crates.io/bitflags/1.3.2 
    crate://crates.io/block-buffer/0.9.0 
    crate://crates.io/byteorder/1.4.3 
    crate://crates.io/cfg-if/0.1.10 
    crate://crates.io/cfg-if/1.0.0 
    crate://crates.io/cipher/0.2.5 
    crate://crates.io/cookie/0.11.5 
    crate://crates.io/cpufeatures/0.2.5 
    crate://crates.io/cpuid-bool/0.2.0 
    crate://crates.io/crypto-mac/0.10.1 
    crate://crates.io/ctr/0.6.0 
    crate://crates.io/devise/0.2.1 
    crate://crates.io/devise_codegen/0.2.1 
    crate://crates.io/devise_core/0.2.1 
    crate://crates.io/digest/0.9.0 
    crate://crates.io/filetime/0.2.18 
    crate://crates.io/form_urlencoded/1.1.0 
    crate://crates.io/fsevent-sys/2.0.1 
    crate://crates.io/fsevent/0.4.0 
    crate://crates.io/fuchsia-zircon-sys/0.3.3 
    crate://crates.io/fuchsia-zircon/0.3.3 
    crate://crates.io/generic-array/0.14.6 
    crate://crates.io/getrandom/0.2.8 
    crate://crates.io/ghash/0.3.1 
    crate://crates.io/glob/0.3.0 
    crate://crates.io/hashbrown/0.12.3 
    crate://crates.io/hermit-abi/0.1.19 
    crate://crates.io/hkdf/0.10.0 
    crate://crates.io/hmac/0.10.1 
    crate://crates.io/httparse/1.8.0 
    crate://crates.io/hyper/0.10.16 
    crate://crates.io/idna/0.1.5 
    crate://crates.io/idna/0.3.0 
    crate://crates.io/indexmap/1.9.2 
    crate://crates.io/inotify-sys/0.1.5 
    crate://crates.io/inotify/0.7.1 
    crate://crates.io/iovec/0.1.4 
    crate://crates.io/itoa/1.0.4 
    crate://crates.io/kernel32-sys/0.2.2 
    crate://crates.io/language-tags/0.2.2 
    crate://crates.io/lazycell/1.3.0 
    crate://crates.io/libc/0.2.137 
    crate://crates.io/log/0.3.9 
    crate://crates.io/log/0.4.17 
    crate://crates.io/matches/0.1.9 
    crate://crates.io/memchr/2.5.0 
    crate://crates.io/mime/0.2.6 
    crate://crates.io/mio-extras/2.0.6 
    crate://crates.io/mio/0.6.23 
    crate://crates.io/miow/0.2.2 
    crate://crates.io/net2/0.2.38 
    crate://crates.io/notify/4.0.17 
    crate://crates.io/num_cpus/1.14.0 
    crate://crates.io/opaque-debug/0.3.0 
    crate://crates.io/pear/0.1.5 
    crate://crates.io/pear_codegen/0.1.5 
    crate://crates.io/percent-encoding/1.0.1 
    crate://crates.io/percent-encoding/2.2.0 
    crate://crates.io/polyval/0.4.5 
    crate://crates.io/ppv-lite86/0.2.17 
    crate://crates.io/proc-macro2/0.4.30 
    crate://crates.io/proc-macro2/1.0.47 
    crate://crates.io/quote/0.6.13 
    crate://crates.io/quote/1.0.21 
    crate://crates.io/rand/0.8.5 
    crate://crates.io/rand_chacha/0.3.1 
    crate://crates.io/rand_core/0.6.4 
    crate://crates.io/redox_syscall/0.2.16 
    crate://crates.io/regex-syntax/0.6.28 
    crate://crates.io/regex/1.7.0 
    crate://crates.io/rocket/0.4.11 
    crate://crates.io/rocket_codegen/0.4.11 
    crate://crates.io/rocket_contrib/0.4.11 
    crate://crates.io/rocket_cors/0.5.2 
    crate://crates.io/rocket_http/0.4.11 
    crate://crates.io/ryu/1.0.11 
    crate://crates.io/safemem/0.3.3 
    crate://crates.io/same-file/1.0.6 
    crate://crates.io/serde/1.0.147 
    crate://crates.io/serde_derive/1.0.147 
    crate://crates.io/serde_json/1.0.89 
    crate://crates.io/sha2/0.9.9 
    crate://crates.io/slab/0.4.7 
    crate://crates.io/smallvec/1.10.0 
    crate://crates.io/state/0.4.2 
    crate://crates.io/subtle/2.4.1 
    crate://crates.io/syn/0.15.44 
    crate://crates.io/syn/1.0.103 
    crate://crates.io/time/0.1.44 
    crate://crates.io/tinyvec/1.6.0 
    crate://crates.io/tinyvec_macros/0.1.0 
    crate://crates.io/toml/0.4.10 
    crate://crates.io/traitobject/0.1.0 
    crate://crates.io/typeable/0.1.2 
    crate://crates.io/typenum/1.15.0 
    crate://crates.io/unicase/1.4.2 
    crate://crates.io/unicase/2.6.0 
    crate://crates.io/unicase_serde/0.1.0 
    crate://crates.io/unicode-bidi/0.3.8 
    crate://crates.io/unicode-ident/1.0.5 
    crate://crates.io/unicode-normalization/0.1.22 
    crate://crates.io/unicode-xid/0.1.0 
    crate://crates.io/universal-hash/0.4.1 
    crate://crates.io/url/1.7.2 
    crate://crates.io/url/2.3.1 
    crate://crates.io/version_check/0.1.5 
    crate://crates.io/version_check/0.9.4 
    crate://crates.io/walkdir/2.3.2 
    crate://crates.io/wasi/0.10.0+wasi-snapshot-preview1 
    crate://crates.io/wasi/0.11.0+wasi-snapshot-preview1 
    crate://crates.io/winapi-build/0.1.1 
    crate://crates.io/winapi-i686-pc-windows-gnu/0.4.0 
    crate://crates.io/winapi-util/0.1.5 
    crate://crates.io/winapi-x86_64-pc-windows-gnu/0.4.0 
    crate://crates.io/winapi/0.2.8 
    crate://crates.io/winapi/0.3.9 
    crate://crates.io/windows-sys/0.42.0 
    crate://crates.io/windows_aarch64_gnullvm/0.42.0 
    crate://crates.io/windows_aarch64_msvc/0.42.0 
    crate://crates.io/windows_i686_gnu/0.42.0 
    crate://crates.io/windows_i686_msvc/0.42.0 
    crate://crates.io/windows_x86_64_gnu/0.42.0 
    crate://crates.io/windows_x86_64_gnullvm/0.42.0 
    crate://crates.io/windows_x86_64_msvc/0.42.0 
    crate://crates.io/ws2_32-sys/0.2.1 
    crate://crates.io/yansi/0.5.1 
"



# FIXME: update generateme with the real MD5 of the license file
LIC_FILES_CHKSUM = " 
    "

SUMMARY = "Webserver with Rust"t"
LICENSE = "CLOSED"

# includes this file if it exists but does not fail
# this is useful for anything you may want to override from
# what cargo-bitbake generates.
include MyRustApp-${PV}.inc
include MyRustApp.inc

解答

问题1:错误成因与修复方案

这个错误的核心是rust-common.inc中的llvm_features_from_tune函数调用了未定义的target_is_armv7函数。原因是meta-rust-bin层和openembedded-core中的rust recipes版本不兼容——meta-rust-bin提供的Nightly工具链对应的rust recipes版本,和当前OE-core里的rust-cross_1.59.0.bb不匹配,导致函数定义缺失。

修复步骤:

  • 版本对齐:确保meta-rust-bin层使用的rust版本和OE-core中rust recipes的版本一致。如果meta-rust-bin构建的是较新的Nightly版本,需要同步升级OE-core到对应兼容的分支,或者找和OE-core 1.59版本匹配的meta-rust-bin分支。
  • 临时补全函数:在rust-common.inc中添加target_is_armv7的定义:
    def target_is_armv7(d):
        return d.getVar('TARGET_ARCH') == 'arm' and 'v7' in d.getVar('TUNE_FEATURES', True)
    
    注意这种临时补丁可能引发其他兼容性问题,优先推荐版本对齐方案。
  • 强制跳过特性计算:如果目标架构不是ARMv7,可在local.conf中强制设置:
    TARGET_LLVM_FEATURES = ""
    
    ARM平台不建议使用该方法。

问题2:Rust Nightly交叉编译示例与实践

不少开发者尝试过在OE中交叉编译Rust Nightly应用,常见实践:

  • 指定Nightly工具链:在myRustApp recipe中替换或添加:
    RUST_VERSION = "nightly"
    inherit rust-bin
    
    确保cargo继承的rust环境为Nightly版本。
  • 配置交叉编译目标:在recipe中添加:
    CARGO_TARGET = "${TARGET_PREFIX}"
    CARGO_BUILD_FLAGS += "--target ${CARGO_TARGET}"
    
  • 手动调整依赖:Rocket 0.4.x需要Rust 1.54+ Nightly,确保工具链版本满足要求,同时修正生成的recipe中的语法
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 04:20:20