Skip to content

Commit

Permalink
refactor(build): hermetic install of some rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ADD-SP committed Oct 23, 2024
1 parent 6d7bf68 commit bfcfa4b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
19 changes: 18 additions & 1 deletion build/build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ def _render_template(ctx, output):
substitutions = dict(ctx.attr.substitutions)
for l in ctx.attr.srcs + ctx.attr.tools:
if OutputGroupInfo in l and "gen_dir" in l[OutputGroupInfo]: # usualy it's foreign_cc target
p = l[OutputGroupInfo].gen_dir.to_list()[0].path
gen_dirs = l[OutputGroupInfo].gen_dir.to_list()
# foreign_cc target usually has only one element in gen_dirs
if len(gen_dirs) == 1:
# foreign_cc target usually has the similar path structure
# bazel-out/k8-fastbuild/bin/external/<name>/copy_<name>/<name>
segments = gen_dirs[0].path.split("/")
if len(segments) >= 2 and segments[-2] == "copy_" + segments[-1]:
# go up to the copy_<name> directory and then go down to the <name> directory
# For example,
# bazel-out/k8-fastbuild/bin/external/openssl/copy_openssl/openssl ->
# bazel-out/k8-fastbuild/bin/external/openssl/openssl
p = gen_dirs[0].path + "/../../" + segments[-1]
else:
fail("expect a target of rules_foreign_cc")
else:
fail("expect a target of rules_foreign_cc")

else: # otherwise it's usually output from gen_rule, file_group etc
files = l.files.to_list()
p = files[0].path
Expand Down Expand Up @@ -325,6 +341,7 @@ def _kong_install_impl(ctx):
outputs.append(output)

if full_path.find(".so.") >= 0 and ctx.attr.create_dynamic_library_symlink:
# libX.so.2.3.4 -> ["libX", "so", "2", "3", "4"]
el = full_path.split(".")
si = el.index("so")
sym_paths = []
Expand Down
2 changes: 0 additions & 2 deletions build/libexpat/BUILD.libexpat.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ configure_make(
"//conditions:default": {},
}),
lib_source = ":all_srcs",
out_include_dir = "include/libexpat", # don't install headers
# out_lib_dir = "lib",
out_shared_libs = select({
"@platforms//os:macos": [
"libexpat.1.dylib",
Expand Down
14 changes: 14 additions & 0 deletions build/luarocks/templates/luarocks_exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ EXPAT_DIR=$root_path/$libexpat_path
LIBXML2_DIR=$root_path/$libxml2_path
OPENSSL_DIR=$root_path/$openssl_path

# The Bazel rules doesn't export the `libexpat.so` file,
# it only exports something like `libexpat.so.1.6.0`,
# but the linker expects `libexpat.so` to be present.
# So we create a symlink to the actual file
# if it doesn't exist.
if ! test -e $EXPAT_DIR/lib/libexpat.so; then
so=$(ls $EXPAT_DIR/lib/libexpat.*)
if [[ -z $so ]]; then
echo "No expat library found in $EXPAT_DIR/lib"
exit 1
fi
ln -s $so $EXPAT_DIR/lib/libexpat.so
fi

# we use system libyaml on macos
if [[ "$OSTYPE" == "darwin"* ]]; then
YAML_DIR=$(HOME=~$(whoami) PATH=/opt/homebrew/bin:$PATH brew --prefix)/opt/libyaml
Expand Down

0 comments on commit bfcfa4b

Please sign in to comment.