@@ -22,9 +22,11 @@ use rustc_session::EarlyDiagCtxt;
2222use rustc_span:: symbol:: Symbol ;
2323
2424use std:: env;
25+ use std:: fs:: read_to_string;
2526use std:: ops:: Deref ;
2627use std:: path:: Path ;
2728use std:: process:: exit;
29+ use std:: string:: ToString ;
2830
2931use anstream:: println;
3032
@@ -188,12 +190,31 @@ pub fn main() {
188190
189191 exit ( rustc_driver:: catch_with_exit_code ( move || {
190192 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+ } ;
192213
193214 let sys_root_env = std:: env:: var ( "SYSROOT" ) . ok ( ) ;
194215 let pass_sysroot_env_if_given = |args : & mut Vec < String > , sys_root_env| {
195216 if let Some ( sys_root) = sys_root_env {
196- if !has_sysroot_arg {
217+ if !has_sysroot_arg ( args ) {
197218 args. extend ( vec ! [ "--sysroot" . into( ) , sys_root] ) ;
198219 }
199220 } ;
0 commit comments