@@ -405,7 +405,7 @@ pub struct Build {
405405 host : Option < Arc < str > > ,
406406 out_dir : Option < Arc < Path > > ,
407407 opt_level : Option < Arc < str > > ,
408- debug : Option < bool > ,
408+ debug : Option < Arc < str > > ,
409409 force_frame_pointer : Option < bool > ,
410410 env : Vec < ( Arc < OsStr > , Arc < OsStr > ) > ,
411411 compiler : Option < Arc < Path > > ,
@@ -1180,7 +1180,23 @@ impl Build {
11801180 /// This option is automatically scraped from the `DEBUG` environment
11811181 /// variable by build scripts, so it's not required to call this function.
11821182 pub fn debug ( & mut self , debug : bool ) -> & mut Build {
1183- self . debug = Some ( debug) ;
1183+ self . debug = Some ( debug. to_string ( ) . into ( ) ) ;
1184+ self
1185+ }
1186+
1187+ /// Configures whether the compiler will emit debug information when
1188+ /// generating object files.
1189+ ///
1190+ /// This should be one of the values accepted by Cargo's [`debug`][]
1191+ /// profile setting, which cc-rs will try to map to the appropriate C
1192+ /// compiler flag.
1193+ ///
1194+ /// This option is automatically scraped from the `DEBUG` environment
1195+ /// variable by build scripts, so it's not required to call this function.
1196+ ///
1197+ /// [debuginfo]: https://doc.rust-lang.org/cargo/reference/profiles.html#debug
1198+ pub fn debug_str ( & mut self , debug : & str ) -> & mut Build {
1199+ self . debug = Some ( debug. into ( ) ) ;
11841200 self
11851201 }
11861202
@@ -2161,7 +2177,11 @@ impl Build {
21612177 cmd. args . push ( "-G" . into ( ) ) ;
21622178 }
21632179 let family = cmd. family ;
2164- family. add_debug_flags ( cmd, self . get_dwarf_version ( ) ) ;
2180+ family. add_debug_flags (
2181+ cmd,
2182+ self . get_debug_str ( ) . as_deref ( ) . unwrap_or_default ( ) ,
2183+ self . get_dwarf_version ( ) ,
2184+ ) ;
21652185 }
21662186
21672187 if self . get_force_frame_pointer ( ) {
@@ -3707,8 +3727,25 @@ impl Build {
37073727 }
37083728 }
37093729
3730+ /// Returns true if *any* debug info is enabled.
3731+ ///
3732+ /// [`get_debug_str`] provides more detail.
37103733 fn get_debug ( & self ) -> bool {
3711- self . debug . unwrap_or_else ( || self . getenv_boolean ( "DEBUG" ) )
3734+ match self . get_debug_str ( ) {
3735+ Err ( _) => false ,
3736+ Ok ( d) => match & * d {
3737+ // From https://doc.rust-lang.org/cargo/reference/profiles.html#debug
3738+ "" | "0" | "false" | "none" => false ,
3739+ _ => true ,
3740+ } ,
3741+ }
3742+ }
3743+
3744+ fn get_debug_str ( & self ) -> Result < Cow < ' _ , str > , Error > {
3745+ match & self . debug {
3746+ Some ( d) => Ok ( Cow :: Borrowed ( d) ) ,
3747+ None => self . getenv_unwrap_str ( "DEBUG" ) . map ( Cow :: Owned ) ,
3748+ }
37123749 }
37133750
37143751 fn get_shell_escaped_flags ( & self ) -> bool {
0 commit comments