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
This commit is contained in:
Jingwen Chen
2021-09-17 11:38:09 +00:00
parent 8f22274297
commit 6ada589f6e
5 changed files with 190 additions and 37 deletions

View File

@@ -252,6 +252,7 @@ type bazelCcLibraryAttributes struct {
// This is shared only.
Version_script bazel.LabelAttribute
Link_crt bazel.BoolAttribute
// Common properties shared between both shared and static variants.
Shared staticOrSharedAttributes
@@ -321,6 +322,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Linkopts: linkerAttrs.linkopts,
Link_crt: linkerAttrs.linkCrt,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
@@ -2415,6 +2417,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
Asflags: asFlags,
Linkopts: linkerAttrs.linkopts,
Link_crt: linkerAttrs.linkCrt,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
@@ -2472,6 +2475,7 @@ type bazelCcLibrarySharedAttributes struct {
staticOrSharedAttributes
Linkopts bazel.StringListAttribute
Link_crt bazel.BoolAttribute // Only for linking shared library (and cc_binary)
Use_libcrt bazel.BoolAttribute
Rtti bazel.BoolAttribute
Stl *string