]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/scripts/tests.sh
Rollup merge of #99539 - compiler-errors:bidirectional-block-suggestions, r=fee1...
[rust.git] / compiler / rustc_codegen_cranelift / scripts / tests.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 export CG_CLIF_DISPLAY_CG_TIME=1
6 export CG_CLIF_DISABLE_INCR_CACHE=1
7
8 export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
9 export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE}
10
11 export RUN_WRAPPER=''
12
13 case "$TARGET_TRIPLE" in
14    x86_64*)
15       export JIT_SUPPORTED=1
16       ;;
17    *)
18       export JIT_SUPPORTED=0
19       ;;
20 esac
21
22 if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
23    export JIT_SUPPORTED=0
24    if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
25       # We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
26       export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS
27       export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
28    elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
29       # We are cross-compiling for Windows. Run tests in wine.
30       export RUN_WRAPPER='wine'
31    else
32       echo "Unknown non-native platform"
33    fi
34 fi
35
36 # FIXME fix `#[linkage = "extern_weak"]` without this
37 if [[ "$(uname)" == 'Darwin' ]]; then
38    export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
39 fi
40
41 MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
42
43 function no_sysroot_tests() {
44     echo "[BUILD] mini_core"
45     $MY_RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target "$TARGET_TRIPLE"
46
47     echo "[BUILD] example"
48     $MY_RUSTC example/example.rs --crate-type lib --target "$TARGET_TRIPLE"
49
50     if [[ "$JIT_SUPPORTED" = "1" ]]; then
51         echo "[JIT] mini_core_hello_world"
52         CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
53
54         echo "[JIT-lazy] mini_core_hello_world"
55         CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
56     else
57         echo "[JIT] mini_core_hello_world (skipped)"
58     fi
59
60     echo "[AOT] mini_core_hello_world"
61     $MY_RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target "$TARGET_TRIPLE"
62     $RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
63     # (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd
64 }
65
66 function base_sysroot_tests() {
67     echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
68     $MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target "$TARGET_TRIPLE"
69     $RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
70
71     echo "[AOT] issue_91827_extern_types"
72     $MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE"
73     $RUN_WRAPPER ./target/out/issue_91827_extern_types
74
75     echo "[BUILD] alloc_system"
76     $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
77
78     echo "[AOT] alloc_example"
79     $MY_RUSTC example/alloc_example.rs --crate-type bin --target "$TARGET_TRIPLE"
80     $RUN_WRAPPER ./target/out/alloc_example
81
82     if [[ "$JIT_SUPPORTED" = "1" ]]; then
83         echo "[JIT] std_example"
84         $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
85
86         echo "[JIT-lazy] std_example"
87         $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
88     else
89         echo "[JIT] std_example (skipped)"
90     fi
91
92     echo "[AOT] std_example"
93     $MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE"
94     $RUN_WRAPPER ./target/out/std_example arg
95
96     echo "[AOT] dst_field_align"
97     $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
98     $RUN_WRAPPER ./target/out/dst_field_align
99
100     echo "[AOT] subslice-patterns-const-eval"
101     $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
102     $RUN_WRAPPER ./target/out/subslice-patterns-const-eval
103
104     echo "[AOT] track-caller-attribute"
105     $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
106     $RUN_WRAPPER ./target/out/track-caller-attribute
107
108     echo "[AOT] float-minmax-pass"
109     $MY_RUSTC example/float-minmax-pass.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
110     $RUN_WRAPPER ./target/out/float-minmax-pass
111
112     echo "[AOT] mod_bench"
113     $MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE"
114     $RUN_WRAPPER ./target/out/mod_bench
115 }
116
117 function extended_sysroot_tests() {
118     pushd rand
119     ../build/cargo-clif clean
120     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
121         echo "[TEST] rust-random/rand"
122         ../build/cargo-clif test --workspace
123     else
124         echo "[AOT] rust-random/rand"
125         ../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests
126     fi
127     popd
128
129     pushd simple-raytracer
130     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
131         echo "[BENCH COMPILE] ebobby/simple-raytracer"
132         hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
133         "RUSTFLAGS='' cargo build" \
134         "../build/cargo-clif build"
135
136         echo "[BENCH RUN] ebobby/simple-raytracer"
137         cp ./target/debug/main ./raytracer_cg_clif
138         hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
139     else
140         ../build/cargo-clif clean
141         echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
142         echo "[COMPILE] ebobby/simple-raytracer"
143         ../build/cargo-clif build --target $TARGET_TRIPLE
144         echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
145     fi
146     popd
147
148     pushd build_sysroot/sysroot_src/library/core/tests
149     echo "[TEST] libcore"
150     ../../../../../build/cargo-clif clean
151     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
152         ../../../../../build/cargo-clif test
153     else
154         ../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests
155     fi
156     popd
157
158     pushd regex
159     echo "[TEST] rust-lang/regex example shootout-regex-dna"
160     ../build/cargo-clif clean
161     export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning
162     # Make sure `[codegen mono items] start` doesn't poison the diff
163     ../build/cargo-clif build --example shootout-regex-dna --target $TARGET_TRIPLE
164     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
165         cat examples/regexdna-input.txt \
166             | ../build/cargo-clif run --example shootout-regex-dna --target $TARGET_TRIPLE \
167             | grep -v "Spawned thread" > res.txt
168         diff -u res.txt examples/regexdna-output.txt
169     fi
170
171     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
172         echo "[TEST] rust-lang/regex tests"
173         ../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
174     else
175         echo "[AOT] rust-lang/regex tests"
176         ../build/cargo-clif build --tests --target $TARGET_TRIPLE
177     fi
178     popd
179
180     pushd portable-simd
181     echo "[TEST] rust-lang/portable-simd"
182     ../build/cargo-clif clean
183     ../build/cargo-clif build --all-targets --target $TARGET_TRIPLE
184     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
185         ../build/cargo-clif test -q
186     fi
187     popd
188 }
189
190 case "$1" in
191     "no_sysroot")
192         no_sysroot_tests
193         ;;
194     "base_sysroot")
195         base_sysroot_tests
196         ;;
197     "extended_sysroot")
198         extended_sysroot_tests
199         ;;
200     *)
201         echo "unknown test suite"
202         ;;
203 esac