Skip to content

Commit

Permalink
[cxx] use antlir distro toolchain when building for distro platform
Browse files Browse the repository at this point in the history
Summary:
The previous diff makes a CXX toolchain that uses antlir2 images to build cxx
targets that link against an upstream centos platform, rather than the fbcode
platform.

This diff automatically selects this toolchain when the platform constraint is
active.

Test Plan:
```
❯ buck2 test fbcode//antlir/distro/toolchain/cxx/tests:
Buck UI: https://www.internalfb.com/buck2/bf305863-ab98-4c05-923d-40450a119488
Test UI: https://www.internalfb.com/intern/testinfra/testrun/2251800074356858
Tests finished: Pass 8. Fail 0. Fatal 0. Skip 0. Build failure 0
```

```
❯ buck2 test -c fbcode.arch=aarch64 fbcode//antlir/distro/toolchain/cxx/tests:
Buck UI: https://www.internalfb.com/buck2/d79f7370-2e29-411a-ac64-53789f28b9da
Test UI: https://www.internalfb.com/intern/testinfra/testrun/17169973639622886
Tests finished: Pass 8. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: dtolnay

Differential Revision: D66986700

fbshipit-source-id: d96336154a0c9e5924a8a446e30e805aa4b4241f
  • Loading branch information
vmagro authored and facebook-github-bot committed Jan 14, 2025
1 parent b6559ac commit cf42109
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions antlir/distro/toolchain/cxx/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@ load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/bzl/package:defs.bzl", "package")
load("//antlir/antlir2/testing:image_test.bzl", "image_python_test")
load("//antlir/bzl:build_defs.bzl", "cpp_library")
load("//antlir/bzl:build_defs.bzl", "cpp_binary", "cpp_library")
load("//antlir/distro/platform:defs.bzl", "alias_for_current_image_platform", "default_image_platform")

oncall("antlir")

prelude = native

prelude.cxx_binary(
cpp_binary(
# @autodeps-skip
name = "main",
srcs = ["main.cpp"],
_cxx_toolchain = "//antlir/distro/toolchain/cxx:toolchain",
# This should only be built for a centos system platform, use compatibility
# attrs to guarantee that
compatible_with = [
"//antlir/distro:build-for-distro",
],
default_target_platform = default_image_platform("centos9"),
platform_preprocessor_flags = [
deps = [
":dep",
":platform-preprocessor-flags",
"//antlir/distro/deps/jsoncpp:jsoncpp",
"//antlir/distro/deps/libgcc:stdc++",
],
)

cpp_library(
# @autodeps-skip
name = "dep",
srcs = ["dep.cpp"],
headers = ["dep.h"],
default_target_platform = default_image_platform("centos9"),
deps = [
"//antlir/distro/deps/rpm:librpm",
],
)

prelude.cxx_library(
name = "platform-preprocessor-flags",
exported_platform_preprocessor_flags = [
(
"centos9-x86_64$",
['-DPLATFORM_PREPROCESSOR_FLAG="centos9-x86_64"'],
Expand All @@ -39,23 +59,6 @@ prelude.cxx_binary(
['-DPLATFORM_PREPROCESSOR_FLAG="centos10-aarch64"'],
),
],
deps = [
":dep",
"//antlir/distro/deps/jsoncpp:jsoncpp",
"//antlir/distro/deps/libgcc:stdc++",
],
)

cpp_library(
# @autodeps-skip
name = "dep",
srcs = ["dep.cpp"],
headers = ["dep.h"],
_cxx_toolchain = "//antlir/distro/toolchain/cxx:toolchain",
default_target_platform = default_image_platform("centos9"),
deps = [
"//antlir/distro/deps/rpm:librpm",
],
)

alias_for_current_image_platform(
Expand Down

0 comments on commit cf42109

Please sign in to comment.