From fabaff6bd74cda382dd7d5152df7362bffe233a3 Mon Sep 17 00:00:00 2001 From: ThiƩbaud Weksteen Date: Thu, 27 Aug 2020 13:48:36 +0200 Subject: rust: strip libraries and binaries Reuses the cc.Stripper logic. Abstracts Stripper to avoid the spreading of references to the cc package. rustc requires unstripped libraries (precisely, with the `.rustc` section) when building dependent targets. Contrary to cc, the output of a compiler module will remain unstripped and only an extra build rule will be added. This rule will be referenced at install time (in baseCompiler.install or androidmk). This change drastically reduces the size of the installed libraries: (unstripped, from out/target/product/crosshatch/system) $ find . -name \*.dylib.so -print0 | du -c --files0-from=- 149996 total (stripped, with this change) $ find . -name \*.dylib.so -print0 | du -c --files0-from=- 42380 total Bug: 153430439 Test: cd external/rust; mma Change-Id: I94fd8bbcec97e0610aa325d3db4460be84d01734 --- rust/library.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'rust/library.go') diff --git a/rust/library.go b/rust/library.go index 450c9d429..a44293307 100644 --- a/rust/library.go +++ b/rust/library.go @@ -78,6 +78,7 @@ type LibraryMutatedProperties struct { type libraryDecorator struct { *baseCompiler *flagExporter + stripper Stripper Properties LibraryCompilerProperties MutatedProperties LibraryMutatedProperties @@ -338,7 +339,8 @@ func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorat func (library *libraryDecorator) compilerProps() []interface{} { return append(library.baseCompiler.compilerProps(), &library.Properties, - &library.MutatedProperties) + &library.MutatedProperties, + &library.stripper.StripProperties) } func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { @@ -371,7 +373,8 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F } func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { - var outputFile android.WritablePath + var outputFile android.ModuleOutPath + var fileName string var srcPath android.Path if library.sourceProvider != nil { @@ -391,31 +394,37 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa } if library.rlib() { - fileName := library.getStem(ctx) + ctx.toolchain().RlibSuffix() + fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix() outputFile = android.PathForModuleOut(ctx, fileName) outputs := TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) library.coverageFile = outputs.coverageFile } else if library.dylib() { - fileName := library.getStem(ctx) + ctx.toolchain().DylibSuffix() + fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix() outputFile = android.PathForModuleOut(ctx, fileName) outputs := TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) library.coverageFile = outputs.coverageFile } else if library.static() { - fileName := library.getStem(ctx) + ctx.toolchain().StaticLibSuffix() + fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix() outputFile = android.PathForModuleOut(ctx, fileName) outputs := TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) library.coverageFile = outputs.coverageFile } else if library.shared() { - fileName := library.sharedLibFilename(ctx) + fileName = library.sharedLibFilename(ctx) outputFile = android.PathForModuleOut(ctx, fileName) outputs := TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) library.coverageFile = outputs.coverageFile } + if !library.rlib() && library.stripper.NeedsStrip(ctx) { + strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName) + library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile) + library.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile) + } + var coverageFiles android.Paths if library.coverageFile != nil { coverageFiles = append(coverageFiles, library.coverageFile) @@ -430,7 +439,6 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa library.exportDepFlags(deps.depFlags...) library.exportLinkObjects(deps.linkObjects...) } - library.unstrippedOutputFile = outputFile return outputFile } -- cgit v1.2.3-59-g8ed1b