@@ -59,62 +59,15 @@ impl Rustc {
59
59
self
60
60
}
61
61
62
- /// Configure codegen options.
63
- pub fn codegen_opt ( & mut self , c : CodegenOpt ) -> & mut Self {
64
- self . cmd . arg ( "-C" ) ;
65
-
66
- match c {
67
- CodegenOpt :: PreferDynamic => self . cmd . arg ( "prefer-dynamic=true" ) ,
68
- CodegenOpt :: SymbolManglingVersion ( v) => match v {
69
- SymbolManglingVersion :: Legacy => self . cmd . arg ( "symbol-mangling-version=legacy" ) ,
70
- SymbolManglingVersion :: V0 => self . cmd . arg ( "symbol-mangling-version=v0" ) ,
71
- } ,
72
- CodegenOpt :: Lto ( kind) => match kind {
73
- LtoKind :: Fat => self . cmd . arg ( "lto=fat" ) ,
74
- LtoKind :: Thin => self . cmd . arg ( "lto=thin" ) ,
75
- LtoKind :: None => self . cmd . arg ( "lto=false" ) ,
76
- } ,
77
- CodegenOpt :: OptLevel ( level) => match level {
78
- OptLevel :: O0 => self . cmd . arg ( "opt-level=0" ) ,
79
- OptLevel :: O1 => self . cmd . arg ( "opt-level=1" ) ,
80
- OptLevel :: O2 => self . cmd . arg ( "opt-level=2" ) ,
81
- OptLevel :: O3 => self . cmd . arg ( "opt-level=3" ) ,
82
- OptLevel :: Os => self . cmd . arg ( "opt-level=s" ) ,
83
- OptLevel :: Oz => self . cmd . arg ( "opt-level=z" ) ,
84
- } ,
85
- CodegenOpt :: OverflowChecks => self . cmd . arg ( "overflow-checks=true" ) ,
86
- CodegenOpt :: Panic ( strat) => match strat {
87
- PanicStrategy :: Abort => self . cmd . arg ( "panic=abort" ) ,
88
- PanicStrategy :: Unwind => self . cmd . arg ( "panic=unwind" ) ,
89
- } ,
90
- } ;
91
-
92
- self
93
- }
94
-
95
62
/// Specify default optimization level `-O` (alias for `-C opt-level=2`).
96
- pub fn default_opt ( & mut self ) -> & mut Self {
63
+ pub fn opt ( & mut self ) -> & mut Self {
97
64
self . cmd . arg ( "-O" ) ;
98
65
self
99
66
}
100
67
101
- /// Specify types of output files to generate. See [`EmitKind`] for kinds.
102
- pub fn emit ( & mut self , kinds : & [ EmitKind ] ) -> & mut Self {
103
- let kinds = kinds
104
- . iter ( )
105
- . map ( |kind| match kind {
106
- EmitKind :: Metadata => "metadata" ,
107
- } )
108
- . collect :: < Vec < _ > > ( ) ;
109
- let kinds_str: String = kinds. join ( "," ) ;
110
- self . cmd . arg ( format ! ( "--emit={kinds_str}" ) ) ;
111
- self
112
- }
113
-
114
- /// Set `-Z unstable-options`
115
- pub fn enable_unstable_options ( & mut self ) -> & mut Self {
116
- self . cmd . arg ( "-Z" ) ;
117
- self . cmd . arg ( "unstable-options" ) ;
68
+ /// Specify type(s) of output files to generate.
69
+ pub fn emit ( & mut self , kinds : & str ) -> & mut Self {
70
+ self . cmd . arg ( format ! ( "--emit={kinds}" ) ) ;
118
71
self
119
72
}
120
73
@@ -134,7 +87,7 @@ impl Rustc {
134
87
}
135
88
136
89
/// Specify path to the input file.
137
- pub fn input_file < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Self {
90
+ pub fn input < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Self {
138
91
self . cmd . arg ( path. as_ref ( ) ) ;
139
92
self
140
93
}
@@ -146,18 +99,29 @@ impl Rustc {
146
99
self
147
100
}
148
101
149
- // Last-resort builder methods
150
-
151
- /// Fallback command argument provider. Prefer using semantically meaningful builder methods
152
- /// (add them if they don't exist) whenever possible.
102
+ /// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
103
+ /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
104
+ /// is passed (note the space).
153
105
pub fn arg ( & mut self , arg : & str ) -> & mut Self {
106
+ assert ! (
107
+ !( [ "-Z" , "-C" ] . contains( & arg) || arg. starts_with( "-Z " ) || arg. starts_with( "-C " ) ) ,
108
+ "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
109
+ ) ;
154
110
self . cmd . arg ( arg) ;
155
111
self
156
112
}
157
113
158
- /// Fallback command arguments provider. Prefer using semantically meaningful builder methods
159
- /// (add them if they don't exist) whenever possible.
114
+ /// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
115
+ /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
116
+ /// is passed (note the space).
160
117
pub fn args ( & mut self , args : & [ & str ] ) -> & mut Self {
118
+ for arg in args {
119
+ assert ! (
120
+ !( [ "-Z" , "-C" ] . contains( & arg) || arg. starts_with( "-Z " ) || arg. starts_with( "-C " ) ) ,
121
+ "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
122
+ ) ;
123
+ }
124
+
161
125
self . cmd . args ( args) ;
162
126
self
163
127
}
@@ -188,74 +152,3 @@ impl Rustc {
188
152
self
189
153
}
190
154
}
191
-
192
- /// Specifies the types of output files to generate.
193
- pub enum EmitKind {
194
- /// Generates a file containing metadata about the crate. The default output filename is
195
- /// `libCRATE_NAME.rmeta`.
196
- Metadata ,
197
- }
198
-
199
- /// Specifies codegen options.
200
- pub enum CodegenOpt {
201
- /// By default, rustc prefers to statically link dependencies. This option will indicate that
202
- /// dynamic linking should be used if possible if both a static and dynamic versions of a
203
- /// library are available.
204
- PreferDynamic ,
205
- /// Controls the name mangling format for encoding Rust item names for the purpose of generating
206
- /// object code and linking.
207
- SymbolManglingVersion ( SymbolManglingVersion ) ,
208
- /// Controls whether LLVM uses link time optimizations to produce better optimized code, using
209
- /// whole-program analysis, at the cost of longer linking time.
210
- Lto ( LtoKind ) ,
211
- ///
212
- OptLevel ( OptLevel ) ,
213
- /// Control the behavior of runtime integer overflow. When `overflow-checks` are enabled, a
214
- /// panic will occur on overflow.
215
- OverflowChecks ,
216
- /// Control what happens when the code panics.
217
- Panic ( PanicStrategy ) ,
218
- }
219
-
220
- /// The name mangling format for encoding Rust item names for the purpose of generating object code
221
- /// and linking.
222
- pub enum SymbolManglingVersion {
223
- Legacy ,
224
- V0 ,
225
- }
226
-
227
- /// Kind of LTO to perform.
228
- pub enum LtoKind {
229
- /// Perform "fat" LTO which attempts to perform optimizations across all crates within the
230
- /// dependency graph.
231
- Fat ,
232
- /// Similar to "fat", but takes substantially less time to run while still achieving performance
233
- /// gains similar to "fat".
234
- Thin ,
235
- /// Disable LTO.
236
- None ,
237
- }
238
-
239
- /// Optimization level.
240
- pub enum OptLevel {
241
- /// No optimizations, also turns on `cfg(debug_assertions)` (the default).
242
- O0 ,
243
- /// Basic optimizations.
244
- O1 ,
245
- /// Some optimizations.
246
- O2 ,
247
- /// All optimizations.
248
- O3 ,
249
- /// Optimize for binary size.
250
- Os ,
251
- /// Optimize for binary size, but also turn off loop vectorization.
252
- Oz ,
253
- }
254
-
255
- /// What happens when the code panics.
256
- pub enum PanicStrategy {
257
- /// Terminate the process upon panic.
258
- Abort ,
259
- /// Unwind the stack upon panic.
260
- Unwind ,
261
- }
0 commit comments