diff --git a/rust/builder.go b/rust/builder.go index 910965130..27eeec23d 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -44,6 +44,8 @@ func init() { func TransformSrcToBinary(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) { + flags.RustFlags = append(flags.RustFlags, "-C lto") + transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", includeDirs) } @@ -59,11 +61,13 @@ func TransformSrctoDylib(ctx android.ModuleContext, mainSrc android.Path, deps P func TransformSrctoStatic(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) { + flags.RustFlags = append(flags.RustFlags, "-C lto") transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", includeDirs) } func TransformSrctoShared(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) { + flags.RustFlags = append(flags.RustFlags, "-C lto") transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", includeDirs) } diff --git a/rust/config/global.go b/rust/config/global.go index 7846d212e..4d8778093 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -37,6 +37,9 @@ var ( GlobalRustFlags = []string{ "--remap-path-prefix $$(pwd)=", + "-C codegen-units=1", + "-C opt-level=3", + "-C relocation-model=pic", } deviceGlobalRustFlags = []string{}