Express no{,_lib}crt via features vs attrs

Given that we can map them directly to disabling the
corresponding Bazel features: `-{link_,use_lib}crt`

Test: Existing (adapted) Unit Tests
Test: bp2build.sh
Change-Id: Ib502f6fb929ace8e86a1001e3cc21f399317500c
This commit is contained in:
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux
2023-01-30 22:53:04 +00:00
parent 92ac65952d
commit 01ec55ec92
7 changed files with 70 additions and 106 deletions

View File

@@ -237,29 +237,14 @@ type BaseLinkerProperties struct {
Exclude_shared_libs []string `android:"arch_variant"`
}
func invertBoolPtr(value *bool) *bool {
if value == nil {
return nil
}
ret := !(*value)
return &ret
func (blp *BaseLinkerProperties) crt() bool {
// Since crt is enabled for almost every module compiling against the Bionic runtime,
// we interpret `nil` as enabled.
return blp.Nocrt == nil || !*blp.Nocrt
}
func (blp *BaseLinkerProperties) crt() *bool {
val := invertBoolPtr(blp.Nocrt)
if val != nil && *val {
// == True
//
// Since crt is enabled for almost every module compiling against the Bionic runtime,
// use `nil` when it's enabled, and rely on the Starlark macro to set it to True by default.
// This keeps the BUILD files clean.
return nil
}
return val // can be False or nil
}
func (blp *BaseLinkerProperties) libCrt() *bool {
return invertBoolPtr(blp.No_libcrt)
func (blp *BaseLinkerProperties) libCrt() bool {
return blp.No_libcrt == nil || !*blp.No_libcrt
}
func NewBaseLinker(sanitize *sanitize) *baseLinker {
@@ -392,7 +377,7 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
if ctx.toolchain().Bionic() {
// libclang_rt.builtins has to be last on the command line
if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
if linker.Properties.libCrt() && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
@@ -415,7 +400,7 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
}
} else if ctx.toolchain().Musl() {
if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
if linker.Properties.libCrt() && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
}