Skip to content

Commit

Permalink
[antlir2][toolchain] reorganize third-party deps to match expectations
Browse files Browse the repository at this point in the history
Summary:
Reorganize deps to match the expectations of the standard fbsource machinery
(see the following diff)

Test Plan:
```
❯ buck2 test fbcode//antlir/distro/toolchain/cxx/tests: fbcode//antlir/distro/toolchain/rust/tests:
Buck UI: https://www.internalfb.com/buck2/868bffa6-ae4a-4a6a-93dd-0b15a29605ad
Test UI: https://www.internalfb.com/intern/testinfra/testrun/5066549837190240
Network: Up: 19MiB  Down: 531MiB  (reSessionID-c31c7c23-abf7-4d35-a50b-619a335301a8)
Jobs completed: 324844. Time elapsed: 1:20.6s.
Cache hits: 0%. Commands: 97 (cached: 0, remote: 0, local: 97)
Tests finished: Pass 20. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: naveedgol

Differential Revision: D66893437

fbshipit-source-id: ba61b20f4f2c29a1e518a488a0719b4084b47996
  • Loading branch information
vmagro authored and facebook-github-bot committed Dec 17, 2024
1 parent 25522ca commit 87a4de8
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 29 deletions.
27 changes: 4 additions & 23 deletions antlir/distro/deps/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ 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/image_command_alias:image_command_alias.bzl", "image_command_alias")
load(":pkgconfig.bzl", "image_pkgconfig_library")

oncall("antlir")

prelude = native

image.layer(
name = "sysroot-layer",
features = [
Expand All @@ -16,6 +13,10 @@ image.layer(
# toolchains/cxx:layer, but installing it here gives us all the deps
# that clang will expect to find in `--sysroot`
"clang",
# Install some other core dependencies that we will always need
"libgcc",
"glibc-devel",
"libatomic",
]),
],
rootless = True,
Expand All @@ -30,16 +31,6 @@ package.unprivileged_dir(
visibility = ["PUBLIC"],
)

prelude.prebuilt_cxx_library(
name = "libstdc++",
exported_linker_flags = [
"-std=c++20",
"-lstdc++",
],
exported_preprocessor_flags = ["-std=c++20"],
visibility = ["PUBLIC"],
)

image.layer(
name = "base",
features = [
Expand Down Expand Up @@ -73,13 +64,3 @@ image_command_alias(
rootless = True,
visibility = ["PUBLIC"],
)

image_pkgconfig_library(
name = "rpm",
visibility = ["PUBLIC"],
)

image_pkgconfig_library(
name = "jsoncpp",
visibility = ["PUBLIC"],
)
19 changes: 19 additions & 0 deletions antlir/distro/deps/glibc/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//antlir/distro/deps:sysroot.bzl", "sysroot_dep")

oncall("antlir")

sysroot_dep(
name = "c",
)

sysroot_dep(
name = "m",
)

sysroot_dep(
name = "dl",
)

sysroot_dep(
name = "pthread",
)
8 changes: 8 additions & 0 deletions antlir/distro/deps/jsoncpp/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//antlir/distro/deps:pkgconfig.bzl", "image_pkgconfig_library")

oncall("antlir")

image_pkgconfig_library(
name = "jsoncpp",
visibility = ["PUBLIC"],
)
29 changes: 29 additions & 0 deletions antlir/distro/deps/libgcc/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("//antlir/distro/deps:sysroot.bzl", "sysroot_dep")

oncall("antlir")

prelude = native

prelude.prebuilt_cxx_library(
name = "stdc++",
exported_linker_flags = [
"-std=c++20",
"-lstdc++",
],
exported_preprocessor_flags = ["-std=c++20"],
visibility = ["PUBLIC"],
)

prelude.prebuilt_cxx_library(
name = "stdc++-legacy",
exported_preprocessor_flags = ["-I$(location //antlir/distro/deps:sysroot)/usr/include/c++/11/backward"],
visibility = ["PUBLIC"],
)

sysroot_dep(
name = "gcc_s",
)

sysroot_dep(
name = "atomic",
)
11 changes: 11 additions & 0 deletions antlir/distro/deps/openmp/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
oncall("antlir")

prelude = native

# This exists only because it's an implicit dep added on every cxx target. If it
# becomes needed by any binaries using the antlir toolchain, someone will need
# to figure out how to present it.
prelude.prebuilt_cxx_library(
name = "headers",
visibility = ["PUBLIC"],
)
5 changes: 2 additions & 3 deletions antlir/distro/deps/pkgconfig.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ _pkgconfig = rule(
def image_pkgconfig_library(
*,
name: str,
pkgconfig_name: str | None = None,
visibility: list[str] = ["PUBLIC"],
deps: list[str] = [],
exported_preprocessor_flags: list[str] = [],
compatible_with_os: list[str] = []):
# clearly separate out the pkg-config name from the target name in case they
# ever need to differ (but hopefully they don't)
pkgconfig_name = name
pkgconfig_name = pkgconfig_name or name

target_compatible_with = select({
"DEFAULT": ["antlir//antlir/distro:incompatible"],
Expand Down
11 changes: 11 additions & 0 deletions antlir/distro/deps/rpm/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("//antlir/distro/deps:pkgconfig.bzl", "image_pkgconfig_library")

oncall("antlir")

image_pkgconfig_library(
# Existing third-party copies of rpm are named 'librpm', so to be consistent
# we use 'pkgconfig(rpm)' but name it 'librpm'
name = "librpm",
pkgconfig_name = "rpm",
visibility = ["PUBLIC"],
)
21 changes: 21 additions & 0 deletions antlir/distro/deps/sysroot.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

def sysroot_dep(
*,
name: str,
link: str | None = None,
visibility: list[str] = ["PUBLIC"]):
"""
A cxx_library target that links against a library that exists in the
sysroot, but does not have any pkg-config definition, just a linker flag.
"""
native.prebuilt_cxx_library(
name = name,
exported_linker_flags = [
"-l" + (link or name),
],
visibility = visibility,
)
6 changes: 3 additions & 3 deletions antlir/distro/toolchain/cxx/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ prelude.cxx_binary(
default_target_platform = default_image_platform("centos9"),
deps = [
":dep",
"//antlir/distro/deps:jsoncpp",
"//antlir/distro/deps:libstdc++",
"//antlir/distro/deps/jsoncpp:jsoncpp",
"//antlir/distro/deps/libgcc:stdc++",
],
)

Expand All @@ -36,7 +36,7 @@ cpp_library(
_cxx_toolchain = "//antlir/distro/toolchain/cxx:toolchain",
default_target_platform = default_image_platform("centos9"),
deps = [
"//antlir/distro/deps:rpm",
"//antlir/distro/deps/rpm:librpm",
],
)

Expand Down

0 comments on commit 87a4de8

Please sign in to comment.