2
0
mirror of https://codeberg.org/kiss-community/repo synced 2024-12-24 16:30:04 -07:00
repo/extra/rust/build
2021-10-31 08:32:17 +02:00

113 lines
2.8 KiB
Bash
Executable File

#!/bin/sh -e
patch -p1 < fix-curl.patch
# Instruct the compiler to trim absolute paths in resulting binaries and instead
# change them to relative paths ($PWD/... ./...).
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix=$PWD=."
# This package mimics the download process of rust's 'x.py'
# bootstrap library to allow for the removal of the internet
# connection requirement per build.
{
mkdir -p "${cache_dir:=build/cache/2021-09-09}"
for tarball in *.tar.xz\?no-extract; do
mv -f "$tarball" "$cache_dir/${tarball%%\?no-extract}"
done
}
# Set shared linking as the default.
for f in \
compiler/rustc_target/src/spec/linux_musl_base.rs \
vendor/rustc-ap-rustc_target/src/spec/linux_musl_base.rs
do
sed 's/\(crt_static_default = \)true/\1false/' "$f" > _
mv -f _ "$f"
done
# Ignore checksums of files modified above.
sed 's/\("files":{\)[^}]*/\1/' \
vendor/rustc-ap-rustc_target/.cargo-checksum.json > _
mv -f _ vendor/rustc-ap-rustc_target/.cargo-checksum.json
sed 's/\("files":{\)[^}]*/\1/' \
vendor/curl-sys/.cargo-checksum.json > _
mv -f _ vendor/curl-sys/.cargo-checksum.json
cat > config.toml <<EOF
[llvm]
link-shared = true
skip-rebuild = true
[build]
build = "x86_64-unknown-linux-musl"
host = [ "x86_64-unknown-linux-musl" ]
target = [ "x86_64-unknown-linux-musl" ]
docs = false
compiler-docs = false
extended = true
submodules = false
python = "python3"
locked-deps = true
vendor = true
tools = [ "cargo", "rustfmt" ]
sanitizers = false
profiler = false
full-bootstrap = false
[install]
prefix = "/usr"
[target.x86_64-unknown-linux-musl]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
sanitizers = false
[dist]
src-tarball = false
[rust]
backtrace = false
channel = "stable"
codegen-tests = false
codegen-units-std = 1
codegen-units = 0
debug = false
debug-assertions = false
debuginfo-level = 0
incremental = false
jemalloc = false
rpath = false
dist-src = false
EOF
# Workaround to get Rust to build in llvm-only environments.
# libgcc_s.so is needed for Rust's bootstrap binaries, on llvm-only systems
# this library does not exist. This hack creates it as alias to libunwind.
case $("$CC" -print-file-name=libunwind.so) in */*)
printf 'llvm-libunwind = "system"\n' >> config.toml
mkdir -p libgcc
printf 'INPUT(-lunwind)\n' > \
libgcc/libgcc_s.so
ln -sf "$KISS_ROOT/usr/lib/libunwind.so.1" \
libgcc/libgcc_s.so.1
export \
LD_LIBRARY_PATH="$PWD/libgcc:$LD_LIBRARY_PATH" \
LIBRARY_PATH="$PWD/libgcc:$LIBRARY_PATH"
esac
./x.py build -j "$(grep -scF 'core id' /proc/cpuinfo)"
./x.py install
rm -rf \
"$1/usr/lib/rustlib/src/" \
"$1/usr/share/doc" \
"$1/usr/share/zsh" \
"$1/usr/lib/rustlib/uninstall.sh"