@@ -59,62 +59,15 @@ impl Rustc {
5959 self
6060 }
6161
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-
9562 /// 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 {
9764 self . cmd . arg ( "-O" ) ;
9865 self
9966 }
10067
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}" ) ) ;
11871 self
11972 }
12073
@@ -134,7 +87,7 @@ impl Rustc {
13487 }
13588
13689 /// 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 {
13891 self . cmd . arg ( path. as_ref ( ) ) ;
13992 self
14093 }
@@ -146,18 +99,29 @@ impl Rustc {
14699 self
147100 }
148101
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).
153105 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+ ) ;
154110 self . cmd . arg ( arg) ;
155111 self
156112 }
157113
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).
160117 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+
161125 self . cmd . args ( args) ;
162126 self
163127 }
@@ -188,74 +152,3 @@ impl Rustc {
188152 self
189153 }
190154}
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