@@ -22,9 +22,11 @@ use rustc_session::EarlyDiagCtxt;
22
22
use rustc_span:: symbol:: Symbol ;
23
23
24
24
use std:: env;
25
+ use std:: fs:: read_to_string;
25
26
use std:: ops:: Deref ;
26
27
use std:: path:: Path ;
27
28
use std:: process:: exit;
29
+ use std:: string:: ToString ;
28
30
29
31
use anstream:: println;
30
32
@@ -188,12 +190,31 @@ pub fn main() {
188
190
189
191
exit ( rustc_driver:: catch_with_exit_code ( move || {
190
192
let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
191
- let has_sysroot_arg = arg_value ( & orig_args, "--sysroot" , |_| true ) . is_some ( ) ;
193
+
194
+ let has_sysroot_arg = |args : & mut [ String ] | -> bool {
195
+ if arg_value ( args, "--sysroot" , |_| true ) . is_some ( ) {
196
+ return true ;
197
+ }
198
+ // https://doc.rust-lang.org/rustc/command-line-arguments.html#path-load-command-line-flags-from-a-path
199
+ // Beside checking for existence of `--sysroot` on the command line, we need to
200
+ // check for the arg files that are prefixed with @ as well to be consistent with rustc
201
+ for arg in args. iter ( ) {
202
+ if let Some ( arg_file_path) = arg. strip_prefix ( '@' ) {
203
+ if let Ok ( arg_file) = read_to_string ( arg_file_path) {
204
+ let split_arg_file: Vec < String > = arg_file. lines ( ) . map ( ToString :: to_string) . collect ( ) ;
205
+ if arg_value ( & split_arg_file, "--sysroot" , |_| true ) . is_some ( ) {
206
+ return true ;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ false
212
+ } ;
192
213
193
214
let sys_root_env = std:: env:: var ( "SYSROOT" ) . ok ( ) ;
194
215
let pass_sysroot_env_if_given = |args : & mut Vec < String > , sys_root_env| {
195
216
if let Some ( sys_root) = sys_root_env {
196
- if !has_sysroot_arg {
217
+ if !has_sysroot_arg ( args ) {
197
218
args. extend ( vec ! [ "--sysroot" . into( ) , sys_root] ) ;
198
219
}
199
220
} ;
0 commit comments