Handle no_libcrt in bp2build.
Test: ci/bp2build.sh
Bug: 187928307
Change-Id: Ib80c4318169652b322e5d878c8784679e42f87dd
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 752d43b..211fe5e 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -489,6 +489,7 @@
dynamicDeps bazel.LabelListAttribute
wholeArchiveDeps bazel.LabelListAttribute
exportedDeps bazel.LabelListAttribute
+ useLibcrt bazel.BoolAttribute
linkopts bazel.StringListAttribute
versionScript bazel.LabelAttribute
}
@@ -512,6 +513,7 @@
var wholeArchiveDeps bazel.LabelListAttribute
var linkopts bazel.StringListAttribute
var versionScript bazel.LabelAttribute
+ var useLibcrt bazel.BoolAttribute
for _, linkerProps := range module.linker.linkerProps() {
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
@@ -535,6 +537,7 @@
if baseLinkerProps.Version_script != nil {
versionScript.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
}
+ useLibcrt.Value = baseLinkerProps.libCrt()
break
}
@@ -559,6 +562,7 @@
if baseLinkerProps.Version_script != nil {
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
}
+ useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt())
}
}
}
@@ -624,6 +628,7 @@
dynamicDeps: dynamicDeps,
wholeArchiveDeps: wholeArchiveDeps,
linkopts: linkopts,
+ useLibcrt: useLibcrt,
versionScript: versionScript,
}
}
diff --git a/cc/library.go b/cc/library.go
index c88c29a..5995e98 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -234,6 +234,7 @@
Whole_archive_deps bazel.LabelListAttribute
Includes bazel.StringListAttribute
Linkopts bazel.StringListAttribute
+ Use_libcrt bazel.BoolAttribute
// Attributes pertaining to shared variant.
Shared_srcs bazel.LabelListAttribute
@@ -320,6 +321,7 @@
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Includes: exportedIncludes,
Linkopts: linkerAttrs.linkopts,
+ Use_libcrt: linkerAttrs.useLibcrt,
Shared_srcs: sharedAttrs.srcs,
Shared_srcs_c: sharedAttrs.srcs_c,
@@ -2262,6 +2264,7 @@
Whole_archive_deps bazel.LabelListAttribute
Linkopts bazel.StringListAttribute
Linkstatic bool
+ Use_libcrt bazel.BoolAttribute
Includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
@@ -2298,6 +2301,7 @@
Linkopts: linkerAttrs.linkopts,
Linkstatic: true,
+ Use_libcrt: linkerAttrs.useLibcrt,
Includes: exportedIncludes,
Cppflags: compilerAttrs.cppFlags,
diff --git a/cc/linker.go b/cc/linker.go
index 1d8c649..895931a 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -200,6 +200,18 @@
Exclude_shared_libs []string `android:"arch_variant"`
}
+func invertBoolPtr(value *bool) *bool {
+ if value == nil {
+ return nil
+ }
+ ret := !(*value)
+ return &ret
+}
+
+func (blp *BaseLinkerProperties) libCrt() *bool {
+ return invertBoolPtr(blp.No_libcrt)
+}
+
func NewBaseLinker(sanitize *sanitize) *baseLinker {
return &baseLinker{sanitize: sanitize}
}