Files
BMLFS/build-scripts/rustc.cmlfs.build
dslm4515 394686c14d Upgraded rustc (for CMLFS) from 1.73.0 to 1.74.0
A full rustc build now fails after building stage 2 compiler & standard libray. The built stage 2 compiler & libray can be installed as rustc-tiny. Rustc-tiny can then be used to complete the full build of rustc.
2023-12-31 23:23:11 -06:00

121 lines
5.1 KiB
Bash

#! /bin/bash
# rustc (for CMLFS-based systems)
# Source: https://static.rust-lang.org/dist/rustc-1.74.0-src.tar.xz
#
# $BUILD = Directory to temporarily install
# $PKGS = Directory to store built packages
#
# DEPS
# Required: cargo rustc-tiny libffi libxml2 curl cmake
# Recommended: NONE
# Optional: patchelf
#
# NOTE: Rustc fails to build beyound stage 2 with rustc-bootstrap.
# Stage 2 compiler & std library (rustc-tiny) from failed build
# can be used to complete this build
# Apply patches from Chimera Linux
patch -Np1 -i ../patches/rust-1.74.0-chimera/0001-add-chimera-targets-always-dynamic-musl-static-pie.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0002-remove-a-bunch-of-unused-junk.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0003-move-debugger-scripts-to-usr-share-rust.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0004-fix-shebang-on-install-template.sh.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0005-get-rid-of-wrong-linkage.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0006-do-not-install-libunwind-source-removed.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0007-fix-rustdoc-when-cross-compiling.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0008-link-stage-2-tools-dynamically-to-libstd.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0009-use-CBUILD_TARGET_SYSROOT-to-locate-llvm-when-cross-.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0010-do-not-export-LD_LIBRARY_PATH.patch
patch -Np1 -i ../patches/rust-1.74.0-chimera/0011-drop-latomic-on-riscv-and-elsewhere.patch
export OPENSSL_NO_VENDOR=1 RUST_BACKTRACE=1
export BOOTSTRAP=0
export RUSTFLAGS="" PKG_CONFIG_ALLOW_CROSS=1
# Set cargo variables?
export HOST_CC="clang" HOST_CFLAGS="-O2" ZSTD_SYS_USE_PKG_CONFIG=1
export PCRE2_SYS_STATIC=0 LIBSSH2_SYS_USE_PKG_CONFIG=1
export LIBGIT2_NO_VENDOR=1 CARGO_BUILD_JOBS=2 CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export PKG_CONFIG_ALLOW_CROSS=1
# Using patches from Chimera Linux introduces required variables
# Not sure if omitting patch 0009 is a good idea. For now:
export CBUILD_TARGET_SYSROOT="/"
# Don't use bundled llvm, not patched for musl
rm -rf src/llvm-project
# Clear vendor checksums
for d in libc libc-0.2.138 libc-0.2.140 libc-0.2.146
do
sed -i 's/\("files":{\)[^}]*/\1/' vendor/$d/.cargo-checksum.json
done
# Compiling will invoke c++ instead of g++ or clang++
sudo ln -sv clang-15 /usr/bin/c++
# Configure scripts seem to always fail. Use a config.toml instead.
# Copy build config. Make sure target, host, and build are all set to x86_64-unknown-linux-musl
cp -v ../files/config.toml.rustc config.toml
# Make sure cargo & rustc-bootstrap are in PATH
export PATH=/opt/rustc/bin:$PATH
# Build & pack up as a distributive archive
env -u $PKGCONFIG -- python3 ./x.py dist -v --jobs 2
# Unpack to "install' to staging area
sudo mkdir /TBUILD
sudo tar xf build/dist/rustc-1.73.0-x86_64-chimera-linux-musl.tar.xz -C /TBUILD
sudo tar xf build/dist/rust-std-1.74.0-x86_64-unknown-linux-musl.tar.xz -C /TBUILD
sudo tar xf build/dist/rustc-dev-1.74.0-x86_64-unknown-linux-musl.tar.xz -C /TBUILD
sudo tar xf build/dist/rust-src-1.74.0.tar.xz -C /TBUILD
# Install rustc & rust-std to staging area
cd /TBUILD/rustc-1.74.0-x86_64-unknown-linux-musl/
sudo ./install.sh --destdir=$BUILD --prefix=/opt/rustc-1.74.0
cd /TBUILD/rust-std-1.74.0-x86_64-unknown-linux-musl/
sudo ./install.sh --destdir=$BUILD --prefix=/opt/rustc-1.74.0
cd /TBUILD/rustc-dev-1.74.0-x86_64-unknown-linux-musl/
cd /TBUILD/rust-src-1.74.0/
sudo ./install.sh --destdir=$BUILD --prefix=/opt/rustc-1.74.0
sudo ln -sv rustc-1.74.0 $BUILD/opt/rustc
# Set runtime path
sudo patchelf --set-rpath /opt/rustc-1.74.0/lib $BUILD/opt/rustc-1.74.0/bin/rustc
sudo patchelf --set-rpath /opt/rustc-1.74.0/lib $BUILD/opt/rustc-1.74.0/lib/librustc_driver-*
# Clean up
sudo rm -v /usr/bin/c++
unset OPENSSL_NO_VENDOR RUST_BACKTRACE BOOTSTRAP rlib_dir
unset HOST_CC HOST_CFLAGS ZSTD_SYS_USE_PKG_CONFIG
unset LIBGIT2_NO_VENDOR CARGO_BUILD_JOBS CARGO_PROFILE_RELEASE_CODEGEN_UNITS
unset PKG_CONFIG_ALLOW_CROSS CBUILD_TARGET_SYSROOT
# Remove clutter
sudo rm -v $BUILD/opt/rustc-1.74.0/lib/rustlib/manifest-*
sudo rm -v $BUILD/opt/rustc-1.74.0/lib/rustlib/{components,uninstall.sh,install.log,rust-installer-version}
cd $BUILD && sudo -S mkdir -v ${BUILD}/install &&
cat > /tmp/slack-desc << "EOF"
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
rustc: rustc
rustc:
rustc: Rust is a curly-brace, block-structured expression language.
rustc: Includes rust-std and rustc. Requires cargo.
rustc:
rustc: Homepage: https://rust-lang.org
rustc:
EOF
sudo -S mv -v /tmp/slack-desc install/ &&
sudo -S makepkg -l y -c n $PKGS/rustc-1.74.0-$PSUFFIX &&
sudo -S rm -rf ${BUILD}/*