summaryrefslogtreecommitdiff
path: root/rust/compiler.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/compiler.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/compiler.go')
-rw-r--r--rust/compiler.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/rust/compiler.go b/rust/compiler.go
index 5033fbac2..efc3deef3 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -47,6 +47,7 @@ type compiler interface {
edition() string
features() []string
rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
+ Thinlto() bool
// Output directory in which source-generated code from dependencies is
// copied. This is equivalent to Cargo's OUT_DIR variable.
@@ -231,6 +232,15 @@ type BaseCompilerProperties struct {
// If cargo_env_compat is true, sets the CARGO_PKG_VERSION env var to this value.
Cargo_pkg_version *string
+
+ // Control whether LTO is used for the final (Rust) linkage. This does not impact
+ // cross-language LTO.
+ Lto struct {
+ // Whether thin LTO should be enabled. By default this is true.
+ // LTO provides such a large code size benefit for Rust, this should always
+ // be enabled for production builds unless there's a clear need to disable it.
+ Thin *bool `android:"arch_variant"`
+ } `android:"arch_variant"`
}
type baseCompiler struct {
@@ -273,6 +283,11 @@ func (compiler *baseCompiler) Disabled() bool {
return false
}
+// Thin LTO is enabled by default.
+func (compiler *baseCompiler) Thinlto() bool {
+ return BoolDefault(compiler.Properties.Lto.Thin, true)
+}
+
func (compiler *baseCompiler) SetDisabled() {
panic("baseCompiler does not implement SetDisabled()")
}