@@ -10,7 +10,7 @@ use std::cell::{Cell, RefCell};
1010use std:: cmp;
1111use std:: collections:: { HashMap , HashSet } ;
1212use std:: env;
13- use std:: fmt;
13+ use std:: fmt:: { self , Display } ;
1414use std:: fs;
1515use std:: io:: IsTerminal ;
1616use std:: path:: { Path , PathBuf } ;
@@ -50,6 +50,57 @@ pub enum DryRun {
5050 UserSelected ,
5151}
5252
53+ #[ derive( Copy , Clone , Default ) ]
54+ pub enum DebuginfoLevel {
55+ #[ default]
56+ None ,
57+ LineTablesOnly ,
58+ Limited ,
59+ Full ,
60+ }
61+
62+ // NOTE: can't derive(Deserialize) because the intermediate trip through toml::Value only
63+ // deserializes i64, and derive() only generates visit_u64
64+ impl < ' de > Deserialize < ' de > for DebuginfoLevel {
65+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
66+ where
67+ D : Deserializer < ' de > ,
68+ {
69+ use serde:: de:: Error ;
70+
71+ Ok ( match Deserialize :: deserialize ( deserializer) ? {
72+ StringOrInt :: String ( "none" ) | StringOrInt :: Int ( 0 ) => DebuginfoLevel :: None ,
73+ StringOrInt :: String ( "line-tables-only" ) => DebuginfoLevel :: LineTablesOnly ,
74+ StringOrInt :: String ( "limited" ) | StringOrInt :: Int ( 1 ) => DebuginfoLevel :: Limited ,
75+ StringOrInt :: String ( "full" ) | StringOrInt :: Int ( 2 ) => DebuginfoLevel :: Full ,
76+ StringOrInt :: Int ( n) => {
77+ let other = serde:: de:: Unexpected :: Signed ( n) ;
78+ return Err ( D :: Error :: invalid_value ( other, & "expected 0, 1, or 2" ) ) ;
79+ }
80+ StringOrInt :: String ( s) => {
81+ let other = serde:: de:: Unexpected :: Str ( s) ;
82+ return Err ( D :: Error :: invalid_value (
83+ other,
84+ & "expected none, line-tables-only, limited, or full" ,
85+ ) ) ;
86+ }
87+ } )
88+ }
89+ }
90+
91+ /// Suitable for passing to `-C debuginfo`
92+ impl Display for DebuginfoLevel {
93+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
94+ use DebuginfoLevel :: * ;
95+ f. write_str ( match self {
96+ None => "0" ,
97+ LineTablesOnly => "line-tables-only" ,
98+ Limited => "1" ,
99+ Full => "2" ,
100+ } )
101+ }
102+ }
103+
53104/// Global configuration for the entire build and/or bootstrap.
54105///
55106/// This structure is parsed from `config.toml`, and some of the fields are inferred from `git` or build-time parameters.
@@ -159,10 +210,10 @@ pub struct Config {
159210 pub rust_overflow_checks : bool ,
160211 pub rust_overflow_checks_std : bool ,
161212 pub rust_debug_logging : bool ,
162- pub rust_debuginfo_level_rustc : u32 ,
163- pub rust_debuginfo_level_std : u32 ,
164- pub rust_debuginfo_level_tools : u32 ,
165- pub rust_debuginfo_level_tests : u32 ,
213+ pub rust_debuginfo_level_rustc : DebuginfoLevel ,
214+ pub rust_debuginfo_level_std : DebuginfoLevel ,
215+ pub rust_debuginfo_level_tools : DebuginfoLevel ,
216+ pub rust_debuginfo_level_tests : DebuginfoLevel ,
166217 pub rust_split_debuginfo : SplitDebuginfo ,
167218 pub rust_rpath : bool ,
168219 pub rustc_parallel : bool ,
@@ -810,6 +861,13 @@ impl Default for StringOrBool {
810861 }
811862}
812863
864+ #[ derive( Deserialize ) ]
865+ #[ serde( untagged) ]
866+ enum StringOrInt < ' a > {
867+ String ( & ' a str ) ,
868+ Int ( i64 ) ,
869+ }
870+
813871define_config ! {
814872 /// TOML representation of how the Rust build is configured.
815873 struct Rust {
@@ -822,11 +880,11 @@ define_config! {
822880 overflow_checks: Option <bool > = "overflow-checks" ,
823881 overflow_checks_std: Option <bool > = "overflow-checks-std" ,
824882 debug_logging: Option <bool > = "debug-logging" ,
825- debuginfo_level: Option <u32 > = "debuginfo-level" ,
826- debuginfo_level_rustc: Option <u32 > = "debuginfo-level-rustc" ,
827- debuginfo_level_std: Option <u32 > = "debuginfo-level-std" ,
828- debuginfo_level_tools: Option <u32 > = "debuginfo-level-tools" ,
829- debuginfo_level_tests: Option <u32 > = "debuginfo-level-tests" ,
883+ debuginfo_level: Option <DebuginfoLevel > = "debuginfo-level" ,
884+ debuginfo_level_rustc: Option <DebuginfoLevel > = "debuginfo-level-rustc" ,
885+ debuginfo_level_std: Option <DebuginfoLevel > = "debuginfo-level-std" ,
886+ debuginfo_level_tools: Option <DebuginfoLevel > = "debuginfo-level-tools" ,
887+ debuginfo_level_tests: Option <DebuginfoLevel > = "debuginfo-level-tests" ,
830888 split_debuginfo: Option <String > = "split-debuginfo" ,
831889 run_dsymutil: Option <bool > = "run-dsymutil" ,
832890 backtrace: Option <bool > = "backtrace" ,
@@ -1478,17 +1536,17 @@ impl Config {
14781536
14791537 config. rust_debug_logging = debug_logging. unwrap_or ( config. rust_debug_assertions ) ;
14801538
1481- let with_defaults = |debuginfo_level_specific : Option < u32 > | {
1539+ let with_defaults = |debuginfo_level_specific : Option < _ > | {
14821540 debuginfo_level_specific. or ( debuginfo_level) . unwrap_or ( if debug == Some ( true ) {
1483- 1
1541+ DebuginfoLevel :: Limited
14841542 } else {
1485- 0
1543+ DebuginfoLevel :: None
14861544 } )
14871545 } ;
14881546 config. rust_debuginfo_level_rustc = with_defaults ( debuginfo_level_rustc) ;
14891547 config. rust_debuginfo_level_std = with_defaults ( debuginfo_level_std) ;
14901548 config. rust_debuginfo_level_tools = with_defaults ( debuginfo_level_tools) ;
1491- config. rust_debuginfo_level_tests = debuginfo_level_tests. unwrap_or ( 0 ) ;
1549+ config. rust_debuginfo_level_tests = debuginfo_level_tests. unwrap_or ( DebuginfoLevel :: None ) ;
14921550
14931551 let download_rustc = config. download_rustc_commit . is_some ( ) ;
14941552 // See https://github.com/rust-lang/compiler-team/issues/326
0 commit comments