Make building Rust targets faster in eng builds
This CL makes the following changes when building an eng variant to speed up compilation, possibly at the expense of the performance of the generated binary: * Disables LTO * Enables incremental compilation * Sets codegen units to 256 to increase parallelism (default set when enabling incremental compilation) These changes reduce the time taken to compile all of Android's Rust code from 16m20s to 12m10s. Test: lunch aosp_oriole-eng && m clean && m rust Bug: https://b.corp.google.com/issues/289094772 Change-Id: I97f1675c67ded69120b0c0e0fb5608aa9314a866
This commit is contained in:
@@ -122,8 +122,6 @@ func init() {
|
||||
|
||||
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
|
||||
}
|
||||
|
||||
@@ -134,20 +132,16 @@ func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
||||
|
||||
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib")
|
||||
}
|
||||
|
||||
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
|
||||
}
|
||||
|
||||
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
|
||||
}
|
||||
|
||||
@@ -263,6 +257,21 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
||||
|
||||
inputs = append(inputs, main)
|
||||
|
||||
if ctx.Config().Eng() {
|
||||
// Per https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
|
||||
// incremental building implies codegen-units=256
|
||||
incrementalPath := android.PathForModuleOut(ctx, "rustc-incremental").String()
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C incremental="+incrementalPath)
|
||||
|
||||
} else {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C codegen-units=1")
|
||||
|
||||
if !(ctx.RustModule().Rlib() || ctx.RustModule().ProcMacro()) {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-Z dylib-lto")
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
}
|
||||
}
|
||||
|
||||
// Collect rustc flags
|
||||
rustcFlags = append(rustcFlags, flags.GlobalRustFlags...)
|
||||
rustcFlags = append(rustcFlags, flags.RustFlags...)
|
||||
@@ -278,15 +287,6 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
||||
// Suppress an implicit sysroot
|
||||
rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
|
||||
|
||||
// Enable incremental compilation if requested by user
|
||||
if ctx.Config().IsEnvTrue("SOONG_RUSTC_INCREMENTAL") {
|
||||
incrementalPath := android.PathForOutput(ctx, "rustc").String()
|
||||
|
||||
rustcFlags = append(rustcFlags, "-C incremental="+incrementalPath)
|
||||
} else {
|
||||
rustcFlags = append(rustcFlags, "-C codegen-units=1")
|
||||
}
|
||||
|
||||
// Disallow experimental features
|
||||
modulePath := ctx.ModuleDir()
|
||||
if !(android.IsThirdPartyPath(modulePath) || strings.HasPrefix(modulePath, "prebuilts")) {
|
||||
|
Reference in New Issue
Block a user