Scripts for bootstrapping various programming languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
2.2 KiB

#!/bin/sh
set -eu
# From: https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/eclass/multiprocessing.eclass
makeopts_jobs() {
# This assumes the first .* will be more greedy than the second .*
# since POSIX doesn't specify a non-greedy match (i.e. ".*?").
local jobs=$(echo " $MAKEFLAGS " | sed -r -n \
-e 's:.*[[:space:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
-e 's:.*[[:space:]](-j|--jobs)[[:space:]].*:999:p')
echo ${jobs:-1}
}
version_mrustc=0.10.1
version_mrustc_rust=1.29.0
VERSION_GIT_FULLHASH="2a9ab55bbaa706544858ab0968180e665fe7ff4a"
VERSION_GIT_SHORTHASH="2a9ab55"
VERSION_GIT_BRANCH="v$version_mrustc"
dir_download="$PWD/download"
dir_patches="$PWD/patches"
mkdir -p build; cd build
dir_install="$PWD/install-rustc-$version_mrustc_rust"
# Prepare source
tar xf "$dir_download/mrustc-$version_mrustc.tar.gz"
cd "mrustc-$version_mrustc"
sed -i -e 's/$(shell git show --pretty=%H -s --no-show-signature)/'"$VERSION_GIT_FULLHASH"'/g' \
-e 's/$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)/'"$VERSION_GIT_BRANCH"'/g' \
-e 's/$(shell git show -s --pretty=%h --no-show-signature)/'"$VERSION_GIT_SHORTHASH"'/g' \
-e 's/$(shell git diff-index --quiet HEAD; echo $$?)/0/g' \
Makefile
sed -i -e 's/ -g\>//' Makefile tools/common/Makefile tools/minicargo/Makefile
sed -i -e '/args.push_back("-g");/d' tools/minicargo/build.cpp
export RUSTC_VERSION="$version_mrustc_rust"
export MRUSTC_TARGET_VER="${version_mrustc_rust%.*}"
cp "$dir_download/rustc-$version_mrustc_rust-src.tar.xz" .
touch "rustc-$version_mrustc_rust-src.tar.gz"
make RUSTC_SRC_TARBALL="rustc-$version_mrustc_rust-src.tar.xz" RUSTCSRC
# Build and install
export PKG_CONFIG_PATH="$PWD/../install-openssl/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export CMAKE_GENERATOR='Unix Makefiles'
export PARLEVEL="$(makeopts_jobs)"
make
make -f minicargo.mk "rustc-$version_mrustc_rust-src/build/bin/llvm-config"
make -f minicargo.mk
make -C run_rustc
cp -a run_rustc/output/prefix "$dir_install"
cat > "$dir_install/bin/rustc" << EOF
#!/bin/sh
d="\$(dirname "\$0")"
LD_LIBRARY_PATH="$dir_install/lib:$dir_install/lib/rustlib/$(uname -m)-unknown-linux-gnu/lib" "\$d/rustc_binary" "\$@"
EOF