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
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
} {
39 global TESTING_IN_BUILD_TREE
43 if { [is_remote host
] ||
![info exists TESTING_IN_BUILD_TREE
] } {
53 # rust_link_flags
-- linker flags
for the gcc tree structure
56 proc rust_link_flags
{ paths
} {
58 global ld_library_path
59 global RUST_UNDER_TEST
66 set ld_library_path
"."
67 set shlib_ext
[get_shlib_extension
]
69 verbose
"shared lib extension: $shlib_ext"
71 set_ld_library_path_env_vars
77 # rust_init
-- called at the start of each subdir of tests
80 proc rust_init
{ args } {
82 global rust_initialized
86 global gluefile wrap_flags
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.
100 if ![info exists RUST_UNDER_TEST
] then {
101 if [info exists TOOL_EXECUTABLE
] {
102 set RUST_UNDER_TEST $TOOL_EXECUTABLE
104 if { [is_remote host
] ||
! [info exists TESTING_IN_BUILD_TREE
] } {
105 set RUST_UNDER_TEST
[transform gccrs
]
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"
119 if ![info exists tmpdir
] {
123 if [info exists 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}] ]"
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
} {
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
]