Skip to content

Commit

Permalink
Merge branch 'master' into ad-retries-port
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six authored Sep 11, 2024
2 parents 86a679f + c937edc commit ba95dcf
Show file tree
Hide file tree
Showing 28 changed files with 924 additions and 266 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: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ jobs:
bazelisk-version: "1.20.0"
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}
# Share repository cache between workflows.
repository-cache: true


- name: Install Deb Dependencies
if: matrix.package == 'deb' && steps.cache-deps.outputs.cache-hit != 'true'
run: |
Expand Down
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
###############################################################################
36 changes: 28 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,38 @@ 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 = "bazel_features",
sha256 = "ba1282c1aa1d1fffdcf994ab32131d7c7551a9bc960fbf05f42d55a1b930cbfb",
strip_prefix = "bazel_features-1.15.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.15.0/bazel_features-v1.15.0.tar.gz",
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
patch_args = ["-p1"],
patches = [
"//build:patches/01-revert-LD-environment.patch",
"//build:patches/02-revert-Reduce-build-times-especially-on-windows.patch",
],
sha256 = "a2e6fb56e649c1ee79703e99aa0c9d13c6cc53c8d7a0cbb8797ab2888bbc99a3",
strip_prefix = "rules_foreign_cc-0.12.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.12.0/rules_foreign_cc-0.12.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
Expand All @@ -32,6 +48,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
18 changes: 8 additions & 10 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ clib_deps = [
kong_install(
name = "install-%s" % get_workspace_name(k),
src = k,
# only install openssl headers
exclude = [] if k in ("@openssl",) else ["include"],
prefix = "kong/lib" if k in ("@passwdqc", "@snappy", "@ada") else "kong",
strip_path = "snappy" if k == "@snappy" else "ada" if k == "@ada" else "",
)
Expand Down Expand Up @@ -65,10 +67,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 +237,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 +263,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
2 changes: 0 additions & 2 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ The build system requires the following tools to be installed:
# check bazel version
bazel version
```
- [Python](https://www.python.org/), Python 3 is used to build some of the dependencies. Note: build system relies on `python`
in the PATH; if you have `python3` you need to create a symlink from `python` to `python3`
- [Build dependencies](https://github.com/Kong/kong/blob/master/DEVELOPER.md#build-and-install-from-source)

**Note**: Bazel relies on logged user to create the temporary file system; however if your username contains `@`
Expand Down
70 changes: 63 additions & 7 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 @@ -279,6 +285,15 @@ def _kong_install_impl(ctx):
if path.startswith(ctx.attr.src.label.workspace_name + "/copy_" + ctx.attr.src.label.name):
continue

# skip explictly excluded directories
should_skip = False
for e in ctx.attr.exclude:
if path.startswith(label_path + "/" + e):
should_skip = True
break
if should_skip:
continue

# only replace the first one
target_path = path.replace(strip_path + "/", "", 1)
full_path = "%s/%s%s" % (KONG_VAR["BUILD_NAME"], prefix, target_path)
Expand All @@ -295,11 +310,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 Expand Up @@ -338,11 +358,11 @@ kong_install = rule(
# doc = "List of files to explictly install, take effect after exclude; full name, or exactly one '*' at beginning or end as wildcard are supported",
# default = [],
# ),
# "exclude": attr.string_list(
# mandatory = False,
# doc = "List of directories to exclude from installation",
# default = [],
# ),
"exclude": attr.string_list(
mandatory = False,
doc = "List of directories to exclude from installation",
default = [],
),
"create_dynamic_library_symlink": attr.bool(
mandatory = False,
doc = "Create non versioned symlinks to the versioned so, e.g. libfoo.so -> libfoo.so.1.2.3",
Expand All @@ -355,3 +375,39 @@ kong_install = rule(

def get_workspace_name(label):
return label.replace("@", "").split("/")[0]

def _kong_cc_static_library_impl(ctx):
linker_input = ctx.attr.src[CcInfo].linking_context.linker_inputs.to_list()[0]
libs = []
for lib in linker_input.libraries:
libs.append(cc_common.create_library_to_link(
actions = ctx.actions,
# omit dynamic_library and pic_dynamic_library fields
static_library = lib.static_library,
pic_static_library = lib.pic_static_library,
interface_library = lib.interface_library,
alwayslink = lib.alwayslink,
))

cc_info = CcInfo(
compilation_context = ctx.attr.src[CcInfo].compilation_context,
linking_context = cc_common.create_linking_context(
linker_inputs = depset(direct = [
cc_common.create_linker_input(
owner = linker_input.owner,
libraries = depset(libs),
user_link_flags = linker_input.user_link_flags,
),
]),
),
)

return [ctx.attr.src[OutputGroupInfo], cc_info]

kong_cc_static_library = rule(
implementation = _kong_cc_static_library_impl,
doc = "Filter a cc_library target to only output archive (.a) files",
attrs = {
"src": attr.label(allow_files = True, doc = "Label of a cc_library"),
},
)
9 changes: 1 addition & 8 deletions build/cross_deps/libxcrypt/BUILD.libxcrypt.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@ configure_make(
configure_command = "configure",
configure_in_place = True,
configure_options = select({
"@kong//:aarch64-linux-glibc-cross": [
"--host=aarch64-unknown-linux-gnu",
],
"@kong//:x86_64-linux-glibc-cross": [
"--host=x86_64-unknown-linux-gnu",
],
"//conditions:default": [],
}) + select({
":disable-obsolete-api": [
"--enable-obsolete-api=no",
],
"//conditions:default": [],
}),
configure_xcompile = True, # use automatic cross compile detection
lib_source = ":all_srcs",
# out_lib_dir = "lib",
out_shared_libs = select({
Expand Down
10 changes: 1 addition & 9 deletions build/cross_deps/libyaml/BUILD.libyaml.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ configure_make(
name = "libyaml",
configure_command = "configure",
configure_in_place = True,
configure_options = select({
"@kong//:aarch64-linux-glibc-cross": [
"--host=aarch64-unknown-linux-gnu",
],
"@kong//:x86_64-linux-glibc-cross": [
"--host=x86_64-unknown-linux-gnu",
],
"//conditions:default": [],
}),
configure_xcompile = True, # use automatic cross compile detection
lib_source = ":all_srcs",
# out_lib_dir = "lib",
out_shared_libs = select({
Expand Down
13 changes: 2 additions & 11 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 Expand Up @@ -80,13 +78,6 @@ def _check_sanity(ctx):
"The following command is useful to check if Xcode is picked up by Bazel:\n" +
"eval `find /private/var/tmp/_bazel_*/|grep xcode-locator|head -n1`")

python = ctx.execute(["which", "python"]).stdout.strip()
if not python:
fail("rules_foreign_cc hasn't migrated to python3 on macOS yet, and your system doens't \n" +
"have a `python` binary. Consider create a symlink to `python3` and include in PATH:\n" +
"ln -s `which python3` /usr/local/bin/python\n" +
"export PATH=/usr/local/bin:$PATH bazel build <target>\n")

user = ctx.os.environ.get("USER", "")
if "@" in user:
fail("Bazel uses $USER in cache and rule_foreign_cc uses `@` in its sed command.\n" +
Expand Down
11 changes: 2 additions & 9 deletions build/libexpat/BUILD.libexpat.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ configure_make(
"--without-xmlwf",
"--without-examples",
"--without-docbook",
] + select({
"@kong//:aarch64-linux-glibc-cross": [
"--host=aarch64-unknown-linux-gnu",
],
"@kong//:x86_64-linux-glibc-cross": [
"--host=x86_64-unknown-linux-gnu",
],
"//conditions:default": [],
}),
],
configure_xcompile = True, # use automatic cross compile detection
env = select({
"@platforms//os:macos": {
# don't use rule_foreign_cc's libtool as archiver as it seems to be a bug
Expand Down
Loading

0 comments on commit ba95dcf

Please sign in to comment.