Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolchain): multiple fixes for cxx cross build and on macOS #12945

Merged
merged 7 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ common --color=yes
common --curses=auto

build --experimental_ui_max_stdouterr_bytes=10485760
# required to build shared library on macOS
build --experimental_cc_shared_library

build --show_progress_rate_limit=0
Expand Down
4 changes: 2 additions & 2 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ kong_directory_genrule(
"@openresty",
"@openresty//:luajit",
"@protoc//:all_srcs",
"@snappy//:snappy",
"@snappy//:snappy-lib",
] + select({
"@kong//:skip_webui_flags": [],
"//conditions:default": [
Expand Down Expand Up @@ -153,7 +153,7 @@ kong_directory_genrule(
tar -cC ${LUAJIT}/share . | tar -xC ${BUILD_DESTDIR}/openresty/luajit/share
chmod -R "+rw" ${BUILD_DESTDIR}/openresty/luajit

SNAPPY=${WORKSPACE_PATH}/$(dirname $(echo '$(locations @snappy//:snappy)' | awk '{print $1}'))
SNAPPY=${WORKSPACE_PATH}/$(dirname $(echo '$(locations @snappy//:snappy-lib)' | awk '{print $1}'))
cp ${SNAPPY}/libsnappy.${libext} ${BUILD_DESTDIR}/kong/lib

LUAROCKS=${WORKSPACE_PATH}/$(dirname '$(location @luarocks//:luarocks_make)')/luarocks_tree
Expand Down
16 changes: 13 additions & 3 deletions build/openresty/snappy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cc_library(
)

cc_library(
name = "snappy.a",
name = "snappy",
srcs = [
"snappy.cc",
"snappy-c.cc",
Expand All @@ -84,9 +84,19 @@ cc_library(
],
)

# workaround for apple_cc_toolchain doesn't support dynamic linker feature
cc_shared_library(
name = "snappy",
deps = [":snappy.a"],
name = "snappy-macos-lib",
shared_lib_name = "libsnappy.dylib",
deps = [":snappy"],
)

alias(
name = "snappy-lib",
actual = select({
"@platforms//os:osx": ":snappy-macos-lib",
"//conditions:default": ":snappy",
}),
)

filegroup(
Expand Down
3 changes: 3 additions & 0 deletions build/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load("//build/cross_deps:repositories.bzl", "cross_deps_repositories")
load("//build/libexpat:repositories.bzl", "libexpat_repositories")
load("//build:build_system.bzl", "github_release")
load("@kong_bindings//:variables.bzl", "KONG_VAR")
load("//build/toolchain:bindings.bzl", "load_bindings")

_SRCS_BUILD_FILE_CONTENT = """
filegroup(
Expand Down Expand Up @@ -75,6 +76,8 @@ def kong_resty_websocket_repositories():
)

def build_repositories():
load_bindings(name = "toolchain_bindings")

libexpat_repositories()
luarocks_repositories()

Expand Down
2 changes: 1 addition & 1 deletion build/toolchain/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cc_toolchain_config(
compiler_configuration = {},
target_cpu = "aarch64",
toolchain_path_prefix = "/usr/aarch64-linux-gnu/", # is this required?
tools_path_prefix = "/usr/bin/aarch64-linux-gnu-",
tools_prefix = "aarch64-linux-gnu-",
)

cc_toolchain(
Expand Down
13 changes: 13 additions & 0 deletions build/toolchain/bindings.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Global variables
"""

def _load_bindings_impl(ctx):
root = "/".join(ctx.execute(["pwd"]).stdout.split("/")[:-1])

ctx.file("BUILD.bazel", "")
ctx.file("variables.bzl", "INTERNAL_ROOT = \"%s\"\n" % root)

load_bindings = repository_rule(
implementation = _load_bindings_impl,
)
Loading
Loading