Files
BMLFS/build-scripts/rustc.build

136 lines
5.0 KiB
Bash

#! /bin/bash
# Rustc
# Source: https://static.rust-lang.org/dist/rustc-1.58.1-src.tar.gz
#
# v1.58.1 = Succeeds to build with musl patched scheduler functions & rustup toolchain
# v1.46.0 = failed, both Alpine & Void methods due to precompiled rustc & cargo
# v1.45.1 = Succeeds with alpine method, requires max libressl-3.0.0
#
# $BUILD = Directory to temporarily install
# $PKGS = Directory to store built packages
#
# DEPS
# Required: cURL, CMake, libssh2, libgit2
# Recommended: LLVM
# Optional: GDB
#
# Tested architectures:
# [ PASS ] aarch64-alpine-linux-musl (1.58.1)
# [ Pending ] x86_64-linux-musl (1.58.1)
# [ Pending ] i686-unknown-linux-musl
#
# *** NOTE ***
# This build needs precompiled Cargo and Rust, from rustup, to bootstrap build
# Rust can be build but fails to install at this time.
# **To see targets supported by downloaded rust toolchain from rustup, use rustc --print-target-list**
case $(uname -m) in
x86_64) export TUPLE="x86_64-unknown-linux-musl"
export ECONFIG="--musl-root-x86_64=/usr"
;;
i686*) export TUPLE="i686-unknown-linux-musl"
export ECONFIG="--musl-root-i686=/usr"
;;
armv6*) export TUPLE="armv6-unknown-linux-musl"
export ECONFIG="--musl-root-armv6=/usr"
;;
armv7*) export TUPLE="armv7-unknown-linux-musleabihf"
export ECONFIG="--musl-root-armv7=/usr"
;;
aarch64) export TUPLE="aarch64-unknown-linux-musl"
export ECONFIG="--musl-root-aarch64=/usr"
;;
esac
# Downlaod and install [pre-built] rust-toolchain.
# Select full install. Make sure toolchain is added to $PATH
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
export rtools=~/.cargo # make sure its a full path.
# Apply patches from Alpine Linux
patch -Np1 -i ../patches/rustc-alpine/alpine-move-py-scripts-to-share.patch
patch -Np1 -i ../patches/rustc-alpine/alpine-target.patch
patch -Np1 -i ../patches/rustc-alpine/install-template-shebang.patch
patch -Np1 -i ../patches/rustc-alpine/link-musl-dynamically.patch
patch -Np1 -i ../patches/rustc-alpine/musl-fix-linux_musl_base.patch
patch -Np1 -i ../patches/rustc-alpine/need-rpath.patch
patch -Np1 -i ../patches/rustc-alpine/need-ssp_nonshared.patch
export RUST_BACKTRACE=1
sed -i /LD_LIBRARY_PATH/d src/bootstrap/bootstrap.py
# to dynamically link against musl
sed -i 's/\("files":{\)[^}]*/\1/' vendor/libc/.cargo-checksum.json
export CARGS="--build=$TUPLE "
export CARGS+="--host=$TUPLE "
export CARGS+="--target=$TUPLE "
export CARGS+="--prefix=/usr "
export CARGS+="--release-channel=stable "
export CARGS+="--enable-local-rust "
export CARGS+="--local-rust-root=$rtools "
export CARGS+="--llvm-root=/usr "
export CARGS+="--disable-docs "
export CARGS+="--enable-extended "
export CARGS+="--tools=\"analysis,cargo\" "
export CARGS+="--enable-llvm-link-shared "
export CARGS+="--enable-option-checking "
export CARGS+="--enable-locked-deps "
export CARGS+="--enable-vendor "
export CARGS+="--python=python3 "
export CARGS+="--set=\"rust.musl-root=/usr\" "
export CARGS+="--set=\"rust.codegen-units=1\" "
export CARGS+="--set=\"target.${TRUPLE}.llvm-config=/usr/bin/llvm-config\" "
export CARGS+="--set=\"target.${TRUPLE}.musl-root=/usr\" "
export CARGS+="--set=\"target.${TRUPLE}.crt-static=false\" "
./configure $CARGS $ECONFIG && \
# Allow warnings instead of just aborting the build
sed 's/#deny-warnings = .*/deny-warnings = false/' -i config.toml
sed 's|deny(warnings,|deny(|' -i src/bootstrap/lib.rs
# Build
read -p "Compile?" &&
python3 ./x.py build --jobs 4 &&
read -p "Install?" &&
# If not using any package manager:
#sudo -E -S DESTDIR=${PWD}/install python3 ./x.py install
#chown -R root:root install
#cp -a install/* /
# Make install target fails...install in build directory then copy over to ${BUILD}
#DESTDIR=${PWD}/install python3 ./x.py install
#sudo -S chown -R root:root install
#sudo -S cp -ar install/* ${BUILD}/
# ... still fails. Manually copy files over
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: rust (a safe, concurrent, practical language)
rustc:
rustc: Rust is a curly-brace, block-structured expression language.
rustc: Its design is oriented toward concerns of "programming in the large",
rustc: that is, of creating and maintaining boundaries - both abstract and
rustc: operational - that preserve large-system integrity, availability,
rustc: and concurrency.
rustc:
rustc: Homepage: https://rust-lang.org
rustc:
rustc:
EOF
sudo -S mv -v /tmp/slack-desc install/ &&
sudo -S makepkg -l y -c n $PKGS/rustc-1.58.1-$(uname -m)-mlfs.txz &&
sudo -S rm -rf ${BUILD}/*