summaryrefslogtreecommitdiff
path: root/rust/library.go
diff options
context:
space:
mode:
author ThiƩbaud Weksteen <tweek@google.com> 2020-08-27 13:48:36 +0200
committer ThiƩbaud Weksteen <tweek@google.com> 2020-08-28 10:50:17 +0200
commitfabaff6bd74cda382dd7d5152df7362bffe233a3 (patch)
treeb411acff92ba05568af230b00db941bb03e9b7b5 /rust/library.go
parent31f1bb80efe196f2340ec88a6cc374963e7aa7b5 (diff)
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
Diffstat (limited to 'rust/library.go')
-rw-r--r--rust/library.go22
1 files changed, 15 insertions, 7 deletions
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
}