Skip to content

Commit

Permalink
[antlir2][toolchain] better cxx platform names
Browse files Browse the repository at this point in the history
Summary:
Set the platform name to a better (more clear for regex matching) string,
excluding the `toolchain--` prefix.
Also set the `deps_aliases` to express that these are `linux-(aarch64|x86_64)`
platforms.

Test Plan:
```
❯ buck audit providers fbcode//antlir/distro/toolchain/cxx:toolchain
...

    CxxPlatformInfo(
      name="centos9-x86_64",
      deps_aliases=[ "linux-x86_64" ]
    )
  ])

❯ buck2 test fbcode//antlir/distro/toolchain/cxx/tests:
Buck UI: https://www.internalfb.com/buck2/d9a316aa-9312-43c2-951e-80190a159d87
Test UI: https://www.internalfb.com/intern/testinfra/testrun/16888498667264438
Tests finished: Pass 17. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: naveedgol

Differential Revision: D67764044

fbshipit-source-id: 09eeab593adfb46a4c94c2deac41b578d626615c
  • Loading branch information
vmagro authored and facebook-github-bot committed Jan 17, 2025
1 parent 2f24111 commit 77e3e44
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions antlir/distro/toolchain/cxx/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# LICENSE file in the root directory of this source tree.

load("//antlir/antlir2/bzl:configured_alias.bzl", "antlir2_configured_alias")
load("//antlir/antlir2/bzl:selects.bzl", "selects")
load("//antlir/antlir2/bzl/package:defs.bzl", "package")
load("//antlir/antlir2/image_command_alias:image_command_alias.bzl", "image_command_alias")
load("//antlir/antlir2/os:oses.bzl", "OSES")
Expand All @@ -28,6 +29,8 @@ def _include_sysroot(sysroot: str, flag: str) -> list[str]:
def _single_image_cxx_toolchain(
*,
name: str,
platform_name,
platform_deps_aliases,
layer: str,
sysroot: str = "antlir//antlir/distro/deps:sysroot",
visibility: list[str] = []):
Expand All @@ -49,6 +52,8 @@ def _single_image_cxx_toolchain(

native.cxx_toolchain(
name = name,
platform_name = platform_name,
platform_deps_aliases = platform_deps_aliases,
archiver = _layer_tool(name, "llvm-ar"),
archiver_type = "gnu",
archiver_flags = _llvm_base_args,
Expand Down Expand Up @@ -83,38 +88,18 @@ def image_cxx_toolchain(
sysroot: str = "antlir//antlir/distro/deps:sysroot",
visibility: list[str] = []):
oses = [os for os in OSES if os.has_platform_toolchain]
for os in oses:
antlir2_configured_alias(
name = "{}--{}--layer".format(name, os.name),
actual = layer,
default_os = os.name,
)
for arch in os.architectures:
# despite the fact that this has no arch-specific configuration, the
# toolchain name is used by the cxx rules `_*_platform` attrs (eg
# `platform_compiler_flags`) and so it should have an architecture
# to match on
_single_image_cxx_toolchain(
name = "{}--{}-{}".format(name, os.name, arch.name),
layer = ":{}--{}--layer".format(name, os.name),
sysroot = sysroot,
visibility = [],
)

# The "real" toolchain is actually an alias that depends on the selected OS.
# This is necessary because all the tools listed above (clang, ld.lld, etc)
# are exec_deps which do not inherit the target configuration, but we want
# them to match the target platform! As a workaround, we select the entire
# toolchain with "pre-configured" exec_deps that match the target os version
# (but maybe not the target os architecture!)
return prelude.toolchain_alias(
prelude.toolchain_alias(
name = name,
actual = select(
{
os.select_key: select({
arch.select_key: ":{}--{}-{}".format(name, os.name, arch.name)
for arch in os.architectures
})
os.select_key: ":{}--{}".format(name, os.name)
for os in oses
} |
# This will never actually be configured as DEFAULT for a real
Expand All @@ -123,7 +108,28 @@ def image_cxx_toolchain(
# the default when looking up this target directly (instead of
# preconfigured as a dependency of something using an antlir
# distro platform)
{"DEFAULT": ":{}--{}-{}".format(name, oses[0].name, oses[0].architectures[0].name)},
{"DEFAULT": ":{}--{}".format(name, oses[0].name)},
),
visibility = visibility,
)

for os in oses:
antlir2_configured_alias(
name = "{}--{}--layer".format(name, os.name),
actual = layer,
default_os = os.name,
)
_single_image_cxx_toolchain(
name = "{}--{}".format(name, os.name),
platform_name = selects.apply(select({
"ovr_config//cpu:arm64": "aarch64",
"ovr_config//cpu:x86_64": "x86_64",
}), lambda arch: os.name + "-" + arch),
platform_deps_aliases = select({
"ovr_config//cpu:arm64": ["linux-aarch64"],
"ovr_config//cpu:x86_64": ["linux-x86_64"],
}),
layer = ":{}--{}--layer".format(name, os.name),
sysroot = sysroot,
visibility = [],
)

0 comments on commit 77e3e44

Please sign in to comment.