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
This commit is contained in:
parent
5e7011bc14
commit
fb04c41299
3 changed files with 61 additions and 12 deletions
|
@ -31,11 +31,11 @@ const (
|
|||
|
||||
// OsType names in arch.go
|
||||
OsAndroid = "android"
|
||||
osDarwin = "darwin"
|
||||
osLinux = "linux_glibc"
|
||||
OsDarwin = "darwin"
|
||||
OsLinux = "linux_glibc"
|
||||
osLinuxMusl = "linux_musl"
|
||||
osLinuxBionic = "linux_bionic"
|
||||
osWindows = "windows"
|
||||
OsWindows = "windows"
|
||||
|
||||
// Targets in arch.go
|
||||
osArchAndroidArm = "android_arm"
|
||||
|
@ -156,11 +156,11 @@ var (
|
|||
// constraint_value for the @platforms//os:os constraint_setting
|
||||
platformOsMap = map[string]string{
|
||||
OsAndroid: "//build/bazel/platforms/os:android",
|
||||
osDarwin: "//build/bazel/platforms/os:darwin",
|
||||
osLinux: "//build/bazel/platforms/os:linux_glibc",
|
||||
OsDarwin: "//build/bazel/platforms/os:darwin",
|
||||
OsLinux: "//build/bazel/platforms/os:linux_glibc",
|
||||
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
|
||||
osLinuxBionic: "//build/bazel/platforms/os:linux_bionic",
|
||||
osWindows: "//build/bazel/platforms/os:windows",
|
||||
OsWindows: "//build/bazel/platforms/os:windows",
|
||||
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
|
||||
}
|
||||
|
||||
|
@ -192,22 +192,22 @@ var (
|
|||
// in a cyclic dependency.
|
||||
osToArchMap = map[string][]string{
|
||||
OsAndroid: {archArm, archArm64, archRiscv64, archX86, archX86_64},
|
||||
osLinux: {archX86, archX86_64},
|
||||
OsLinux: {archX86, archX86_64},
|
||||
osLinuxMusl: {archX86, archX86_64},
|
||||
osDarwin: {archArm64, archX86_64},
|
||||
OsDarwin: {archArm64, archX86_64},
|
||||
osLinuxBionic: {archArm64, archX86_64},
|
||||
// TODO(cparsons): According to arch.go, this should contain archArm, archArm64, as well.
|
||||
osWindows: {archX86, archX86_64},
|
||||
OsWindows: {archX86, archX86_64},
|
||||
}
|
||||
|
||||
osAndInApexMap = map[string]string{
|
||||
AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex",
|
||||
AndroidPlatform: "//build/bazel/rules/apex:system",
|
||||
osDarwin: "//build/bazel/platforms/os:darwin",
|
||||
osLinux: "//build/bazel/platforms/os:linux_glibc",
|
||||
OsDarwin: "//build/bazel/platforms/os:darwin",
|
||||
OsLinux: "//build/bazel/platforms/os:linux_glibc",
|
||||
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
|
||||
osLinuxBionic: "//build/bazel/platforms/os:linux_bionic",
|
||||
osWindows: "//build/bazel/platforms/os:windows",
|
||||
OsWindows: "//build/bazel/platforms/os:windows",
|
||||
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey,
|
||||
}
|
||||
|
||||
|
|
|
@ -4657,3 +4657,49 @@ cc_library {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
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": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1254,6 +1254,9 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
|
|||
}
|
||||
|
||||
la.additionalLinkerInputs.SetSelectValue(axis, config, additionalLinkerInputs)
|
||||
if axis == bazel.OsConfigurationAxis && (config == bazel.OsDarwin || config == bazel.OsLinux || config == bazel.OsWindows) {
|
||||
linkerFlags = append(linkerFlags, props.Host_ldlibs...)
|
||||
}
|
||||
la.linkopts.SetSelectValue(axis, config, linkerFlags)
|
||||
|
||||
if axisFeatures != nil {
|
||||
|
|
Loading…
Reference in a new issue