1
1
use std:: env;
2
- use std:: ffi:: OsStr ;
2
+ use std:: ffi:: { OsStr , OsString } ;
3
3
use std:: path:: Path ;
4
4
use std:: process:: { Command , Output } ;
5
5
@@ -86,6 +86,33 @@ impl Rustc {
86
86
self
87
87
}
88
88
89
+ /// Specify number of codegen units
90
+ pub fn codegen_units ( & mut self , units : usize ) -> & mut Self {
91
+ self . cmd . arg ( format ! ( "-Ccodegen-units={units}" ) ) ;
92
+ self
93
+ }
94
+
95
+ /// Specify directory path used for incremental cache
96
+ pub fn incremental < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Self {
97
+ let mut arg = OsString :: new ( ) ;
98
+ arg. push ( "-Cincremental=" ) ;
99
+ arg. push ( path. as_ref ( ) ) ;
100
+ self . cmd . arg ( & arg) ;
101
+ self
102
+ }
103
+
104
+ /// Specify error format to use
105
+ pub fn error_format ( & mut self , format : & str ) -> & mut Self {
106
+ self . cmd . arg ( format ! ( "--error-format={format}" ) ) ;
107
+ self
108
+ }
109
+
110
+ /// Specify json messages printed by the compiler
111
+ pub fn json ( & mut self , items : & str ) -> & mut Self {
112
+ self . cmd . arg ( format ! ( "--json={items}" ) ) ;
113
+ self
114
+ }
115
+
89
116
/// Specify target triple.
90
117
pub fn target ( & mut self , target : & str ) -> & mut Self {
91
118
assert ! ( !target. contains( char :: is_whitespace) , "target triple cannot contain spaces" ) ;
@@ -94,13 +121,7 @@ impl Rustc {
94
121
}
95
122
96
123
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
97
- /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
98
- /// is passed (note the space).
99
- pub fn arg ( & mut self , arg : & str ) -> & mut Self {
100
- assert ! (
101
- !( [ "-Z" , "-C" ] . contains( & arg) || arg. starts_with( "-Z " ) || arg. starts_with( "-C " ) ) ,
102
- "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
103
- ) ;
124
+ pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
104
125
self . cmd . arg ( arg) ;
105
126
self
106
127
}
@@ -120,16 +141,7 @@ impl Rustc {
120
141
}
121
142
122
143
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
123
- /// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
124
- /// is passed (note the space).
125
- pub fn args ( & mut self , args : & [ & str ] ) -> & mut Self {
126
- for arg in args {
127
- assert ! (
128
- !( [ "-Z" , "-C" ] . contains( & arg) || arg. starts_with( "-Z " ) || arg. starts_with( "-C " ) ) ,
129
- "use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
130
- ) ;
131
- }
132
-
144
+ pub fn args < S : AsRef < OsStr > > ( & mut self , args : & [ S ] ) -> & mut Self {
133
145
self . cmd . args ( args) ;
134
146
self
135
147
}
0 commit comments