@@ -18,6 +18,7 @@ pub(crate) struct RustcCodegenFlags<'a> {
18
18
force_frame_pointers : Option < bool > ,
19
19
no_redzone : Option < bool > ,
20
20
soft_float : Option < bool > ,
21
+ dwarf_version : Option < u32 > ,
21
22
}
22
23
23
24
impl < ' this > RustcCodegenFlags < ' this > {
@@ -86,6 +87,10 @@ impl<'this> RustcCodegenFlags<'this> {
86
87
}
87
88
}
88
89
90
+ fn arg_to_u32 ( arg : impl AsRef < str > ) -> Option < u32 > {
91
+ arg. as_ref ( ) . parse ( ) . ok ( )
92
+ }
93
+
89
94
let ( flag, value) = if let Some ( ( flag, value) ) = flag. split_once ( '=' ) {
90
95
( flag, Some ( value) )
91
96
} else {
@@ -148,6 +153,14 @@ impl<'this> RustcCodegenFlags<'this> {
148
153
self . branch_protection =
149
154
Some ( flag_ok_or ( value, "-Zbranch-protection must have a value" ) ?) ;
150
155
}
156
+ // https://doc.rust-lang.org/beta/unstable-book/compiler-flags/dwarf-version.html
157
+ // FIXME: Drop the -Z variant and update the doc link once the option is stablized
158
+ "-Zdwarf-version" | "-Cdwarf-version" => {
159
+ self . dwarf_version = Some ( value. and_then ( arg_to_u32) . ok_or ( Error :: new (
160
+ ErrorKind :: InvalidFlag ,
161
+ "-Zdwarf-version must have a value" ,
162
+ ) ) ?) ;
163
+ }
151
164
_ => { }
152
165
}
153
166
Ok ( ( ) )
@@ -250,6 +263,11 @@ impl<'this> RustcCodegenFlags<'this> {
250
263
} ;
251
264
push_if_supported ( cc_flag. into ( ) ) ;
252
265
}
266
+ // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-gdwarf-2
267
+ // https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-gdwarf
268
+ if let Some ( value) = self . dwarf_version {
269
+ push_if_supported ( format ! ( "-gdwarf-{value}" ) . into ( ) ) ;
270
+ }
253
271
}
254
272
255
273
// Compiler-exclusive flags
@@ -390,6 +408,7 @@ mod tests {
390
408
"-Crelocation-model=pic" ,
391
409
"-Csoft-float=yes" ,
392
410
"-Zbranch-protection=bti,pac-ret,leaf" ,
411
+ "-Zdwarf-version=5" ,
393
412
// Set flags we don't recognise but rustc supports next
394
413
// rustc flags
395
414
"--cfg" ,
@@ -496,6 +515,7 @@ mod tests {
496
515
relocation_model : Some ( "pic" ) ,
497
516
soft_float : Some ( true ) ,
498
517
branch_protection : Some ( "bti,pac-ret,leaf" ) ,
518
+ dwarf_version : Some ( 5 ) ,
499
519
} ,
500
520
) ;
501
521
}
0 commit comments