1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

rust: Generate per recipe target configuration files

Instead of generating target configuration files centrally and often getting
it wrong, or having trouble finding the right set, generate them dynamically
from the bbclass into WORKDIR per recipe.

(From OE-Core rev: 9160e4a37561d8ac882057450a818621bec13bed)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2022-08-05 13:15:31 +01:00
parent 9a093d0348
commit b1d8d2a3bf
8 changed files with 26 additions and 22 deletions
+2 -1
View File
@@ -4,6 +4,7 @@
## Cargo. ## Cargo.
inherit cargo_common inherit cargo_common
inherit rust-target-config
# the binary we will use # the binary we will use
CARGO = "cargo" CARGO = "cargo"
@@ -40,7 +41,7 @@ BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
CARGO_TARGET_SUBDIR="${RUST_HOST_SYS}/${BUILD_DIR}" CARGO_TARGET_SUBDIR="${RUST_HOST_SYS}/${BUILD_DIR}"
oe_cargo_build () { oe_cargo_build () {
export RUSTFLAGS="${RUSTFLAGS}" export RUSTFLAGS="${RUSTFLAGS}"
export RUST_TARGET_PATH="${RUST_TARGET_PATH}" bbnote "Using rust targets from ${RUST_TARGET_PATH}"
bbnote "cargo = $(which ${CARGO})" bbnote "cargo = $(which ${CARGO})"
bbnote "rustc = $(which ${RUSTC})" bbnote "rustc = $(which ${RUSTC})"
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
-1
View File
@@ -93,7 +93,6 @@ do_configure () {
} }
oe_runrustc () { oe_runrustc () {
export RUST_TARGET_PATH="${RUST_TARGET_PATH}"
bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@" bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
"${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@" "${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
} }
+1 -1
View File
@@ -1,4 +1,5 @@
inherit python3native inherit python3native
inherit rust-target-config
# Common variables used by all Rust builds # Common variables used by all Rust builds
export rustlibdir = "${libdir}/rust" export rustlibdir = "${libdir}/rust"
@@ -10,7 +11,6 @@ RUSTLIB = "-L ${STAGING_LIBDIR}/rust"
RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}" RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}" RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
RUSTLIB_DEP ?= "libstd-rs" RUSTLIB_DEP ?= "libstd-rs"
export RUST_TARGET_PATH = "${STAGING_LIBDIR_NATIVE}/rustlib"
RUST_PANIC_STRATEGY ?= "unwind" RUST_PANIC_STRATEGY ?= "unwind"
# Native builds are not effected by TCLIBC. Without this, rust-native # Native builds are not effected by TCLIBC. Without this, rust-native
+9 -9
View File
@@ -292,6 +292,7 @@ def rust_gen_target(d, thing, wd, arch):
import json import json
sys = d.getVar('{}_SYS'.format(thing)) sys = d.getVar('{}_SYS'.format(thing))
prefix = d.getVar('{}_PREFIX'.format(thing)) prefix = d.getVar('{}_PREFIX'.format(thing))
rustsys = d.getVar('RUST_{}_SYS'.format(thing))
abi = None abi = None
cpu = "generic" cpu = "generic"
@@ -318,13 +319,9 @@ def rust_gen_target(d, thing, wd, arch):
features = features or d.getVarFlag('FEATURES', arch_abi) or "" features = features or d.getVarFlag('FEATURES', arch_abi) or ""
features = features.strip() features = features.strip()
llvm_target = d.getVar('RUST_TARGET_SYS')
if thing == "BUILD":
llvm_target = d.getVar('RUST_HOST_SYS')
# build tspec # build tspec
tspec = {} tspec = {}
tspec['llvm-target'] = llvm_target tspec['llvm-target'] = rustsys
tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch_abi) tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch_abi)
if tspec['data-layout'] is None: if tspec['data-layout'] is None:
bb.fatal("No rust target defined for %s" % arch_abi) bb.fatal("No rust target defined for %s" % arch_abi)
@@ -358,7 +355,7 @@ def rust_gen_target(d, thing, wd, arch):
tspec['panic-strategy'] = d.getVar("RUST_PANIC_STRATEGY") tspec['panic-strategy'] = d.getVar("RUST_PANIC_STRATEGY")
# write out the target spec json file # write out the target spec json file
with open(wd + sys + '.json', 'w') as f: with open(wd + rustsys + '.json', 'w') as f:
json.dump(tspec, f, indent=4) json.dump(tspec, f, indent=4)
# These are accounted for in tmpdir path names so don't need to be in the task sig # These are accounted for in tmpdir path names so don't need to be in the task sig
@@ -366,10 +363,13 @@ rust_gen_target[vardepsexclude] += "ABIEXTENSION llvm_cpu"
do_rust_gen_targets[vardeps] += "DATA_LAYOUT TARGET_ENDIAN TARGET_POINTER_WIDTH TARGET_C_INT_WIDTH MAX_ATOMIC_WIDTH FEATURES" do_rust_gen_targets[vardeps] += "DATA_LAYOUT TARGET_ENDIAN TARGET_POINTER_WIDTH TARGET_C_INT_WIDTH MAX_ATOMIC_WIDTH FEATURES"
RUST_TARGETGENS = "BUILD" RUST_TARGETS_DIR = "${WORKDIR}/rust-targets/"
export RUST_TARGET_PATH = "${RUST_TARGETS_DIR}"
RUST_TARGETGENS = "BUILD HOST TARGET"
python do_rust_gen_targets () { python do_rust_gen_targets () {
wd = d.getVar('WORKDIR') + '/targets/' wd = d.getVar('RUST_TARGETS_DIR')
# Order of BUILD, HOST, TARGET is important in case the files overwrite, most specific last # Order of BUILD, HOST, TARGET is important in case the files overwrite, most specific last
rust_gen_target(d, 'BUILD', wd, d.getVar('BUILD_ARCH')) rust_gen_target(d, 'BUILD', wd, d.getVar('BUILD_ARCH'))
if "HOST" in d.getVar("RUST_TARGETGENS"): if "HOST" in d.getVar("RUST_TARGETGENS"):
@@ -379,5 +379,5 @@ python do_rust_gen_targets () {
} }
addtask rust_gen_targets after do_patch before do_compile addtask rust_gen_targets after do_patch before do_compile
do_rust_gen_targets[dirs] += "${WORKDIR}/targets" do_rust_gen_targets[dirs] += "${RUST_TARGETS_DIR}"
+2
View File
@@ -18,6 +18,8 @@ EXCLUDE_FROM_WORLD = "1"
inherit cargo pkgconfig inherit cargo pkgconfig
RUST_TARGETGENS = "BUILD HOST TARGET"
do_cargo_setup_snapshot () { do_cargo_setup_snapshot () {
${WORKDIR}/rust-snapshot-components/${CARGO_SNAPSHOT}/install.sh --prefix="${WORKDIR}/${CARGO_SNAPSHOT}" --disable-ldconfig ${WORKDIR}/rust-snapshot-components/${CARGO_SNAPSHOT}/install.sh --prefix="${WORKDIR}/${CARGO_SNAPSHOT}" --disable-ldconfig
# Need to use uninative's loader if enabled/present since the library paths # Need to use uninative's loader if enabled/present since the library paths
+3
View File
@@ -12,6 +12,9 @@ DEPENDS:append:libc-musl = " libunwind"
DEPENDS:remove:riscv32 = "libunwind" DEPENDS:remove:riscv32 = "libunwind"
DEPENDS:remove:riscv64 = "libunwind" DEPENDS:remove:riscv64 = "libunwind"
RUST_TARGETGENS = "BUILD HOST TARGET"
# Embed bitcode in order to allow compiling both with and without LTO # Embed bitcode in order to allow compiling both with and without LTO
RUSTFLAGS += "-Cembed-bitcode=yes" RUSTFLAGS += "-Cembed-bitcode=yes"
# Needed so cargo can find libbacktrace # Needed so cargo can find libbacktrace
+2 -3
View File
@@ -12,9 +12,6 @@ DEPENDS:append:class-native = " rust-llvm-native"
S = "${RUSTSRC}" S = "${RUSTSRC}"
# We generate local targets, and need to be able to locate them
export RUST_TARGET_PATH="${WORKDIR}/targets/"
export FORCE_CRATE_HASH="${BB_TASKHASH}" export FORCE_CRATE_HASH="${BB_TASKHASH}"
RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config" RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
@@ -40,6 +37,8 @@ setup_cargo_environment () {
inherit rust-target-config inherit rust-target-config
RUST_TARGETGENS = "BUILD HOST TARGET"
do_rust_setup_snapshot () { do_rust_setup_snapshot () {
for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do
"${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig "${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig
+7 -7
View File
@@ -14,7 +14,7 @@ SECTION = "x11/utils"
DEPENDS = "cairo gdk-pixbuf glib-2.0 libxml2 pango python3-docutils-native" DEPENDS = "cairo gdk-pixbuf glib-2.0 libxml2 pango python3-docutils-native"
BBCLASSEXTEND = "native nativesdk" BBCLASSEXTEND = "native nativesdk"
inherit gnomebase pixbufcache upstream-version-is-even gobject-introspection rust vala gi-docgen inherit cargo_common gnomebase pixbufcache upstream-version-is-even gobject-introspection rust vala gi-docgen
SRC_URI += "file://0001-Makefile.am-pass-rust-target-to-cargo-also-when-not-.patch \ SRC_URI += "file://0001-Makefile.am-pass-rust-target-to-cargo-also-when-not-.patch \
file://0001-system-deps-src-lib.rs-do-not-probe-into-harcoded-li.patch \ file://0001-system-deps-src-lib.rs-do-not-probe-into-harcoded-li.patch \
@@ -29,7 +29,6 @@ BASEDEPENDS:append = " cargo-native"
export RUST_BACKTRACE = "full" export RUST_BACKTRACE = "full"
export RUSTFLAGS export RUSTFLAGS
export RUST_TARGET_PATH
export RUST_TARGET = "${RUST_HOST_SYS}" export RUST_TARGET = "${RUST_HOST_SYS}"
@@ -38,16 +37,17 @@ RUSTFLAGS:append:mipsel = " --cfg crossbeam_no_atomic_64"
RUSTFLAGS:append:powerpc = " --cfg crossbeam_no_atomic_64" RUSTFLAGS:append:powerpc = " --cfg crossbeam_no_atomic_64"
RUSTFLAGS:append:riscv32 = " --cfg crossbeam_no_atomic_64" RUSTFLAGS:append:riscv32 = " --cfg crossbeam_no_atomic_64"
CARGO_DISABLE_BITBAKE_VENDORING = "1"
do_configure[postfuncs] += "cargo_common_do_configure"
inherit rust-target-config
# rust-cross writes the target linker binary into target json definition without any flags. # rust-cross writes the target linker binary into target json definition without any flags.
# This breaks here because the linker isn't going to work without at least knowing where # This breaks here because the linker isn't going to work without at least knowing where
# the sysroot is. So copy the json to workdir, and patch in the path to wrapper from rust class # the sysroot is. So copy the json to workdir, and patch in the path to wrapper from rust class
# which supplies the needed flags. # which supplies the needed flags.
do_compile:prepend() { do_compile:prepend() {
cp ${STAGING_LIBDIR_NATIVE}/rustlib/${HOST_SYS}.json ${WORKDIR} sed -ie 's,"linker": ".*","linker": "${RUST_TARGET_CC}",g' ${RUST_TARGETS_DIR}/${RUST_HOST_SYS}.json
cp ${STAGING_LIBDIR_NATIVE}/rustlib/${BUILD_SYS}.json ${WORKDIR}
sed -ie 's,"linker": ".*","linker": "${RUST_TARGET_CC}",g' ${WORKDIR}/${RUST_HOST_SYS}.json
RUST_TARGET_PATH="${WORKDIR}"
export RUST_TARGET_PATH
} }
# Issue only on windows # Issue only on windows