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 | # shellcheck shell=bash |
| 2 | # Helpers shared by bench.sh, bench-compile.sh, stress.sh and ci.sh. |
| 3 | # Sourced, not run; the caller has `cd`'d to the repository root. |
| 4 | |
| 5 | # Faster links with mold when it is installed (runners may lack it). |
| 6 | # Target-scoped, never a global RUSTFLAGS: a global one makes cargo ignore |
| 7 | # CARGO_TARGET_<triple>_RUSTFLAGS, which the aarch64 lane's lld/sysroot |
| 8 | # flags need (found by WS-BC). LOUISE_NO_MOLD=1 opts out. |
| 9 | # Scripts that set their own global RUSTFLAGS for a --target build |
| 10 | # (runtime.sh's lto archive, tsan.sh, the loom lane) go through |
| 11 | # without_mold: the scoped var would shadow their flags otherwise. |
| 12 | LOUISE_MOLD_FLAGS="" |
| 13 | if [ "${LOUISE_NO_MOLD:-0}" != 1 ] && command -v mold >/dev/null; then |
| 14 | LOUISE_MOLD_FLAGS="-C link-arg=-fuse-ld=mold" |
| 15 | LOUISE_MOLD_VAR="CARGO_TARGET_$(rustc -vV | sed -n 's/^host: //p' | tr 'a-z-.' 'A-Z__')_RUSTFLAGS" |
| 16 | if [ -z "${!LOUISE_MOLD_VAR:-}" ]; then export "$LOUISE_MOLD_VAR=$LOUISE_MOLD_FLAGS"; fi |
| 17 | export LOUISE_MOLD_VAR |
| 18 | fi |
| 19 | export LOUISE_MOLD_FLAGS |
| 20 | |
| 21 | # without_mold CMD... — CMD builds with its own RUSTFLAGS for a --target: |
| 22 | # run it with the scoped mold var cleared (its own flags then apply). |
| 23 | without_mold() { |
| 24 | if [ -n "${LOUISE_MOLD_VAR:-}" ]; then env -u "$LOUISE_MOLD_VAR" "$@"; else "$@"; fi |
| 25 | } |
| 26 | |
| 27 | # heavy CMD... — on a shared host (LOUISE_CI_SHARED_HOST=1), run heavy lanes |
| 28 | # one at a time per machine, niced; ci.sh uses this, and standalone scripts |
| 29 | # source lib.sh to get it. |
| 30 | heavy() { |
| 31 | if [ "${LOUISE_CI_SHARED_HOST:-0}" = 1 ]; then flock /tmp/louise-ci-heavy.lock nice -n 10 "$@"; else "$@"; fi |
| 32 | } |
| 33 | |
| 34 | # The compiler and runtime the scripts build programs with, in the Cargo |
| 35 | # profile LOUISE_PROFILE names: `release` (the default) or `dist`, the |
| 36 | # toolchain's release builds (issue gabla108/louise#120). `louise` finds the runtime next |
| 37 | # to itself, so both come from one profile. |
| 38 | LOUISE_PROFILE="${LOUISE_PROFILE:-release}" |
| 39 | # A prebuilt compiler (a container mounts one), with its runtime archive |
| 40 | # next to it: set LOUISE_BIN to it and the build is skipped. |
| 41 | louise_prebuilt=0 |
| 42 | if [ -n "${LOUISE_BIN:-}" ]; then |
| 43 | louise_prebuilt=1 |
| 44 | else |
| 45 | LOUISE_BIN="target/$LOUISE_PROFILE/louise" |
| 46 | fi |
| 47 | build_release_louise() { |
| 48 | [ "$louise_prebuilt" = 1 ] && return |
| 49 | cargo build --quiet --profile "$LOUISE_PROFILE" -p louise -p louise_rt |
| 50 | # The `fast` archive release builds link (ADR 0031). |
| 51 | scripts/runtime.sh "$LOUISE_PROFILE" |
| 52 | } |
| 53 | |
| 54 | # The output a test program expects: its `//>` lines (format: |
| 55 | # tests/README.md). |
| 56 | expected_output() { |
| 57 | sed -n 's|^//> \{0,1\}||p' "$1" |
| 58 | } |
| 59 | |
| 60 | # A table of results, one row per measurement in milliseconds, that the |
| 61 | # benchmarks save (`--save FILE`) or compare with saved results |
| 62 | # (`--compare FILE`): |
| 63 | # |
| 64 | # table_start MODE FILE WIDTH TITLE RESULTS # print the header |
| 65 | # table_row NAME MS # print a row, record it in RESULTS |
| 66 | # table_end # with --save, copy RESULTS to FILE |
| 67 | table_start() { |
| 68 | table_mode=$1 table_file=$2 table_width=$3 table_results=$5 |
| 69 | declare -gA table_baseline=() |
| 70 | if [ "$table_mode" = --compare ]; then |
| 71 | while read -r name ms; do table_baseline[$name]=$ms; done < "$table_file" |
| 72 | fi |
| 73 | : > "$table_results" |
| 74 | printf "%-${table_width}s %9s" "$4" ms |
| 75 | if [ "$table_mode" = --compare ]; then printf ' %9s %8s' before change; fi |
| 76 | printf '\n' |
| 77 | } |
| 78 | |
| 79 | table_row() { |
| 80 | local name=$1 best=$2 |
| 81 | echo "$name $best" >> "$table_results" |
| 82 | printf "%-${table_width}s %9d" "$name" "$best" |
| 83 | if [ "$table_mode" = --compare ] && [ -n "${table_baseline[$name]:-}" ]; then |
| 84 | local before=${table_baseline[$name]} |
| 85 | printf ' %9d %7d%%' "$before" $(((best - before) * 100 / (before > 0 ? before : 1))) |
| 86 | fi |
| 87 | printf '\n' |
| 88 | } |
| 89 | |
| 90 | table_end() { |
| 91 | if [ "$table_mode" = --save ]; then cp "$table_results" "$table_file"; fi |
| 92 | } |