louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#88 · main · 15 min 30 s
0Étoiles
0Forks
40Issues
| 1 | #!/usr/bin/env bash |
| 2 | # The runtime archives a release build links (ADR 0031, ADR 0032), next to |
| 3 | # `louise` in target/<dir>/, where `louise build` looks for them: |
| 4 | # |
| 5 | # liblouise_rt.a checked: what `cargo build -p louise_rt` makes, with |
| 6 | # the leak oracle; debug builds, tests, LOUISE_LEAKS |
| 7 | # liblouise_rt-fast.a fast: the `runtime` profile (whole-program LTO, one |
| 8 | # codegen unit, panic = abort), no leak oracle; |
| 9 | # release builds |
| 10 | # liblouise_rt-lto.a lto: fast, as LLVM bitcode, for cross-language |
| 11 | # ThinLTO with the program's C; release builds when |
| 12 | # clang and ld.lld can read it. Its LLVM version is |
| 13 | # in liblouise_rt-lto.llvm. Built only when clang, |
| 14 | # ld.lld and llvm-ar are on PATH. |
| 15 | # |
| 16 | # scripts/runtime.sh [DIR] # DIR: target/DIR (default: $LOUISE_PROFILE, |
| 17 | # # else release; `debug` for a dev build) |
| 18 | # |
| 19 | # The fast and lto archives are built with Rust's std rebuilt without its |
| 20 | # `backtrace` feature (ADR 0042): Rust panics in the runtime keep their |
| 21 | # message and lose the backtrace, and programs are about 40% smaller. The |
| 22 | # same compiler rebuilds it, so the lto archive's LLVM stays the system |
| 23 | # lld's; `-Zbuild-std` is unstable, hence RUSTC_BOOTSTRAP=1 for that build |
| 24 | # only. Without rust-src (rust-toolchain.toml lists it) the archives use |
| 25 | # the prebuilt std, as before; so does LOUISE_SMALL_STD=0. |
| 26 | set -euo pipefail |
| 27 | cd "$(dirname "$0")/.." |
| 28 | dir="target/${1:-${LOUISE_PROFILE:-release}}" |
| 29 | mkdir -p "$dir" |
| 30 | # Copied only when it changed: its modification time is part of what a |
| 31 | # skipped build checks (ADR 0025 Revision 1). |
| 32 | install_if_changed() { |
| 33 | if ! cmp -s "$1" "$2"; then |
| 34 | cp "$1" "$2" |
| 35 | fi |
| 36 | } |
| 37 | host="$(rustc -vV | sed -n 's/^host: //p')" |
| 38 | small=() |
| 39 | cargo_small=(cargo) |
| 40 | sysroot="$(rustc --print sysroot)" |
| 41 | if [ "${LOUISE_SMALL_STD:-1}" != 0 ] && [ -d "$sysroot/lib/rustlib/src/rust/library" ]; then |
| 42 | cargo_small=(env RUSTC_BOOTSTRAP=1 cargo) |
| 43 | # shellcheck disable=SC2054 # one flag, whose value lists crates |
| 44 | small=(--target "$host" -Zbuild-std=std,panic_abort -Zbuild-std-features=) |
| 45 | fi |
| 46 | "${cargo_small[@]}" build --quiet --profile runtime -p louise_rt --no-default-features --features mimalloc,tls,crypto \ |
| 47 | --target-dir target/fast "${small[@]}" |
| 48 | if [ ${#small[@]} -gt 0 ]; then |
| 49 | install_if_changed "target/fast/$host/runtime/liblouise_rt.a" "$dir/liblouise_rt-fast.a" |
| 50 | else |
| 51 | install_if_changed target/fast/runtime/liblouise_rt.a "$dir/liblouise_rt-fast.a" |
| 52 | fi |
| 53 | |
| 54 | if ! command -v clang >/dev/null || ! command -v ld.lld >/dev/null || ! command -v llvm-ar >/dev/null; then |
| 55 | echo "runtime.sh: no clang, ld.lld or llvm-ar: not building liblouise_rt-lto.a" >&2 |
| 56 | rm -f "$dir/liblouise_rt-lto.a" "$dir/liblouise_rt-lto.llvm" |
| 57 | exit 0 |
| 58 | fi |
| 59 | # The newest LLVM in the archive: rustc's, or clang's for mimalloc. A |
| 60 | # linker reads bitcode of its own version or older: an older one links the |
| 61 | # fast archive instead (ADR 0032). |
| 62 | rust_llvm="$(rustc -vV | sed -n 's/^LLVM version: \([0-9]*\).*/\1/p')" |
| 63 | clang_llvm="$(clang --version | sed -n 's/.*clang version \([0-9]*\).*/\1/p' | head -1)" |
| 64 | llvm=$(( rust_llvm > clang_llvm ? rust_llvm : clang_llvm )) |
| 65 | var="${host//-/_}" |
| 66 | # Bitcode from rustc (-Clinker-plugin-lto) and from clang for mimalloc's C. |
| 67 | # `--target` keeps the flags off build scripts, which are linked as usual; |
| 68 | # its own target directory keeps the other builds' artifacts. |
| 69 | env RUSTFLAGS="-Clinker-plugin-lto" \ |
| 70 | "CC_$var=clang" "CFLAGS_$var=-flto=thin" "AR_$var=llvm-ar" \ |
| 71 | "${cargo_small[@]}" build --quiet --profile runtime-lto --target "$host" --target-dir target/lto \ |
| 72 | -p louise_rt --no-default-features --features mimalloc,tls,crypto "${small[@]:2}" |
| 73 | install_if_changed "target/lto/$host/runtime-lto/liblouise_rt.a" "$dir/liblouise_rt-lto.a" |
| 74 | echo "$llvm" > "target/lto/llvm" |
| 75 | install_if_changed target/lto/llvm "$dir/liblouise_rt-lto.llvm" |