From 5f788403089bf03232ed601c8095119a8bd76d4f Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Thu, 2 Mar 2023 16:06:01 -0800 Subject: [PATCH] Enable LTO for Rust dylibs Test: m rust Test: TH Change-Id: I2257fe9fce1457821a5cf7df644c73f3137a62bb --- rust/builder.go | 2 ++ rust/config/global.go | 1 + 2 files changed, 3 insertions(+) diff --git a/rust/builder.go b/rust/builder.go index a2f1238c2..55664512d 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -134,6 +134,8 @@ 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") } diff --git a/rust/config/global.go b/rust/config/global.go index 0dface47b..937502238 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -54,6 +54,7 @@ var ( // TODO (b/267698452): Temporary workaround until the "no unstable // features" policy is enforced. "-A stable-features", + "-Zdylib-lto", } deviceGlobalRustFlags = []string{