Files
BMLFS/build-scripts/rustc-i686.build

174 lines
5.9 KiB
Bash

#! /bin/bash
# Rustc for i686
# Source: https://static.rust-lang.org/dist/rustc-1.45.1-src.tar.gz
# Method: Alpine Linux
#
# $BUILD = Directory to temporarily install
# $PKGS = Directory to store built packages
#
# DEPS
# Required: cURL, CMake, libssh2, libgit2
# Recommended: LLVM
# Optional: GDB
# *** NOTE ***
# This build needs precompiled Cargo and Rust to bootstrap build.
# Precompiled binaries and libraries are from Alpine, which has
# LLVM built with all targets like X86, ARM, etc.
#
# Bootstrap versions:
# Cargo-1.44.0 + rust-1.44.0
# Requires OpenSSL 1.0.1 through 1.1.1, or LibreSSL 2.5 through 3.0.x
# Targets supported by this version:
# aarch64-alpine-linux-musl
# aarch64-unknown-linux-musl
# armv6-alpine-linux-musleabihf
# armv7-alpine-linux-musleabihf
# armv7-unknown-linux-musleabihf
# armv7-unknown-linux-musleabi
# i586-alpine-linux-musl
# i686-unknown-linux-musl
# x86_64-alpine-linux-musl
# x86_64-unknown-linux-musl
# **for more use rustc --print target-list**
patch -Np1 -i ../patches/rust-alpine-1.45.1/0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/alpine-move-py-scripts-to-share.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/alpine-target.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/install-template-shebang.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/link-musl-dynamically.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/musl-dont-use-crt-static.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/musl-fix-linux_musl_base.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/need-rpath.patch
patch -Np1 -i ../patches/rust-alpine-1.45.1/need-ssp_nonshared.patch
# Create bootstrap directory
mkdir -pv stage0/{tmp,bin}
cd stage0/tmp
export ARCH="x86"
wget \
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/$ARCH/cargo-1.44.0-r0.apk \
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/$ARCH/rust-stdlib-1.44.0-r0.apk \
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/$ARCH/rust-1.44.0-r0.apk
unset ARCH
## unpack to extract cargo:
tar xf cargo-1.44.0-r0.apk &&
mv -v usr/bin/cargo ../bin/ &&
rm -rvf usr .PKGINFO .SIGN.RSA.alpine-* &&
# # Unpack rust std library
tar xf rust-stdlib-1.44.0-r0.apk &&
mv -v usr/lib ../
rm -rvf usr .PKGINFO .SIGN.RSA.alpine-* &&
# # Unpack rust
tar xf rust-1.44.0-r0.apk &&
mv -v usr/bin/rustc ../bin/ &&
mv -v usr/share ../ &&
cp -r usr/lib/* ../lib/ &&
rm -rvf usr .PKGINFO .SIGN.RSA.alpine-* &&
cd ../..
# # Add compatability links for Cargo 1.44.0 from Alpine with libreSSL 3.0.0
sudo ln -sv libssl.so.47.0.6 /usr/lib/libssl.so.1.1
sudo ln -sv libcrypto.so.45.0.5 /usr/lib/libcrypto.so.1.1
# # Bootsrapping will look for musl-gcc, just link it
sudo ln -sv gcc /usr/bin/musl-gcc
# # Add bootstrap to PATH
export PATH="$PWD/stage0/bin:$PATH"
export _build="i586-alpine-linux-musl"
export _target="i686-unknown-linux-musl"
export _rlibdir="lib/rustlib/$_build/lib"
export _sharedir="share/rust"
export ldpath="/src-bmlfs/rustc-1.45.1-src/stage0/$_rlibdir"
export LD_LIBRARY_PATH="$PWD/stage0/lib:$ldpath"
export RUST_BACKTRACE=1
for f in libc;
do
sed -i 's/\("files":{\)[^}]*/\1/' vendor/$f/.cargo-checksum.json
done
sed -i /LD_LIBRARY_PATH/d src/bootstrap/bootstrap.py
rm -Rf src/llvm-project/
export CFLAGS="$CFLAGS -fno-stack-protector"
export PKG_CONFIG_ALLOW_CROSS=1
./configure \
--build="$_build" \
--host="$_target" \
--target="$_target" \
--prefix="/usr" \
--release-channel="stable" \
--enable-local-rust \
--local-rust-root="/src-bmlfs/rustc-1.45.1-src/stage0" \
--llvm-root="/usr/lib" \
--disable-docs \
--enable-extended \
--tools="analysis,cargo,src" \
--enable-llvm-link-shared \
--enable-option-checking \
--enable-locked-deps \
--enable-vendor \
--python="python3" \
--set="rust.musl-root=/usr" \
--set="target.$_target.llvm-config=/usr/bin/llvm-config" \
--set="target.$_build.musl-root=/usr" \
--set="target.$_build.crt-static=false"
ed 's/#deny-warnings = .*/deny-warnings = false/' -i config.toml
sed 's|deny(warnings,|deny(|' -i src/bootstrap/lib.rs
# ** Check config.toml for **
# llvm-config=/usr/bin/llvm-config
read -p "Build?" &&
python3 ./x.py build --jobs 2 &&
# If not using any package manager:
#sudo -E -S DESTDIR=${PWD}/install python3 ./x.py install
#chown -R root:root install
#cp -a install/* /
sudo -E -S DESTDIR="${BUILD}" python3 ./x.py install -v &&
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 (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/ &&
cd usr/lib/rustlib/ &&
rm -v components install.log manifest-* rust-installer-version uninstall.sh
cd - &&
sudo -S makepkg -l y -c n $PKGS/rustc-1.45.1-$(uname -m)-mlfs.txz &&
sudo -S rm -rf ${BUILD}/* &&
# Remove compatiblility links for build and reset environemt
sudo rm -v /usr/lib/libssl.so.1.1 /usr/lib/libcrypto.so.1.1 /usr/bin/musl-gcc &&
unset RUST_BACKTRACE CFLAGS LD_LIBRARY_PATH ARCH _sharedir &&
unset ldpath RUSTFLAGS _build _rlibdir PKG_CONFIG_ALLOW_CROSS &&
export PATH=$OLD_PATH