bp2build support for host_ldlibs
host_ldlibs are used during linking. Set these in `linkopts` for now.
Note that this CL does not do the `CheckBadHostLdLibs` validation of
Soong. There are some different ways to do this, and these are being
discussed in b/216626461. It is likely that we will need to create a new
property `host_ldlibs` to do the validation. But for now, re-use
`linkopts`.
Bug: 216626461
Test: bp2build unit tests
Change-Id: Id4c77e4460fb1fb003fa58ea27bab5b50ea8cefe
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 17b1608..7cccec1 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -4657,3 +4657,49 @@
},
})
}
+
+func TestCcLibraryHostLdLibs(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_binary linker flags for host_ldlibs",
+ ModuleTypeUnderTest: "cc_binary",
+ ModuleTypeUnderTestFactory: cc.BinaryFactory,
+ Blueprint: soongCcLibraryPreamble + `cc_binary {
+ name: "a",
+ host_supported: true,
+ ldflags: ["-lcommon"],
+ target: {
+ linux: {
+ host_ldlibs: [
+ "-llinux",
+ ],
+ },
+ darwin: {
+ ldflags: ["-ldarwinadditional"],
+ host_ldlibs: [
+ "-ldarwin",
+ ],
+ },
+ windows: {
+ host_ldlibs: [
+ "-lwindows",
+ ],
+ },
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("cc_binary", "a", AttrNameToString{
+ "linkopts": `["-lcommon"] + select({
+ "//build/bazel/platforms/os:darwin": [
+ "-ldarwinadditional",
+ "-ldarwin",
+ ],
+ "//build/bazel/platforms/os:linux_glibc": ["-llinux"],
+ "//build/bazel/platforms/os:windows": ["-lwindows"],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}