@@ -89,18 +89,33 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
89
89
cmd. arg ( "vga" ) ;
90
90
}
91
91
92
+ let mut rustflags = Vec :: new ( ) ;
93
+ rustflags. push ( "-Zmutable-noalias=no" . to_string ( ) ) ;
94
+
92
95
#[ cfg( feature = "instrument" ) ]
93
96
{
94
- cmd. env ( "RUSTFLAGS" , "-Z instrument-mcount" ) ;
95
- // if instrument is not set, ensure that instrument is not in environment variables!
96
- cmd. env (
97
- "RUSTFLAGS" ,
98
- env:: var ( "RUSTFLAGS" )
99
- . unwrap_or_else ( |_| "" . into ( ) )
100
- . replace ( "-Z instrument-mcount" , "" ) ,
101
- ) ;
97
+ rustflags. push ( "-Zinstrument-mcount" . to_string ( ) ) ;
98
+ // Add outer `RUSTFLAGS` to command
99
+ if let Ok ( var) = env:: var ( "RUSTFLAGS" ) {
100
+ rustflags. push ( var) ;
101
+ }
102
102
}
103
103
104
+ #[ cfg( not( feature = "instrument" ) ) ]
105
+ {
106
+ // If the `instrument` feature feature is not enabled,
107
+ // filter it from outer `RUSTFLAGS` before adding them to the command.
108
+ if let Ok ( var) = env:: var ( "RUSTFLAGS" ) {
109
+ let flags = var
110
+ . split ( ',' )
111
+ . filter ( |& flag| !flag. contains ( "instrument-mcount" ) )
112
+ . map ( String :: from) ;
113
+ rustflags. extend ( flags) ;
114
+ }
115
+ }
116
+
117
+ cmd. env ( "RUSTFLAGS" , rustflags. join ( "," ) ) ;
118
+
104
119
let output = cmd. output ( ) . expect ( "Unable to build kernel" ) ;
105
120
let stdout = std:: string:: String :: from_utf8 ( output. stdout ) ;
106
121
let stderr = std:: string:: String :: from_utf8 ( output. stderr ) ;
0 commit comments