From 4111c52fa2fd19efce3636c940b893ffa3b5602e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 8 Mar 2022 11:56:27 -0800 Subject: [PATCH 1/2] Support building python pars against static or shared musl libc Support building python pars against musl libc by either adding libc_musl as an install dependency or using the static version of the python launchers. Bug: 179809553 Test: m USE_HOST_MUSL=true apexer deapexer Test: m USE_HOST_MUSL=true BUILD_HOST_static=true apexer deapexer Change-Id: I4a56efb227bea746836eb785d929eb4b5d8e15f1 --- python/python.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/python.go b/python/python.go index 734ac57f1..b100cc318 100644 --- a/python/python.go +++ b/python/python.go @@ -423,6 +423,9 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { if ctx.Target().Os.Bionic() { launcherSharedLibDeps = append(launcherSharedLibDeps, "libc", "libdl", "libm") } + if ctx.Target().Os == android.LinuxMusl && !ctx.Config().HostStaticBinaries() { + launcherSharedLibDeps = append(launcherSharedLibDeps, "libc_musl") + } switch p.properties.Actual_version { case pyVersion2: @@ -432,6 +435,7 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { if p.bootstrapper.autorun() { launcherModule = "py2-launcher-autorun" } + launcherSharedLibDeps = append(launcherSharedLibDeps, "libc++") case pyVersion3: @@ -441,6 +445,9 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { if p.bootstrapper.autorun() { launcherModule = "py3-launcher-autorun" } + if ctx.Config().HostStaticBinaries() && ctx.Target().Os == android.LinuxMusl { + launcherModule += "-static" + } if ctx.Device() { launcherSharedLibDeps = append(launcherSharedLibDeps, "liblog") From 7e2092a274f215dee379dbe8c1bc4803d55ea93a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 8 Mar 2022 13:15:58 -0800 Subject: [PATCH 2/2] Support BUILD_HOST_static=1 for musl and linux_bionic builds BUILD_HOST_static=1 is useful for musl and linux_bionic builds to produce standalone static binaries. Bug: 179809553 Test: m USE_HOST_MUSL=true BUILD_HOST_static=1 apexer deapexer Change-Id: Iac0f4ca92c3ffb27bccd4cac15a6ef9fa5924471 --- cc/binary.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cc/binary.go b/cc/binary.go index 0fe44903c..9262f217e 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -220,18 +220,18 @@ func newBinary(hod android.HostOrDeviceSupported, bazelable bool) (*Module, *bin func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) { binary.baseLinker.linkerInit(ctx) - if !ctx.toolchain().Bionic() && !ctx.toolchain().Musl() { - if ctx.Os() == android.Linux { - // Unless explicitly specified otherwise, host static binaries are built with -static - // if HostStaticBinaries is true for the product configuration. - if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() { - binary.Properties.Static_executable = BoolPtr(true) - } - } else { - // Static executables are not supported on Darwin or Windows - binary.Properties.Static_executable = nil + if ctx.Os().Linux() && ctx.Host() { + // Unless explicitly specified otherwise, host static binaries are built with -static + // if HostStaticBinaries is true for the product configuration. + if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() { + binary.Properties.Static_executable = BoolPtr(true) } } + + if ctx.Darwin() || ctx.Windows() { + // Static executables are not supported on Darwin or Windows + binary.Properties.Static_executable = nil + } } func (binary *binaryDecorator) static() bool {