Add support for nocrt by translating it to link_crt in bp2build.
If nocrt is true, then the compilation for cc_shared_library,
cc_binary (shared or static binaries) will _not_ link against their
respective crtbegin and crtend libraries.
nocrt is true only for the Bionic libraries themselves. For everything
else that links against the Bionic runtime, crtbegin and crtend
libraries are used. This makes the "nocrt: false" case the majority.
Hence, if nocrt is explicitly false, we omit the generating attribute in
bp2build.
If nocrt is explicitly true (link_crt is false), the Starlark macro will
disable the link_crt cc_toolchain feature.
Test: new tests
Test: CI
Fixes: 187928070
Fixes: 197946668
Change-Id: I8947789930e599dc802d8eae440859257d044475
diff --git a/cc/linker.go b/cc/linker.go
index 0d612b5..20e377c 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -238,6 +238,19 @@
return &ret
}
+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)
}