diff options
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 |
commit | fabaff6bd74cda382dd7d5152df7362bffe233a3 (patch) | |
tree | b411acff92ba05568af230b00db941bb03e9b7b5 /rust/binary.go | |
parent | 31f1bb80efe196f2340ec88a6cc374963e7aa7b5 (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/binary.go')
-rw-r--r-- | rust/binary.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/rust/binary.go b/rust/binary.go index d287a06ef..1d02453db 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -28,6 +28,7 @@ type BinaryCompilerProperties struct { type binaryDecorator struct { *baseCompiler + stripper Stripper Properties BinaryCompilerProperties } @@ -86,7 +87,8 @@ func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { func (binary *binaryDecorator) compilerProps() []interface{} { return append(binary.baseCompiler.compilerProps(), - &binary.Properties) + &binary.Properties, + &binary.stripper.StripProperties) } func (binary *binaryDecorator) nativeCoverage() bool { @@ -95,16 +97,20 @@ func (binary *binaryDecorator) nativeCoverage() bool { func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix() - srcPath, _ := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs) - outputFile := android.PathForModuleOut(ctx, fileName) - binary.unstrippedOutputFile = outputFile flags.RustFlags = append(flags.RustFlags, deps.depFlags...) flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...) outputs := TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) + + if binary.stripper.NeedsStrip(ctx) { + strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName) + binary.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile) + binary.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile) + } + binary.coverageFile = outputs.coverageFile var coverageFiles android.Paths |