@@ -88,6 +88,12 @@ pub fn escape_for_toml(s: &str) -> String {
88
88
format ! ( "\" {s}\" " )
89
89
}
90
90
91
+ pub fn flagsplit ( flags : & str ) -> Vec < String > {
92
+ // This code is taken from `RUSTFLAGS` handling in cargo.
93
+ // Taken from miri-script util.rs
94
+ flags. split ( ' ' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) . collect ( )
95
+ }
96
+
91
97
pub fn get_miriflags ( ) -> Vec < String > {
92
98
// TODO: I quite not understand what Carl Jung means by Oh and please add a link to https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags.
93
99
// I guess we don't support the target.rustflags part yet? (That's okay but should be mentioned in a comment.)
@@ -102,10 +108,33 @@ pub fn get_miriflags() -> Vec<String> {
102
108
// Respect `MIRIFLAGS` and `miri.flags` setting in cargo config.
103
109
// If MIRIFLAGS is present, flags from cargo config are ignored.
104
110
// This matches cargo behavior for RUSTFLAGS.
105
- if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
111
+ //
112
+ // Strategy: (1) check pseudo var CARGO_ENCODED_MIRIFLAGS first (this is only set after we check for --config
113
+ // in the cargo_dash_dash in the if else)
114
+ //
115
+ // if CARGO_ENCODED_MIRIFLAGS doesn't exist, we check in --config (2)
116
+ // if --config doesn't exist, we check offical env var MIRIFLAGS (3)
117
+ //
118
+ // if MIRIFLAGS is non-existent, we then check for toml (4)
119
+ let cargo_dash_dash_config = cargo_extra_flags ( ) ;
120
+ if let Ok ( cargo_encoded_miri_flags) = env:: var ( "CARGO_ENCODED_MIRIFLAGS" ) {
121
+ // (1)
122
+ flagsplit ( cargo_encoded_miri_flags. as_str ( ) )
123
+ } else if cargo_dash_dash_config. contains ( & "miri" . to_string ( ) ) {
124
+ // (2)
125
+ let miri_flags_vec = cargo_dash_dash_config
126
+ . into_iter ( )
127
+ . filter ( |arg| arg. contains ( & "miri" . to_string ( ) ) )
128
+ . collect :: < Vec < String > > ( ) ;
129
+ let miri_flags_string = miri_flags_vec. join ( " " ) ;
130
+ env:: set_var ( "CARGO_ENCODED_MIRIFLAGS" , miri_flags_string) ;
131
+ miri_flags_vec
132
+ } else if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
133
+ // (3)
106
134
// This code is taken from `RUSTFLAGS` handling in cargo.
107
135
a. split ( ' ' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) . collect ( )
108
136
} else {
137
+ // (4)
109
138
serde_json:: from_str :: < Vec < String > > ( config_miriflags) . unwrap_or_default ( )
110
139
}
111
140
}
0 commit comments