RISC-V: Refactor Dynamic LMUL codes
[official-gcc.git] / gcc / testsuite / lib / rust.exp
blobe3c4d7ee63246ff9dd0b457baddfae59ca3e3044
1 # Copyright (C) 2012-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
18 # rust support library routines
21 load_lib prune.exp
22 load_lib gcc-defs.exp
23 load_lib timeout.exp
24 load_lib target-libpath.exp
27 # RUST_UNDER_TEST is the compiler under test.
30 set rust_compile_options ""
34 # rust_include_flags -- include flags for the gcc tree structure
37 proc rust_include_flags { paths } {
38 global srcdir
39 global TESTING_IN_BUILD_TREE
41 set flags ""
43 if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } {
44 return "${flags}"
47 set gccpath ${paths}
49 return "$flags"
53 # rust_link_flags -- linker flags for the gcc tree structure
56 proc rust_link_flags { paths } {
57 global srcdir
58 global ld_library_path
59 global RUST_UNDER_TEST
60 global shlib_ext
61 global SHARED_OPTION
63 set gccpath ${paths}
64 set libio_dir ""
65 set flags ""
66 set ld_library_path "."
67 set shlib_ext [get_shlib_extension]
68 set SHARED_OPTION ""
69 verbose "shared lib extension: $shlib_ext"
71 set_ld_library_path_env_vars
73 return "$flags"
77 # rust_init -- called at the start of each subdir of tests
80 proc rust_init { args } {
81 global subdir
82 global rust_initialized
83 global base_dir
84 global tmpdir
85 global libdir
86 global gluefile wrap_flags
87 global objdir srcdir
88 global ALWAYS_RUSTFLAGS
89 global TOOL_EXECUTABLE TOOL_OPTIONS
90 global RUST_UNDER_TEST
91 global TESTING_IN_BUILD_TREE
92 global TEST_ALWAYS_FLAGS
93 global gcc_warning_prefix
94 global gcc_error_prefix
96 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
97 setenv LC_ALL C
98 setenv LANG C
100 if ![info exists RUST_UNDER_TEST] then {
101 if [info exists TOOL_EXECUTABLE] {
102 set RUST_UNDER_TEST $TOOL_EXECUTABLE
103 } else {
104 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
105 set RUST_UNDER_TEST [transform gccrs]
106 } else {
107 set RUST_UNDER_TEST [findfile $base_dir/../../gccrs "$base_dir/../../gccrs -B$base_dir/../../" [findfile $base_dir/gccrs "$base_dir/gccrs -B$base_dir/" [transform gccrs]]]
112 if ![is_remote host] {
113 if { [which $RUST_UNDER_TEST] == 0 } then {
114 perror "RUST_UNDER_TEST ($RUST_UNDER_TEST) does not exist"
115 exit 1
119 if ![info exists tmpdir] {
120 set tmpdir "/tmp"
123 if [info exists gluefile] {
124 unset gluefile
127 rust_maybe_build_wrapper "${tmpdir}/rust-testglue.o"
129 set ALWAYS_RUSTFLAGS ""
131 # TEST_ALWAYS_FLAGS are flags that should be passed to every
132 # compilation. They are passed first to allow individual
133 # tests to override them.
134 if [info exists TEST_ALWAYS_FLAGS] {
135 lappend ALWAYS_RUSTFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
138 if ![is_remote host] {
139 if [info exists TOOL_OPTIONS] {
140 lappend ALWAYS_RUSTFLAGS "additional_flags=[rust_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
141 lappend ALWAYS_RUSTFLAGS "ldflags=[rust_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
142 } else {
143 lappend ALWAYS_RUSTFLAGS "additional_flags=[rust_include_flags [get_multilibs] ]"
144 lappend ALWAYS_RUSTFLAGS "ldflags=[rust_link_flags [get_multilibs] ]"
148 if [info exists TOOL_OPTIONS] {
149 lappend ALWAYS_RUSTFLAGS "additional_flags=$TOOL_OPTIONS"
152 lappend ALWAYS_RUSTFLAGS "additional_flags=-frust-incomplete-and-experimental-compiler-do-not-use"
154 verbose -log "ALWAYS_RUSTFLAGS set to $ALWAYS_RUSTFLAGS"
156 set gcc_warning_prefix "warning:"
157 set gcc_error_prefix "(fatal )?error:"
159 verbose "rust is initialized" 3
163 # rust_target_compile -- compile a source file
166 proc rust_target_compile { source dest type options } {
167 global tmpdir
168 global gluefile wrap_flags
169 global ALWAYS_RUSTFLAGS
170 global RUST_UNDER_TEST
171 global individual_timeout
173 # HACK: guard against infinite loops in the compiler
174 set individual_timeout 10
176 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
177 lappend options "libs=${gluefile}"
178 lappend options "ldflags=${wrap_flags}"
181 lappend options "timeout=[timeout_value]"
182 lappend options "compiler=$RUST_UNDER_TEST"
184 set options [concat "$ALWAYS_RUSTFLAGS" $options]
185 set options [dg-additional-files-options $options $source]
187 return [target_compile $source $dest $type $options]