Skip to content

Commit 84f044c

Browse files
committed
rust-common-without-python3native.bbclass: refresh from oe-core
* there were many changes since this was imported, apply following changes: openembedded-core $ git log --oneline 997d54363a3c..d381122874 -- meta/classes-recipe/rust-common.bbclass meta/classes/rust-common.bbclass d381122874 rust-common.bbclass: move musl-specific linking fix from rust-source.inc 0c07089bdf rust: Do not use default compiler flags defined in CC crate 3bff689f0c rust: Enable baremetal targets a918ea5645 rust-common.bbclass: use built-in rust targets for -native builds f5c1280083 classes: Update classes to match new bitbake class scope functionality 081a391fe0 classes: Add SPDX license identifiers 880c1ea3ed classes: Add copyright statements to files without one ef347bd395 rust-common: Remove conflict with utils create_wrapper 06af65757b rust-common: Set rustlibdir to match target expectation f35d5af06d rust-common: Simplify libc handling dc134c0311 rust-common: Update to match cross targets d02c28b221 rust-common/rust: Improve bootstrap BUILD_SYS handling 9160e4a375 rust: Generate per recipe target configuration files dfff5a1767 rust-common: Rework wrappers to handle musl 1a992268e5 rust-common: Drop export directive from wrappers e2fc083529 rust-common: Add CXXFLAGS 38b61aeaf8 rust-common: Fix sstate signatures between arm hf and non-hf 67b4e0fdb1 rust-common: override RUST_LIBC for crosssdk c13afbade8 rust: Introduce RUST_BUILD_ARCH 9ab61e3cfe rust: Introduce arch_to_rust_arch() to fix firefox.do_configure failure: | 0:04.86 checking MOZ_PULSEAUDIO_LIBS... -lpulse -pthread | 0:04.86 checking for rustc... /OE/build/test-oe-build-time/poky/build/tmp/work/core2-64-poky-linux/firefox/68.9.0esr/recipe-sysroot-native/usr/bin/rustc | 0:04.86 checking for cargo... /OE/build/test-oe-build-time/poky/build/tmp/work/core2-64-poky-linux/firefox/68.9.0esr/recipe-sysroot-native/usr/bin/cargo | 0:04.92 checking rustc version... 1.70.0 | 0:04.93 checking cargo version... 1.70.0 | 0:04.95 checking rust host... x86_64-linux | 0:04.95 checking rust target... x86_64-poky-linux | 0:04.95 checking for rust target triplet... x86_64-poky-linux | 0:04.95 checking for rust host triplet... x86_64-linux | 0:04.95 ERROR: The rust compiler host (x86_64-unknown-linux-gnu) is not suitable for the configure host (x86_64-pc-linux-gnu/x86_64-linux). | 0:04.98 *** Fix above errors and then restart with\ | 0:04.98 "./mach build" | 0:04.98 make: *** [client.mk:115: configure] Error 1 * keep in mind that I'm still not interested in maintaining firefox recipe, I need it just to measure build time, nobody should use this unmaintained version for anything serious Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
1 parent 5099e66 commit 84f044c

File tree

2 files changed

+69
-58
lines changed

2 files changed

+69
-58
lines changed

meta-firefox/classes/mozilla.bbclass

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ export HOST_AR = "${BUILD_AR}"
2929
mozilla_run_mach() {
3030
export SHELL="/bin/sh"
3131
export RUSTFLAGS="${RUSTFLAGS} -Cpanic=unwind"
32-
export RUST_HOST="${BUILD_SYS}"
33-
export RUST_TARGET="${TARGET_SYS}"
34-
export RUST_TARGET_PATH="${STAGING_LIBDIR_NATIVE}/rustlib"
32+
# this needs to match with:
33+
# firefox/68.9.0esr $ recipe-sysroot-native/usr/bin/rustc --version --verbose | grep ^host
34+
# host: x86_64-unknown-linux-gnu
35+
export RUST_HOST="${RUST_BUILD_SYS}"
36+
export RUST_TARGET="${RUST_HOST_SYS}"
3537
export BINDGEN_MFLOAT="${@bb.utils.contains('TUNE_CCARGS_MFLOAT', 'hard', '-mfloat-abi=hard', '', d)}"
3638
export BINDGEN_CFLAGS="--target=${TARGET_SYS} --sysroot=${RECIPE_SYSROOT} ${BINDGEN_MFLOAT}"
3739

meta-firefox/classes/rust-common-without-python3native.bbclass

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
1+
#
2+
# Copyright OpenEmbedded Contributors
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
17
# removed, because firefox fails to configure when it finds native python3 instead of python2.7 from HOSTTOOLS
28
# inherit python3native
9+
inherit rust-target-config
310

411
# Common variables used by all Rust builds
5-
export rustlibdir = "${libdir}/rust"
12+
export rustlibdir = "${libdir}/rustlib/${RUST_HOST_SYS}/lib"
613
FILES:${PN} += "${rustlibdir}/*.so"
714
FILES:${PN}-dev += "${rustlibdir}/*.rlib ${rustlibdir}/*.rmeta"
815
FILES:${PN}-dbg += "${rustlibdir}/.debug"
916

10-
RUSTLIB = "-L ${STAGING_LIBDIR}/rust"
17+
RUSTLIB = "-L ${STAGING_DIR_HOST}${rustlibdir}"
1118
RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
1219
RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
1320
RUSTLIB_DEP ?= "libstd-rs"
14-
export RUST_TARGET_PATH = "${STAGING_LIBDIR_NATIVE}/rustlib"
1521
RUST_PANIC_STRATEGY ?= "unwind"
1622

17-
# Native builds are not effected by TCLIBC. Without this, rust-native
18-
# thinks it's "target" (i.e. x86_64-linux) is a musl target.
19-
RUST_LIBC = "${TCLIBC}"
20-
RUST_LIBC:class-native = "glibc"
21-
22-
def determine_libc(d, thing):
23-
'''Determine which libc something should target'''
24-
25-
# BUILD is never musl, TARGET may be musl or glibc,
26-
# HOST could be musl, but only if a compiler is built to be run on
27-
# target in which case HOST_SYS != BUILD_SYS.
28-
if thing == 'TARGET':
29-
libc = d.getVar('RUST_LIBC')
30-
elif thing == 'BUILD' and (d.getVar('HOST_SYS') != d.getVar('BUILD_SYS')):
31-
libc = d.getVar('RUST_LIBC')
32-
else:
33-
libc = d.getVar('RUST_LIBC:class-native')
34-
35-
return libc
36-
3723
def target_is_armv7(d):
3824
'''Determine if target is armv7'''
3925
# TUNE_FEATURES may include arm* even if the target is not arm
@@ -63,31 +49,31 @@ def rust_base_triple(d, thing):
6349
'''
6450
6551
# The llvm-target for armv7 is armv7-unknown-linux-gnueabihf
66-
if thing == "TARGET" and target_is_armv7(d):
52+
if d.getVar('{}_ARCH'.format(thing)) == d.getVar('TARGET_ARCH') and target_is_armv7(d):
6753
arch = "armv7"
6854
else:
6955
arch = oe.rust.arch_to_rust_arch(d.getVar('{}_ARCH'.format(thing)))
7056
71-
# All the Yocto targets are Linux and are 'unknown'
72-
vendor = "-unknown"
73-
os = d.getVar('{}_OS'.format(thing))
74-
libc = determine_libc(d, thing)
75-
76-
# Prefix with a dash and convert glibc -> gnu
77-
if libc == "glibc":
78-
libc = "-gnu"
79-
elif libc == "musl":
80-
libc = "-musl"
81-
82-
# Don't double up musl (only appears to be the case on aarch64)
83-
if os == "linux-musl":
84-
if libc != "-musl":
85-
bb.fatal("{}_OS was '{}' but TCLIBC was not 'musl'".format(thing, os))
86-
os = "linux"
57+
# Substituting "unknown" when vendor is empty will match rust's standard
58+
# targets when building native recipes (including rust-native itself)
59+
vendor = d.getVar('{}_VENDOR'.format(thing)) or "-unknown"
8760

61+
# Default to glibc
62+
libc = "-gnu"
63+
os = d.getVar('{}_OS'.format(thing))
8864
# This catches ARM targets and appends the necessary hard float bits
8965
if os == "linux-gnueabi" or os == "linux-musleabi":
9066
libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d)
67+
elif "musl" in os:
68+
libc = "-musl"
69+
os = "linux"
70+
elif "elf" in os:
71+
libc = "-elf"
72+
os = "none"
73+
elif "eabi" in os:
74+
libc = "-eabi"
75+
os = "none"
76+
9177
return arch + vendor + '-' + os + libc
9278

9379

@@ -112,13 +98,16 @@ RUST_BUILD_ARCH = "${@oe.rust.arch_to_rust_arch(d.getVar('BUILD_ARCH'))}"
11298
# Rust additionally will use two additional cases:
11399
# - undecorated (e.g. CC) - equivalent to TARGET
114100
# - triple suffix (e.g. CC:x86_64_unknown_linux_gnu) - both
115-
# see: https://github.com/alexcrichton/gcc-rs
101+
# see: https://github.com/rust-lang/cc-rs
116102
# The way that Rust's internal triples and Yocto triples are mapped together
117103
# its likely best to not use the triple suffix due to potential confusion.
118104

119105
RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}"
106+
RUST_BUILD_SYS[vardepvalue] = "${RUST_BUILD_SYS}"
120107
RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}"
108+
RUST_HOST_SYS[vardepvalue] = "${RUST_HOST_SYS}"
121109
RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}"
110+
RUST_TARGET_SYS[vardepvalue] = "${RUST_TARGET_SYS}"
122111

123112
# wrappers to get around the fact that Rust needs a single
124113
# binary but Yocto's compiler and linker commands have
@@ -135,26 +124,46 @@ RUST_TARGET_CXX = "${WRAPPER_DIR}/target-rust-cxx"
135124
RUST_TARGET_CCLD = "${WRAPPER_DIR}/target-rust-ccld"
136125
RUST_TARGET_AR = "${WRAPPER_DIR}/target-rust-ar"
137126

138-
create_wrapper () {
127+
create_wrapper_rust () {
139128
file="$1"
140129
shift
130+
extras="$1"
131+
shift
132+
crate_cc_extras="$1"
133+
shift
141134

142135
cat <<- EOF > "${file}"
143136
#!/usr/bin/env python3
144137
import os, sys
145138
orig_binary = "$@"
139+
extras = "${extras}"
140+
141+
# Apply a required subset of CC crate compiler flags
142+
# when we build a target recipe for a non-bare-metal target.
143+
# https://github.com/rust-lang/cc-rs/blob/main/src/lib.rs#L1614
144+
if "CRATE_CC_NO_DEFAULTS" in os.environ.keys() and \
145+
"TARGET" in os.environ.keys() and not "-none-" in os.environ["TARGET"]:
146+
orig_binary += "${crate_cc_extras}"
147+
146148
binary = orig_binary.split()[0]
147149
args = orig_binary.split() + sys.argv[1:]
150+
if extras:
151+
args.append(extras)
148152
os.execvp(binary, args)
149153
EOF
150154
chmod +x "${file}"
151155
}
152156

153-
export WRAPPER_TARGET_CC = "${CC}"
154-
export WRAPPER_TARGET_CXX = "${CXX}"
155-
export WRAPPER_TARGET_CCLD = "${CCLD}"
156-
export WRAPPER_TARGET_LDFLAGS = "${LDFLAGS}"
157-
export WRAPPER_TARGET_AR = "${AR}"
157+
WRAPPER_TARGET_CC = "${CC}"
158+
WRAPPER_TARGET_CXX = "${CXX}"
159+
WRAPPER_TARGET_CCLD = "${CCLD}"
160+
WRAPPER_TARGET_LDFLAGS = "${LDFLAGS}"
161+
WRAPPER_TARGET_EXTRALD = ""
162+
# see recipes-devtools/gcc/gcc/0018-Add-ssp_nonshared-to-link-commandline-for-musl-targe.patch
163+
# we need to link with ssp_nonshared on musl to avoid "undefined reference to `__stack_chk_fail_local'"
164+
# when building MACHINE=qemux86 for musl
165+
WRAPPER_TARGET_EXTRALD:libc-musl = "-lssp_nonshared"
166+
WRAPPER_TARGET_AR = "${AR}"
158167

159168
# compiler is used by gcc-rs
160169
# linker is used by rustc/cargo
@@ -163,22 +172,22 @@ do_rust_create_wrappers () {
163172
mkdir -p "${WRAPPER_DIR}"
164173

165174
# Yocto Build / Rust Host C compiler
166-
create_wrapper "${RUST_BUILD_CC}" "${BUILD_CC}"
175+
create_wrapper_rust "${RUST_BUILD_CC}" "" "${CRATE_CC_FLAGS}" "${BUILD_CC}"
167176
# Yocto Build / Rust Host C++ compiler
168-
create_wrapper "${RUST_BUILD_CXX}" "${BUILD_CXX}"
177+
create_wrapper_rust "${RUST_BUILD_CXX}" "" "${CRATE_CC_FLAGS}" "${BUILD_CXX}"
169178
# Yocto Build / Rust Host linker
170-
create_wrapper "${RUST_BUILD_CCLD}" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
179+
create_wrapper_rust "${RUST_BUILD_CCLD}" "" "" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
171180
# Yocto Build / Rust Host archiver
172-
create_wrapper "${RUST_BUILD_AR}" "${BUILD_AR}"
181+
create_wrapper_rust "${RUST_BUILD_AR}" "" "" "${BUILD_AR}"
173182

174183
# Yocto Target / Rust Target C compiler
175-
create_wrapper "${RUST_TARGET_CC}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}"
184+
create_wrapper_rust "${RUST_TARGET_CC}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CC}" "${WRAPPER_TARGET_LDFLAGS}"
176185
# Yocto Target / Rust Target C++ compiler
177-
create_wrapper "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_CXX}"
186+
create_wrapper_rust "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_EXTRALD}" "${CRATE_CC_FLAGS}" "${WRAPPER_TARGET_CXX}" "${CXXFLAGS}"
178187
# Yocto Target / Rust Target linker
179-
create_wrapper "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
188+
create_wrapper_rust "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_EXTRALD}" "" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
180189
# Yocto Target / Rust Target archiver
181-
create_wrapper "${RUST_TARGET_AR}" "${WRAPPER_TARGET_AR}"
190+
create_wrapper_rust "${RUST_TARGET_AR}" "" "" "${WRAPPER_TARGET_AR}"
182191

183192
}
184193

0 commit comments

Comments
 (0)