Skip to content

Commit

Permalink
[antlir2][toolchain] cleanup projects.bzl generation
Browse files Browse the repository at this point in the history
Summary:
Be more selective in what targets appear here, so that we can freely add
generated targets, tests, etc without having to pollute `projects.bzl`

Test Plan: Ran the generator, `projects.bzl` is unchanged

Reviewed By: naveedgol

Differential Revision: D68648576

fbshipit-source-id: b37161154583b59771f1f39a8247e5aa8bcaf7c8
  • Loading branch information
vmagro authored and facebook-github-bot committed Jan 27, 2025
1 parent 5200a10 commit afe6540
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 13 deletions.
3 changes: 2 additions & 1 deletion antlir/distro/deps/boost/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:hoist.bzl", "hoist")
load("//antlir/distro/deps:prebuilt_cxx_library.bzl", "prebuilt_cxx_library")

def boost_system_library(
*,
Expand All @@ -20,7 +21,7 @@ def boost_system_library(
path = path or "/usr/lib64/lib{}.so".format(name),
rootless = True,
)
native.prebuilt_cxx_library(
prebuilt_cxx_library(
name = name,
exported_headers = {
"": ":headers",
Expand Down
1 change: 1 addition & 0 deletions antlir/distro/deps/jemalloc/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ rpm_library(
alias(
name = "headers",
actual = ":jemalloc",
labels = ["antlir-distro-dep"],
visibility = ["PUBLIC"],
)
9 changes: 5 additions & 4 deletions antlir/distro/deps/libgcc/BUCK
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
load("//antlir/bzl:build_defs.bzl", "alias")
load("//antlir/distro/deps:prebuilt_cxx_library.bzl", "prebuilt_cxx_library")
load("//antlir/distro/deps:rpm_library.bzl", "rpm_library")
load("//antlir/distro/deps:sysroot.bzl", "sysroot_dep")

oncall("antlir")

prelude = native

sysroot_dep(
name = "stdc++",
lib = "libstdc++.so.6",
Expand All @@ -21,18 +20,19 @@ sysroot_dep(
alias(
name = "stdc++-header-unit",
actual = ":stdc++",
labels = ["antlir-distro-dep"],
visibility = ["PUBLIC"],
)

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

# This is not needed as a separate library on the versions of clang that we
# support, but keep it around for the buck2 graph
prelude.prebuilt_cxx_library(
prebuilt_cxx_library(
name = "stdc++fs",
visibility = ["PUBLIC"],
)
Expand All @@ -51,5 +51,6 @@ rpm_library(
alias(
name = "atomic-header-unit",
actual = ":atomic",
labels = ["antlir-distro-dep"],
visibility = ["PUBLIC"],
)
4 changes: 3 additions & 1 deletion antlir/distro/deps/llvm-fb/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//antlir/distro/deps:prebuilt_cxx_library.bzl", "prebuilt_cxx_library")

libs = [
"clang_rt.asan",
"clang_rt.asan_cxx",
Expand All @@ -18,7 +20,7 @@ libs = [
]

def clang_rt_library(*, name: str):
native.prebuilt_cxx_library(
prebuilt_cxx_library(
name = name,
# TODO: does this need headers too?
shared_lib = ":libs[{}]".format(name),
Expand Down
6 changes: 3 additions & 3 deletions antlir/distro/deps/openmp/BUCK
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
oncall("antlir")
load("//antlir/distro/deps:prebuilt_cxx_library.bzl", "prebuilt_cxx_library")

prelude = native
oncall("antlir")

# 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(
prebuilt_cxx_library(
name = "headers",
visibility = ["PUBLIC"],
)
10 changes: 10 additions & 0 deletions antlir/distro/deps/prebuilt_cxx_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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 prebuilt_cxx_library(*, labels = None, **kwargs):
native.prebuilt_cxx_library(
labels = (labels or []) + ["antlir-distro-dep"],
**kwargs
)
2 changes: 1 addition & 1 deletion antlir/distro/deps/projects.bxl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# LICENSE file in the root directory of this source tree.

def _query_impl(ctx: bxl.Context):
libs = ctx.uquery().kind("alias|cxx_.*", "antlir//antlir/distro/deps/...")
libs = ctx.uquery().attrfilter("labels", "antlir-distro-dep", "antlir//antlir/distro/deps/...")
deps = []
for target in libs:
if target.label.package == "antlir/distro/deps":
Expand Down
7 changes: 5 additions & 2 deletions antlir/distro/deps/rpm_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/genrule_in_image:genrule_in_image.bzl", "genrule_in_image")
load(":prebuilt_cxx_library.bzl", "prebuilt_cxx_library")

def rpm_library(
*,
Expand Down Expand Up @@ -89,14 +90,16 @@ def rpm_library(
target_compatible_with = target_compatible_with,
)

native.prebuilt_cxx_library(
prebuilt_cxx_library(
name = name,
visibility = visibility,
header_dirs = [":{}--outputs[headers]".format(name)],
shared_lib = ":{}--outputs[{}]".format(name, soname) if not header_only else None,
header_only = header_only,
preferred_linkage = "shared",
target_compatible_with = target_compatible_with,
labels = ["antlir-distro-rpm-library"],
labels = [
"antlir-distro-rpm-library",
],
**kwargs
)
4 changes: 3 additions & 1 deletion antlir/distro/deps/sysroot.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:hoist.bzl", "hoist")
load(":prebuilt_cxx_library.bzl", "prebuilt_cxx_library")

def sysroot_dep(
*,
Expand All @@ -25,10 +26,11 @@ def sysroot_dep(
visibility = [],
)

native.prebuilt_cxx_library(
prebuilt_cxx_library(
name = name,
shared_lib = ":" + lib,
preferred_linkage = "shared",
visibility = visibility,
labels = ["antlir-distro-dep"],
**kwargs
)
3 changes: 3 additions & 0 deletions antlir/distro/deps/util-linux/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ load("//antlir/bzl:build_defs.bzl", "alias")

oncall("antlir")

# This is weird, but libuuid is often referred to as a part of util-linux, but
# it's the same as the standalone libuuid directory, so just alias to there
alias(
name = "uuid",
actual = "//antlir/distro/deps/libuuid:libuuid",
labels = ["antlir-distro-dep"],
visibility = ["PUBLIC"],
)

0 comments on commit afe6540

Please sign in to comment.