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/bp2build.go b/cc/bp2build.go
index 22bd90b..ebba9d1 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -364,6 +364,7 @@
wholeArchiveDeps bazel.LabelListAttribute
systemDynamicDeps bazel.LabelListAttribute
+ linkCrt bazel.BoolAttribute
useLibcrt bazel.BoolAttribute
linkopts bazel.StringListAttribute
versionScript bazel.LabelAttribute
@@ -398,6 +399,7 @@
var linkopts bazel.StringListAttribute
var versionScript bazel.LabelAttribute
+ var linkCrt bazel.BoolAttribute
var useLibcrt bazel.BoolAttribute
var stripKeepSymbols bazel.BoolAttribute
@@ -418,6 +420,9 @@
}
}
+ // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
+ var disallowedArchVariantCrt bool
+
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
for config, props := range configToProps {
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
@@ -457,10 +462,23 @@
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
}
useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt())
+
+ // it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
+ if baseLinkerProps.crt() != nil {
+ if axis == bazel.NoConfigAxis {
+ linkCrt.SetSelectValue(axis, config, baseLinkerProps.crt())
+ } else if axis == bazel.ArchConfigurationAxis {
+ disallowedArchVariantCrt = true
+ }
+ }
}
}
}
+ if disallowedArchVariantCrt {
+ ctx.ModuleErrorf("nocrt is not supported for arch variants")
+ }
+
type productVarDep struct {
// the name of the corresponding excludes field, if one exists
excludesField string
@@ -530,6 +548,7 @@
wholeArchiveDeps: wholeArchiveDeps,
systemDynamicDeps: systemSharedDeps,
+ linkCrt: linkCrt,
linkopts: linkopts,
useLibcrt: useLibcrt,
versionScript: versionScript,