Skip to content

Commit 9ac90bd

Browse files
authored
Start switching pkg_install usage to know the full path of where to install things. (#43487)
[ABLD-302] Start switching pkg_install usage to know the full path of where to install things. - Restore the ability to have an addition prefix on so_symlink. - Change --dest_dir={install_dir}/embedded to --dest_dir={install_dir} - Add prefix='embedded' to things we push This did some of the libraries. I can do the rest in a followup or in this PR. # Rationale As we start installing more, we will have some pieces that go to embedded, and others that do not. It will be easier to understand if all the install instances use the single destdir. Eventually, we can create targets like //pkg/install_dir:install, which is a big pkg_install of all the dependencies and config scripts. Then the whole thing gets built with a single `bazel run -- //opt/datadog/lib:install --destdir='#{install_dir}'. When we get multiple remote executors, it can all dispatch in parallel. The next release of rules_pkg will allow destdir to come from a build flag. The need for that is to automate build time genrules where we must brand the dest_dir into a binary. At that point we can also use the command line dest_dir in the pkg_install command, eliminating the need to use --dest_dir on the command lines in .rb files. [ABLD-302]: https://datadoghq.atlassian.net/browse/ABLD-302?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: tony.aiuto <[email protected]>
1 parent acb0631 commit 9ac90bd

File tree

9 files changed

+34
-35
lines changed

9 files changed

+34
-35
lines changed

bazel/rules/so_symlink.bzl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ _SPECS = [
66
struct(os = "windows", prefix = "bin/", format = "{}.dll"),
77
]
88

9-
def _gen_targets(base_name, src, libname, version, spec):
9+
def _gen_targets(base_name, src, libname, version, prefix, spec):
1010
name = "{}_{}".format(base_name, spec.os)
1111
platform = "@platforms//os:{}".format(spec.os)
12+
dest_prefix = (prefix + "/" + spec.prefix) if prefix else spec.prefix
1213

1314
# Windows: no symlinks, no renaming - just copy the DLL as-is
1415
if spec.os == "windows":
1516
pkg_files(
1617
name = name,
1718
srcs = [src],
18-
prefix = spec.prefix,
19+
prefix = dest_prefix,
1920
target_compatible_with = [platform],
2021
)
2122
return platform, ":{}".format(name)
@@ -26,7 +27,7 @@ def _gen_targets(base_name, src, libname, version, spec):
2627
pkg_files(
2728
name = targets[-1],
2829
srcs = [src],
29-
prefix = spec.prefix,
30+
prefix = dest_prefix,
3031
renames = {src: target},
3132
target_compatible_with = [platform],
3233
)
@@ -39,7 +40,7 @@ def _gen_targets(base_name, src, libname, version, spec):
3940
targets.append("{}_{}".format(name, link_name))
4041
pkg_mklink(
4142
name = targets[-1],
42-
link_name = "{}{}".format(spec.prefix, link),
43+
link_name = "{}{}".format(dest_prefix, link),
4344
target = target,
4445
target_compatible_with = [platform],
4546
)
@@ -48,8 +49,8 @@ def _gen_targets(base_name, src, libname, version, spec):
4849
pkg_filegroup(name = name, srcs = targets, target_compatible_with = [platform])
4950
return platform, ":{}".format(name)
5051

51-
def so_symlink(name, src, libname, version):
52-
"""Creates shared library packaging appropriate for each platform.
52+
def so_symlink(name, src, libname = None, version = None, prefix = ""):
53+
"""Creates shared library symlink chain following Unix conventions.
5354
5455
Unix (Linux/macOS): Generates the common multilevel symlink hierarchy for shared libraries:
5556
- `real name`: actual file with full version (e.g., libreadline.so.3.0 / libreadline.3.0.dylib)
@@ -64,9 +65,10 @@ def so_symlink(name, src, libname, version):
6465
name: Name of the generated pkg_filegroup
6566
src: Label of the cc_shared_library to package
6667
libname: Library name without extension (e.g., "libreadline")
68+
prefix: Installation directory prefix (default: "")
6769
version: Full version string (e.g., "3.0", ignored on Windows)
6870
"""
6971
native.alias(
7072
name = name,
71-
actual = select(dict([_gen_targets(name, src, libname, version, spec) for spec in _SPECS])),
73+
actual = select(dict([_gen_targets(name, src, libname, version, prefix, spec) for spec in _SPECS])),
7274
)

deps/attr/attr.BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ so_symlink(
9797
src = ":attr",
9898
libname = "libattr",
9999
version = "1.1.2501",
100+
prefix = "embedded",
100101
)
101102

102103
pkg_files(
103104
name = "hdr_files",
104105
srcs = _PUBLIC_HEADERS,
105-
prefix = "include/attr/",
106+
prefix = "embedded/include/attr/",
106107
)
107108

108109
expand_template(
@@ -122,7 +123,7 @@ expand_template(
122123
pkg_files(
123124
name = "pc_file",
124125
srcs = [":gen_pkgconfig"],
125-
prefix = "lib/pkgconfig",
126+
prefix = "embedded/lib/pkgconfig",
126127
)
127128

128129
pkg_install(

deps/bzip2.BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ cc_shared_library(
138138

139139
pkg_mklink(
140140
name = "so_major_minor",
141-
link_name = "lib/libbz2.so.1.0",
141+
link_name = "embedded/lib/libbz2.so.1.0",
142142
target = SONAME,
143143
)
144144

145145
pkg_mklink(
146146
name = "so_major",
147-
link_name = "lib/libbz2.so.1",
147+
link_name = "embedded/lib/libbz2.so.1",
148148
target = SONAME,
149149
)
150150

151151
pkg_mklink(
152152
name = "so",
153-
link_name = "lib/libbz2.so",
153+
link_name = "embedded/lib/libbz2.so",
154154
target = SONAME,
155155
)
156156

@@ -161,13 +161,13 @@ pkg_files(
161161
# Note: you would think you can put :so and other links here, but pkg_files
162162
# seems to drop links in srcs.
163163
],
164-
prefix = "lib",
164+
prefix = "embedded/lib",
165165
)
166166

167167
pkg_files(
168168
name = "hdr_files",
169169
srcs = _PUBLIC_HEADERS,
170-
prefix = "include",
170+
prefix = "embedded/include",
171171
)
172172

173173
pkg_install(

deps/zlib.BUILD.bazel

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,13 @@ so_symlink(
132132
src = ":z",
133133
libname = "libz",
134134
version = "1.3.1",
135+
prefix = "embedded",
135136
)
136137

137138
pkg_files(
138139
name = "hdr_files",
139140
srcs = _ZLIB_PUBLIC_HEADERS,
140-
prefix = "include",
141-
)
142-
143-
pkg_install(
144-
name = "install",
145-
srcs = [
146-
":hdr_files",
147-
":lib_files",
148-
],
141+
prefix = "embedded/include",
149142
)
150143

151144
copy_file(
@@ -159,11 +152,14 @@ pkg_files(
159152
srcs = [
160153
":renamed_license",
161154
],
155+
prefix = "LICENSES",
162156
)
163157

164158
pkg_install(
165-
name = "install_license",
159+
name = "install",
166160
srcs = [
161+
":hdr_files",
162+
":lib_files",
167163
":license_files",
168164
],
169165
)

deps/zstd.BUILD.bazel

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
load("@@//bazel/rules:so_symlink.bzl", "so_symlink")
2-
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
32
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
3+
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
4+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_shared_library")
45
load("@rules_license//rules:license.bzl", "license")
5-
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
66
load("@rules_pkg//pkg:install.bzl", "pkg_install")
7-
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_shared_library")
7+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
88

99
package(default_visibility = ["//visibility:private"])
1010

@@ -90,12 +90,13 @@ so_symlink(
9090
libname = "libzstd",
9191
src = ":zstd",
9292
version = _VERSION,
93+
prefix = "embedded",
9394
)
9495

9596
pkg_files(
9697
name = "hdr_files",
9798
srcs = _PUBLIC_HEADERS,
98-
prefix = "include/",
99+
prefix = "embedded/include",
99100
)
100101

101102
expand_template(
@@ -110,13 +111,13 @@ expand_template(
110111
"@VERSION@": _VERSION,
111112
"@LIBS_MT@": "",
112113
"@LIBS_PRIVATE@": "",
113-
}
114+
},
114115
)
115116

116117
pkg_files(
117118
name = "pc_file",
118119
srcs = [":gen_pkgconfig"],
119-
prefix = "lib/pkgconfig",
120+
prefix = "embedded/lib/pkgconfig",
120121
)
121122

122123
pkg_install(

omnibus/config/software/attr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
relative_path "#{name}-#{version}"
3030

3131
build do
32-
command_on_repo_root "bazelisk run -- @attr//:install --destdir='#{install_dir}/embedded'"
32+
command_on_repo_root "bazelisk run -- @attr//:install --destdir='#{install_dir}'"
3333
command_on_repo_root "bazelisk run -- //bazel/rules:replace_prefix --prefix '#{install_dir}/embedded'" \
3434
" #{install_dir}/embedded/lib/pkgconfig/libattr.pc" \
3535
" #{install_dir}/embedded/lib/libattr.so"

omnibus/config/software/bzip2.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
source url: "https://fossies.org/linux/misc/#{name}-#{version}.tar.gz"
3333

3434
build do
35-
command_on_repo_root "bazelisk run -- @bzip2//:install --destdir='#{install_dir}/embedded'"
35+
command_on_repo_root "bazelisk run -- @bzip2//:install --destdir='#{install_dir}'"
3636

3737
# The version of bzip2 we use doesn't create a pkgconfig file,
3838
# we add it here manually (needed at least by the Python build)

omnibus/config/software/zlib.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717
name "zlib"
1818

1919
build do
20-
command_on_repo_root "bazelisk run -- @zlib//:install --destdir='#{install_dir}/embedded'"
21-
command_on_repo_root "bazelisk run -- @zlib//:install_license --destdir='#{install_dir}/LICENSES'"
20+
command_on_repo_root "bazelisk run -- @zlib//:install --destdir='#{install_dir}'"
2221
end

omnibus/config/software/zstd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
relative_path "zstd-#{version}"
2929

3030
build do
31-
command_on_repo_root "bazelisk run -- @zstd//:install --destdir='#{install_dir}/embedded'"
31+
command_on_repo_root "bazelisk run -- @zstd//:install --destdir='#{install_dir}'"
3232
command_on_repo_root "bazelisk run -- //bazel/rules:replace_prefix --prefix '#{install_dir}/embedded'" \
3333
" #{install_dir}/embedded/lib/pkgconfig/libzstd.pc" \
3434
" #{install_dir}/embedded/lib/libzstd.so"

0 commit comments

Comments
 (0)