| 1 |
# Copyright (C) 2012-2025 Free Software Foundation, Inc. |
| 2 |
|
| 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. |
| 7 |
# |
| 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. |
| 12 |
# |
| 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/>. |
| 16 |
|
| 17 |
# |
| 18 |
# rust support library routines |
| 19 |
# |
| 20 |
|
| 21 |
load_lib prune.exp |
| 22 |
load_lib gcc-defs.exp |
| 23 |
load_lib timeout.exp |
| 24 |
load_lib target-libpath.exp |
| 25 |
|
| 26 |
# |
| 27 |
# RUST_UNDER_TEST is the compiler under test. |
| 28 |
# |
| 29 |
|
| 30 |
set rust_compile_options "" |
| 31 |
|
| 32 |
|
| 33 |
# |
| 34 |
# rust_include_flags -- include flags for the gcc tree structure |
| 35 |
# |
| 36 |
|
| 37 |
proc rust_include_flags { paths } { |
| 38 |
global srcdir |
| 39 |
global TESTING_IN_BUILD_TREE |
| 40 |
|
| 41 |
set flags "" |
| 42 |
|
| 43 |
if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } { |
| 44 |
return "${flags}" |
| 45 |
} |
| 46 |
|
| 47 |
set gccpath ${paths} |
| 48 |
|
| 49 |
return "$flags" |
| 50 |
} |
| 51 |
|
| 52 |
# |
| 53 |
# rust_link_flags -- linker flags for the gcc tree structure |
| 54 |
# |
| 55 |
|
| 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 |
| 62 |
|
| 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" |
| 70 |
|
| 71 |
set_ld_library_path_env_vars |
| 72 |
|
| 73 |
return "$flags" |
| 74 |
} |
| 75 |
|
| 76 |
# |
| 77 |
# rust_init -- called at the start of each subdir of tests |
| 78 |
# |
| 79 |
|
| 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 |
| 95 |
|
| 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 |
| 99 |
|
| 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]]] |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 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 |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if ![info exists tmpdir] { |
| 120 |
set tmpdir "/tmp" |
| 121 |
} |
| 122 |
|
| 123 |
if [info exists gluefile] { |
| 124 |
unset gluefile |
| 125 |
} |
| 126 |
|
| 127 |
rust_maybe_build_wrapper "${tmpdir}/rust-testglue.o" |
| 128 |
|
| 129 |
set ALWAYS_RUSTFLAGS "" |
| 130 |
|
| 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" |
| 136 |
} |
| 137 |
|
| 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] ]" |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
if [info exists TOOL_OPTIONS] { |
| 149 |
lappend ALWAYS_RUSTFLAGS "additional_flags=$TOOL_OPTIONS" |
| 150 |
} |
| 151 |
|
| 152 |
lappend ALWAYS_RUSTFLAGS "additional_flags=-frust-incomplete-and-experimental-compiler-do-not-use" |
| 153 |
|
| 154 |
verbose -log "ALWAYS_RUSTFLAGS set to $ALWAYS_RUSTFLAGS" |
| 155 |
|
| 156 |
set gcc_warning_prefix "warning:" |
| 157 |
set gcc_error_prefix "(fatal )?error:" |
| 158 |
|
| 159 |
verbose "rust is initialized" 3 |
| 160 |
} |
| 161 |
|
| 162 |
# |
| 163 |
# rust_target_compile -- compile a source file |
| 164 |
# |
| 165 |
|
| 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 |
| 172 |
|
| 173 |
# HACK: guard against infinite loops in the compiler |
| 174 |
set individual_timeout 10 |
| 175 |
|
| 176 |
if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } { |
| 177 |
lappend options "libs=${gluefile}" |
| 178 |
lappend options "ldflags=${wrap_flags}" |
| 179 |
} |
| 180 |
|
| 181 |
lappend options "timeout=[timeout_value]" |
| 182 |
lappend options "compiler=$RUST_UNDER_TEST" |
| 183 |
|
| 184 |
set options [concat "$ALWAYS_RUSTFLAGS" $options] |
| 185 |
set options [dg-additional-files-options $options $source $dest $type] |
| 186 |
|
| 187 |
return [target_compile $source $dest $type $options] |
| 188 |
} |