@@ -122,8 +122,6 @@ func init() {
122
122
123
123
func TransformSrcToBinary (ctx ModuleContext , mainSrc android.Path , deps PathDeps , flags Flags ,
124
124
outputFile android.WritablePath ) buildOutput {
125
- flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C lto=thin" )
126
-
127
125
return transformSrctoCrate (ctx , mainSrc , deps , flags , outputFile , "bin" )
128
126
}
129
127
@@ -134,20 +132,16 @@ func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
134
132
135
133
func TransformSrctoDylib (ctx ModuleContext , mainSrc android.Path , deps PathDeps , flags Flags ,
136
134
outputFile android.WritablePath ) buildOutput {
137
- flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C lto=thin" )
138
-
139
135
return transformSrctoCrate (ctx , mainSrc , deps , flags , outputFile , "dylib" )
140
136
}
141
137
142
138
func TransformSrctoStatic (ctx ModuleContext , mainSrc android.Path , deps PathDeps , flags Flags ,
143
139
outputFile android.WritablePath ) buildOutput {
144
- flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C lto=thin" )
145
140
return transformSrctoCrate (ctx , mainSrc , deps , flags , outputFile , "staticlib" )
146
141
}
147
142
148
143
func TransformSrctoShared (ctx ModuleContext , mainSrc android.Path , deps PathDeps , flags Flags ,
149
144
outputFile android.WritablePath ) buildOutput {
150
- flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C lto=thin" )
151
145
return transformSrctoCrate (ctx , mainSrc , deps , flags , outputFile , "cdylib" )
152
146
}
153
147
@@ -263,6 +257,20 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
263
257
264
258
inputs = append (inputs , main )
265
259
260
+ if ctx .Config ().Eng () {
261
+ // Per https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
262
+ // incremental building implies codegen-units=256
263
+ incrementalPath := android .PathForModuleOut (ctx , "rustc-incremental" ).String ()
264
+ flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C incremental=" + incrementalPath )
265
+
266
+ } else {
267
+ flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C codegen-units=1" )
268
+
269
+ if ! (ctx .RustModule ().Rlib () || ctx .RustModule ().ProcMacro ()) {
270
+ flags .GlobalRustFlags = append (flags .GlobalRustFlags , "-C lto=thin" )
271
+ }
272
+ }
273
+
266
274
// Collect rustc flags
267
275
rustcFlags = append (rustcFlags , flags .GlobalRustFlags ... )
268
276
rustcFlags = append (rustcFlags , flags .RustFlags ... )
@@ -278,15 +286,6 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
278
286
// Suppress an implicit sysroot
279
287
rustcFlags = append (rustcFlags , "--sysroot=/dev/null" )
280
288
281
- // Enable incremental compilation if requested by user
282
- if ctx .Config ().IsEnvTrue ("SOONG_RUSTC_INCREMENTAL" ) {
283
- incrementalPath := android .PathForOutput (ctx , "rustc" ).String ()
284
-
285
- rustcFlags = append (rustcFlags , "-C incremental=" + incrementalPath )
286
- } else {
287
- rustcFlags = append (rustcFlags , "-C codegen-units=1" )
288
- }
289
-
290
289
// Disallow experimental features
291
290
modulePath := ctx .ModuleDir ()
292
291
if ! (android .IsThirdPartyPath (modulePath ) || strings .HasPrefix (modulePath , "prebuilts" )) {
0 commit comments