Skip to content

Commit

Permalink
chore(build): bump bazel to 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Sep 11, 2024
1 parent c498f41 commit a8fdca1
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 47 deletions.
12 changes: 6 additions & 6 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ run --color=yes
common --color=yes
common --curses=auto

# TODO: remove after bump to bazel >= 8
common --enable_workspace

build --experimental_ui_max_stdouterr_bytes=10485760
# TODO: remove after bump to bazel >= 7
build --experimental_cc_shared_library

build --show_progress_rate_limit=0
build --show_timestamps
build --worker_verbose

build --incompatible_strict_action_env

# Enable --platforms API based cpu,compiler,crosstool_top selection; remove this in 7.0.0 as it's enabled by default
build --incompatible_enable_cc_toolchain_resolution
# make output files and directories 0755 instead of 0555
build --experimental_writable_outputs


# Pass PATH, CC, CXX variables from the environment.
build --action_env=CC --host_action_env=CC
build --action_env=CXX --host_action_env=CXX
build --action_env=PATH --host_action_env=PATH

build --action_env=BAZEL_BUILD=1

# temporary fix for https://github.com/bazelbuild/bazel/issues/12905 on macOS
build --features=-debug_prefix_map_pwd_is_dot

Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
7.3.1
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
14 changes: 9 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
)

load("//build:kong_bindings.bzl", "load_bindings")
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

load_bindings(name = "kong_bindings")
bazel_skylib_workspace()

http_archive(
name = "rules_foreign_cc",
Expand All @@ -32,6 +32,10 @@ rules_foreign_cc_dependencies(
register_preinstalled_tools = True, # use preinstalled toolchains like make
)

load("//build:kong_bindings.bzl", "load_bindings")

load_bindings(name = "kong_bindings")

load("//build/openresty:repositories.bzl", "openresty_repositories")

openresty_repositories()
Expand Down
16 changes: 6 additions & 10 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ kong_genrule(
"openresty.dev.nop",
],
cmd = """
chmod -R "u+rw" ${BUILD_DESTDIR}/openresty
rm -rf ${BUILD_DESTDIR}/openresty/nginx
cp -r $(location @openresty//:dev-just-make)/. ${BUILD_DESTDIR}/openresty/
chmod -R "u+rw" ${BUILD_DESTDIR}/openresty
touch ${BUILD_DESTDIR}/openresty.dev.nop
""",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -237,20 +235,14 @@ kong_genrule(
"bin/luarocks",
"bin/luarocks-admin",
"etc/kong/kong.conf.default",
"etc/luarocks",
"lib",
"share",
],
cmd =
""" set -e
chmod -R "u+rw" ${BUILD_DESTDIR}/openresty
rm -rf ${BUILD_DESTDIR}/share ${BUILD_DESTDIR}/lib ${BUILD_DESTDIR}/etc
LUAROCKS=${WORKSPACE_PATH}/$(dirname '$(location @luarocks//:luarocks_make)')/luarocks_tree
LUAROCKS=$(dirname '$(location @luarocks//:luarocks_make)')/luarocks_tree
cp -r ${LUAROCKS}/share ${LUAROCKS}/lib ${LUAROCKS}/etc ${BUILD_DESTDIR}/.
cp ${LUAROCKS}/bin/luarocks ${BUILD_DESTDIR}/bin/.
cp ${LUAROCKS}/bin/luarocks-admin ${BUILD_DESTDIR}/bin/.
chmod -R "u+rw" ${BUILD_DESTDIR}/share/lua
mkdir -p ${BUILD_DESTDIR}/etc/kong/
cp ${WORKSPACE_PATH}/kong.conf.default ${BUILD_DESTDIR}/etc/kong/kong.conf.default
Expand All @@ -269,8 +261,12 @@ kong_genrule(
# create empty folder to make nfpm happy when skip_tools is set to True
mkdir -p ${BUILD_DESTDIR}/kong-tools
chmod -R "u+rw" ${BUILD_DESTDIR}/kong-tools
""",
out_dirs = [
"etc/luarocks",
"lib",
"share",
],
visibility = ["//visibility:public"],
)

Expand Down
15 changes: 13 additions & 2 deletions build/build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def _kong_genrule_impl(ctx):
for f in ctx.attr.outs:
outputs.append(ctx.actions.declare_file(KONG_VAR["BUILD_NAME"] + "/" + f))

for f in ctx.attr.out_dirs:
outputs.append(ctx.actions.declare_directory(KONG_VAR["BUILD_NAME"] + "/" + f))

env = dict(KONG_VAR)
env["BUILD_DESTDIR"] = ctx.var["BINDIR"] + "/build/" + env["BUILD_NAME"]

# XXX: remove the "env" from KONG_VAR which is a list
env["OPENRESTY_PATCHES"] = ""
Expand All @@ -33,6 +37,7 @@ kong_genrule = rule(
"cmd": attr.string(),
"tools": attr.label_list(),
"outs": attr.string_list(),
"out_dirs": attr.string_list(),
},
)

Expand Down Expand Up @@ -82,6 +87,7 @@ def _render_template(ctx, output):

# yes, not a typo, use gcc for linker
substitutions["{{LD}}"] = substitutions["{{CC}}"]
substitutions["{{build_destdir}}"] = ctx.var["BINDIR"] + "/build/" + KONG_VAR["BUILD_NAME"]

ctx.actions.expand_template(
template = ctx.file.template,
Expand Down Expand Up @@ -295,11 +301,16 @@ def _kong_install_impl(ctx):
# f = output.path,
# ),
# )
output = ctx.actions.declare_file(full_path)
if file.is_directory:
output = ctx.actions.declare_directory(full_path)
src = file.path + "/." # avoid duplicating the directory name
else:
output = ctx.actions.declare_file(full_path)
src = file.path
ctx.actions.run_shell(
outputs = [output],
inputs = [file],
command = "cp -r %s %s" % (file.path, output.path),
command = "cp -r %s %s" % (src, output.path),
)

outputs.append(output)
Expand Down
6 changes: 2 additions & 4 deletions build/kong_bindings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ def _load_vars(ctx):
build_name = ctx.os.environ.get("BUILD_NAME", "")
content += '"BUILD_NAME": "%s",\n' % build_name

build_destdir = workspace_path + "/bazel-bin/build/" + build_name
content += '"BUILD_DESTDIR": "%s",\n' % build_destdir

install_destdir = ctx.os.environ.get("INSTALL_DESTDIR", "MANAGED")
if install_destdir == "MANAGED":
install_destdir = build_destdir
# this has to be absoluate path to make build scripts happy and artifacts being portable
install_destdir = workspace_path + "/bazel-bin/build/" + build_name
content += '"INSTALL_DESTDIR": "%s",\n' % install_destdir

# Kong Version
Expand Down
2 changes: 0 additions & 2 deletions build/luarocks/BUILD.luarocks.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ kong_template_genrule(
output = "luarocks_target.log",
progress_message = "Luarocks: Install luarocks with target configuration",
substitutions = {
"{{build_destdir}}": KONG_VAR["BUILD_DESTDIR"],
"{{install_destdir}}": KONG_VAR["INSTALL_DESTDIR"],
"{{luarocks_version}}": KONG_VAR["LUAROCKS"],
"{{workspace_path}}": KONG_VAR["WORKSPACE_PATH"],
},
template = "@//build/luarocks:templates/luarocks_target.sh",
tools = [
Expand Down
10 changes: 5 additions & 5 deletions build/luarocks/templates/luarocks_exec.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash -e

# template variables starts
libexpat_path="{{@libexpat//:libexpat}}"
libexpat_path="{{@@libexpat//:libexpat}}"
libxml2_path="invalid"
openssl_path="{{@openssl//:openssl}}"
luarocks_host_path="{{@luarocks//:luarocks_host}}"
luajit_path="{{@openresty//:luajit}}"
openssl_path="{{@@openssl//:openssl}}"
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
luajit_path="{{@@openresty//:luajit}}"
kongrocks_path="invalid"
cross_deps_libyaml_path="{{@cross_deps_libyaml//:libyaml}}"
cross_deps_libyaml_path="{{@@cross_deps_libyaml//:libyaml}}"
CC={{CC}}
LD={{LD}}
LIB_RPATH={{lib_rpath}}
Expand Down
2 changes: 1 addition & 1 deletion build/luarocks/templates/luarocks_make.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

# template variables starts
luarocks_exec="{{@luarocks//:luarocks_exec}}"
luarocks_exec="{{@@luarocks//:luarocks_exec}}"
# template variables ends

if [[ "$OSTYPE" == "darwin"* ]]; then
Expand Down
15 changes: 7 additions & 8 deletions build/luarocks/templates/luarocks_target.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/bash -e

# template variables starts
workspace_path="{{workspace_path}}"
luarocks_version="{{luarocks_version}}"
install_destdir="{{install_destdir}}"
build_destdir="{{build_destdir}}"

luarocks_exec="{{@luarocks//:luarocks_exec}}"
luajit_path="{{@openresty//:luajit}}"
luarocks_host_path="{{@luarocks//:luarocks_host}}"
luarocks_wrap_script="{{@//build/luarocks:luarocks_wrap_script.lua}}"
luarocks_exec="{{@@luarocks//:luarocks_exec}}"
luajit_path="{{@@openresty//:luajit}}"
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
luarocks_wrap_script="{{@@//build/luarocks:luarocks_wrap_script.lua}}"
# template variables ends

mkdir -p $(dirname $@)
Expand All @@ -19,8 +18,8 @@ mkdir -p $(dirname $@)
$luarocks_exec install "luarocks $luarocks_version"

# use host configuration to invoke luarocks API to wrap a correct bin/luarocks script
rocks_tree=$workspace_path/$(dirname $luarocks_exec)/luarocks_tree
host_luajit=$workspace_path/$luajit_path/bin/luajit
rocks_tree=$(dirname $luarocks_exec)/luarocks_tree
host_luajit=$luajit_path/bin/luajit

host_luarocks_tree=$luarocks_host_path
export LUA_PATH="$build_destdir/share/lua/5.1/?.lua;$build_destdir/share/lua/5.1/?/init.lua;$host_luarocks_tree/share/lua/5.1/?.lua;$host_luarocks_tree/share/lua/5.1/?/init.lua;;"
Expand Down Expand Up @@ -52,7 +51,7 @@ rocks_trees = {
}
EOF

# TODO: this still doesn't work
sed -i -e "s|$build_destdir|$install_destdir|g" $rocks_tree/bin/luarocks
sed -i -e "s|$rocks_tree|$install_destdir|g" $rocks_tree/bin/luarocks

# only generate the output when the command succeeds
Expand Down
4 changes: 3 additions & 1 deletion build/nfpm/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def _nfpm_pkg_impl(ctx):
nfpm_args.add("-p", ctx.attr.packager)
nfpm_args.add("-t", out.path)

build_destdir = ctx.var["BINDIR"] + "/build/" + KONG_VAR["BUILD_NAME"]

ctx.actions.run_shell(
inputs = ctx.files._nfpm_bin,
mnemonic = "nFPM",
command = "ln -sf %s nfpm-prefix; external/nfpm/nfpm $@" % KONG_VAR["BUILD_DESTDIR"],
command = "ln -sf %s nfpm-prefix; external/nfpm/nfpm $@" % build_destdir,
arguments = [nfpm_args],
outputs = [out],
env = env,
Expand Down
9 changes: 7 additions & 2 deletions build/openresty/BUILD.openresty.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ CONFIGURE_OPTIONS = [
}) + select({
"@kong//:brotli_flag": [
"--add-module=$$EXT_BUILD_ROOT$$/external/ngx_brotli",
# force static link; the order or following two entries matter
"--with-ld-opt=\"-l:libbrotlienc.a\"",
"--with-ld-opt=\"-l:libbrotlicommon.a\"",
],
"//conditions:default": [],
}) + wasmx_configure_options
Expand Down Expand Up @@ -350,13 +353,15 @@ genrule(
],
"//conditions:default": [],
}),
outs = ["dev-builddir"],
outs = ["dev-builddir/.marker"],
cmd = """
pushd $(RULEDIR)/openresty.build_tmpdir >/dev/null
make -j%s
make install
popd >/dev/null
cp -r $(RULEDIR)/openresty.build_tmpdir/openresty $@
mkdir -p $$(dirname $@)
cp -r $(RULEDIR)/openresty.build_tmpdir/openresty $$(dirname $@)
touch $@
""" % KONG_VAR["NPROC"],
visibility = ["//visibility:public"],
)

0 comments on commit a8fdca1

Please sign in to comment.