mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-21 22:41:09 +02:00
eclass/coreos-cargo: Restructure how base libs are built
This changes the rustc wrapper script to actually use cargo's RUSTC_WRAPPER variable, and the logic in the script now uses the --target option to detect when it is cross-compiling. If it is, it transparently adds the --sysroot option to the rustc command so the target libraries are used in the board as its sysroot. This allows dropping any distinction between host-compatible targets. In doing this, the cross-compiler wrapper scripts had to be moved from the rustlib package to the eclass for all builds, since no longer having a --sysroot on every call would resurrect failures due to LD_LIBRARY_PATH. The rustlib package itself is now also building proc_macro, using its target output directory in the library search path to find the bootstrapping libraries as it is building them.
This commit is contained in:
parent
0c74d67698
commit
e422bc4fc6
@ -31,35 +31,8 @@ src_configure() {
|
||||
# too, and we don't want that since we aren't building the whole compiler
|
||||
rm src/Cargo.toml
|
||||
|
||||
# Wrap ar for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_AR="${T}/rustproof-ar"
|
||||
cat <<- EOF > "${TARGET_AR}" && chmod 0755 "${TARGET_AR}"
|
||||
#!/bin/sh
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getAR) "\$@"
|
||||
EOF
|
||||
|
||||
# Wrap gcc for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_CC="${T}/rustproof-cc"
|
||||
cat <<- EOF > "${TARGET_CC}" && chmod 0755 "${TARGET_CC}"
|
||||
#!/bin/sh
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getCC) "\$@"
|
||||
EOF
|
||||
|
||||
# Wrap g++ for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_CXX="${T}/rustproof-cxx"
|
||||
cat <<- EOF > "${TARGET_CXX}" && chmod 0755 "${TARGET_CXX}"
|
||||
#!/bin/sh
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getCXX) "\$@"
|
||||
EOF
|
||||
|
||||
# Make cargo use the wrappers as well.
|
||||
sed -i \
|
||||
-e "s,^ar *=.*,ar = \"${TARGET_AR}\"," \
|
||||
-e "s,^linker *=.*,linker = \"${TARGET_CC}\"," \
|
||||
"${ECARGO_HOME}/config"
|
||||
# Add the vendored crates to the local registry.
|
||||
ln -fst "${ECARGO_VENDOR}" "${S}"/src/vendor/*
|
||||
}
|
||||
|
||||
src_compile() {
|
||||
@ -71,21 +44,27 @@ src_compile() {
|
||||
# really building the std libs is bootstrapping anyway, so I don't feel bad
|
||||
local -x RUSTC_BOOTSTRAP=1
|
||||
# various required flags for compiling thes std libs
|
||||
local -x RUSTFLAGS="-Z force-unstable-if-unmarked"
|
||||
# make sure we can find the custom ChromeOS target definitions
|
||||
local -x RUST_TARGET_PATH="/usr/$(get_libdir)/rustlib"
|
||||
local -x RUSTFLAGS="-C prefer-dynamic -L ${CARGO_TARGET_DIR}/${RUST_TARGET}/release/deps -Z force-unstable-if-unmarked"
|
||||
|
||||
# build the std lib, which also builds all the other important libraries
|
||||
# (core, collections, etc). build it for the target we want for this build.
|
||||
# also make sure that the jemalloc libraries are included.
|
||||
local -a features=( $(usex debug debug-jemalloc jemalloc) panic-unwind )
|
||||
cargo build -p std -v $(usex debug '' --release) \
|
||||
cargo build -p std -v --lib $(usex debug '' --release) \
|
||||
--features "${features[*]}" \
|
||||
--manifest-path src/libstd/Cargo.toml \
|
||||
--target "${RUST_TARGET}"
|
||||
--target "${RUST_TARGET}" || die
|
||||
|
||||
cargo build -p term -v --lib $(usex debug '' --release) \
|
||||
--manifest-path src/libterm/Cargo.toml \
|
||||
--target "${RUST_TARGET}" || die
|
||||
|
||||
cargo build -p proc_macro -v --lib $(usex debug '' --release) \
|
||||
--manifest-path src/libproc_macro/Cargo.toml \
|
||||
--target "${RUST_TARGET}" || die
|
||||
|
||||
# Correct the directory name prior to installing it.
|
||||
mv "${T}/target/${RUST_TARGET}/release/deps" "${T}/target/${RUST_TARGET}/release/lib"
|
||||
mv "${CARGO_TARGET_DIR}/${RUST_TARGET}/release/deps" "${CARGO_TARGET_DIR}/${RUST_TARGET}/release/lib"
|
||||
}
|
||||
|
||||
src_install() {
|
@ -33,13 +33,6 @@ coreos-cargo_src_unpack() {
|
||||
|
||||
[[ ${CBUILD:-${CHOST}} != ${CHOST} ]] || return 0
|
||||
|
||||
# Define the cross-compilers for rust-gcc commands.
|
||||
export TARGET_AR="$(tc-getAR)"
|
||||
export TARGET_CC="$(tc-getCC)"
|
||||
export TARGET_CFLAGS="${CFLAGS}"
|
||||
export TARGET_CXX="$(tc-getCXX)"
|
||||
export TARGET_CXXFLAGS="${CXXFLAGS}"
|
||||
|
||||
# Map the SDK host triplet to one that is built into rustc.
|
||||
function rust_builtin_target() case "$1" in
|
||||
aarch64-*-linux-gnu) echo aarch64-unknown-linux-gnu ;;
|
||||
@ -47,22 +40,47 @@ coreos-cargo_src_unpack() {
|
||||
*) die "Unknown host triplet: $1" ;;
|
||||
esac
|
||||
|
||||
# Allow searching host libraries when targeting incompatible systems.
|
||||
export RUST_TARGET=$(rust_builtin_target "${CHOST}")
|
||||
local build_triplet=$(rust_builtin_target "${CBUILD}")
|
||||
[[ ${RUST_TARGET} = ${build_triplet} ]] ||
|
||||
local crossflags="-L /usr/lib64/rustlib/${build_triplet}/lib"
|
||||
# Set the gcc-rs flags for cross-compiling.
|
||||
export TARGET_CFLAGS="${CFLAGS}"
|
||||
export TARGET_CXXFLAGS="${CXXFLAGS}"
|
||||
|
||||
# Create a compiler wrapper to work around rust-lang/cargo#4456.
|
||||
if [[ ${CATEGORY}/${PN} != dev-libs/rustlib ]]; then
|
||||
cat <<- EOF > "${T}/wrustc" && chmod 0755 "${T}/wrustc"
|
||||
# Wrap ar for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_AR="${T}/rustproof-ar"
|
||||
cat <<- EOF > "${TARGET_AR}" && chmod 0755 "${TARGET_AR}"
|
||||
#!/bin/sh
|
||||
exec rustc --sysroot="${ROOT:-/}usr" ${crossflags-} "\$@"
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getAR) "\$@"
|
||||
EOF
|
||||
|
||||
# Wrap gcc for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_CC="${T}/rustproof-cc"
|
||||
cat <<- EOF > "${TARGET_CC}" && chmod 0755 "${TARGET_CC}"
|
||||
#!/bin/sh
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getCC) "\$@"
|
||||
EOF
|
||||
|
||||
# Wrap g++ for gcc-rs to work around rust-lang/cargo#4456.
|
||||
export TARGET_CXX="${T}/rustproof-cxx"
|
||||
cat <<- EOF > "${TARGET_CXX}" && chmod 0755 "${TARGET_CXX}"
|
||||
#!/bin/sh
|
||||
unset LD_LIBRARY_PATH
|
||||
exec $(tc-getCXX) "\$@"
|
||||
EOF
|
||||
|
||||
# Create a compiler wrapper that uses a sysroot for cross-compiling.
|
||||
export RUSTC_WRAPPER="${T}/wrustc"
|
||||
cat <<- 'EOF' > "${RUSTC_WRAPPER}" && chmod 0755 "${RUSTC_WRAPPER}"
|
||||
#!/bin/bash -e
|
||||
rustc=${1:?Missing rustc command}
|
||||
shift
|
||||
xflags=()
|
||||
[ "x$*" = "x${*#--target}" ] || xflags=( --sysroot="${ROOT:-/}usr" )
|
||||
exec "${rustc}" "${xflags[@]}" "$@"
|
||||
EOF
|
||||
export RUSTC="${T}/wrustc"
|
||||
fi
|
||||
|
||||
# Compile for the built-in target, using the SDK cross-tools.
|
||||
export RUST_TARGET=$(rust_builtin_target "${CHOST}")
|
||||
cat <<- EOF >> "${ECARGO_HOME}/config"
|
||||
|
||||
[build]
|
||||
|
Loading…
x
Reference in New Issue
Block a user