summaryrefslogtreecommitdiff
path: root/rust/builder.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2024-05-15 10:59:47 -0400
committer Ivan Lozano <ivanlozano@google.com> 2024-05-17 10:11:57 -0400
commitab58647b2e98e13136a1fe80308b6da1c933437a (patch)
treeb0ea0032c5bdf6898ebb672397c23ee0d16d4ca0 /rust/builder.go
parente8fcd377759608129bb23581d5593e384bb2c15e (diff)
rust: Add an option to disable LTO for Rust
This adds an option to disable LTO when building a Rust module. This is mostly intended to speedu p local prototyping, and LTO should not normally be disabled for production builds. Bug: 339628497 Test: m blueprint_tests && m rust Change-Id: I21d5d4513a259a56f101ce8906e2bef7404e4efb
Diffstat (limited to 'rust/builder.go')
-rw-r--r--rust/builder.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/rust/builder.go b/rust/builder.go
index abbf90d83..1ce92f4ec 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -158,7 +158,9 @@ func getTransformProperties(ctx ModuleContext, crateType string) transformProper
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ if ctx.RustModule().compiler.Thinlto() {
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ }
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "bin"))
}
@@ -212,20 +214,28 @@ func TransformRlibstoStaticlib(ctx android.ModuleContext, mainSrc android.Path,
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ if ctx.RustModule().compiler.Thinlto() {
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ }
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "dylib"))
}
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ if ctx.RustModule().compiler.Thinlto() {
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ }
+
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "staticlib"))
}
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ if ctx.RustModule().compiler.Thinlto() {
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
+ }
+
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "cdylib"))
}