repo/extra/rust/build

131 lines
3.3 KiB
Plaintext
Raw Normal View History

2019-07-21 09:11:03 +00:00
#!/bin/sh -e
2023-03-02 14:40:00 +00:00
export DESTDIR="$1"
2023-10-10 18:08:03 +00:00
patch -p1 < fix-curl.patch
2023-08-26 17:45:25 +00:00
# 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=."
2021-06-30 23:46:09 +00:00
# Set shared linking as the default.
2022-04-08 08:26:54 +00:00
sed 's/\(crt_static_default = \)true/\1false/' \
compiler/rustc_target/src/spec/linux_musl_base.rs > _
mv -f _ compiler/rustc_target/src/spec/linux_musl_base.rs
2021-06-30 23:46:09 +00:00
2023-08-26 17:45:25 +00:00
sed 's/\("files":{\)[^}]*/\1/' vendor/curl-sys/.cargo-checksum.json > _
mv -f _ vendor/curl-sys/.cargo-checksum.json
2019-07-21 09:11:03 +00:00
2019-08-24 20:34:01 +00:00
cat > config.toml <<EOF
[llvm]
link-shared = true
[build]
2020-10-09 08:55:38 +00:00
build = "x86_64-unknown-linux-musl"
host = [ "x86_64-unknown-linux-musl" ]
target = [ "x86_64-unknown-linux-musl" ]
2020-02-27 20:05:15 +00:00
docs = false
compiler-docs = false
extended = true
submodules = false
python = "python3"
locked-deps = true
vendor = true
2021-09-03 15:04:27 +00:00
tools = [ "cargo", "rustfmt" ]
2020-02-27 20:05:15 +00:00
sanitizers = false
profiler = false
full-bootstrap = false
EOF
2022-11-03 18:02:34 +00:00
# If possible, use system rust to bootstrap.
2022-07-06 03:20:59 +00:00
maj="${2%%.*}"
min="${2%.*}"
min="${min#*.}"
2022-11-03 18:02:34 +00:00
# Fall back to vendor binaries if rustc, et al are not present, or if one of
# them suffered ABI breakage.
2022-07-06 03:20:59 +00:00
rust_version=$(rustc --version 2>/dev/null) || rust_version=null
2022-11-03 18:02:34 +00:00
cargo --version 2>/dev/null || rust_version=null
rustfmt --version 2>/dev/null || rust_version=null
2022-07-06 03:20:59 +00:00
rust_version="${rust_version#rustc }"
case "$rust_version" in
2022-07-19 16:02:00 +00:00
"$maj.$min".*|"$maj.$((min - 1))".*)
cat >> config.toml <<EOF
cargo = "/usr/bin/cargo"
rustc = "/usr/bin/rustc"
rustfmt = "/usr/bin/rustfmt"
EOF
;;
*)
# This mimics the download process of rust's 'x.py'
# bootstrap library to allow for the removal of the internet
# connection requirement per build.
2023-10-23 23:04:39 +00:00
mkdir -p "${cache_dir:=build/cache/2023-08-24}"
for tarball in *.tar.xz\?no-extract; do
mv -f "$tarball" "$cache_dir/${tarball%%\?no-extract}"
done
;;
esac
cat >> config.toml <<EOF
2019-08-24 20:34:01 +00:00
[install]
prefix = "/usr"
[target.x86_64-unknown-linux-musl]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
sanitizers = false
2021-09-03 06:55:25 +00:00
[dist]
src-tarball = false
2019-08-24 20:34:01 +00:00
[rust]
backtrace = false
2020-10-09 08:55:38 +00:00
channel = "stable"
codegen-tests = false
2021-09-03 15:04:27 +00:00
codegen-units-std = 1
2021-09-03 06:55:25 +00:00
codegen-units = 0
2020-10-09 08:55:38 +00:00
debug = false
debug-assertions = false
debuginfo-level = 0
incremental = false
jemalloc = false
rpath = false
2021-09-03 06:55:25 +00:00
dist-src = false
2019-08-24 20:34:01 +00:00
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.
2022-03-28 10:46:10 +00:00
libunwind_path=$("$CC" -print-file-name=libunwind.so)
case $libunwind_path in */*)
printf 'llvm-libunwind = "system"\n' >> config.toml
mkdir -p libgcc
printf 'INPUT(-lunwind)\n' > \
libgcc/libgcc_s.so
2022-03-28 10:46:10 +00:00
ln -sf "$libunwind_path" \
libgcc/libgcc_s.so.1
export \
LD_LIBRARY_PATH="$PWD/libgcc:$LD_LIBRARY_PATH" \
LIBRARY_PATH="$PWD/libgcc:$LIBRARY_PATH"
esac
2022-09-22 19:48:03 +00:00
python x.py build -j "$(grep -scF 'core id' /proc/cpuinfo)"
python x.py install
2020-05-05 21:56:59 +00:00
2021-07-06 13:03:16 +00:00
rm -rf \
"$1/usr/lib/rustlib/src/" \
"$1/usr/share/doc" \
"$1/usr/share/zsh" \
"$1/usr/lib/rustlib/uninstall.sh"