Skip to content
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
14 changes: 12 additions & 2 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ kong_rules_group(
"@brotli",
"@pcre",
"@openresty",
"@lua",
],
visibility = ["//visibility:public"],
)
Expand Down Expand Up @@ -233,6 +234,12 @@ kong_rules_group(
visibility = ["//visibility:public"],
)

kong_install(
name = "install-lua",
src = "@lua",
exclude = ["include"], # skip install headers
)

# Wrap up : )

kong_rules_group(
Expand All @@ -244,6 +251,7 @@ kong_rules_group(
":install-openresty",
":install-static-assets",
":install-tools",
":install-lua",
],
visibility = ["//visibility:public"],
)
Expand All @@ -265,8 +273,10 @@ kong_genrule(
rm -rf ${BUILD_DESTDIR}/share ${BUILD_DESTDIR}/lib ${BUILD_DESTDIR}/etc
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/.

TARGET_LUAROCKS=$(dirname '$(location @luarocks//:luarocks_target)')/luarocks_tree
cp ${TARGET_LUAROCKS}/bin/luarocks ${BUILD_DESTDIR}/bin/.
cp ${TARGET_LUAROCKS}/bin/luarocks-admin ${BUILD_DESTDIR}/bin/.

mkdir -p ${BUILD_DESTDIR}/etc/kong/
cp ${WORKSPACE_PATH}/kong.conf.default ${BUILD_DESTDIR}/etc/kong/kong.conf.default
Expand Down
11 changes: 7 additions & 4 deletions build/luarocks/BUILD.luarocks.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ configure_make(
configure_command = "configure",
configure_in_place = True,
configure_options = [
"--lua-suffix=jit",
"--with-lua=$$EXT_BUILD_DEPS/luajit",
"--with-lua-include=$$EXT_BUILD_DEPS/luajit/include/luajit-2.1",
"--with-lua=$$EXT_BUILD_DEPS/lua",
"--with-lua-include=$$EXT_BUILD_DEPS/lua/include",
],
lib_source = ":all_srcs",
out_bin_dir = "",
Expand All @@ -32,7 +31,7 @@ configure_make(
],
visibility = ["//visibility:public"],
deps = [
"@openresty//:luajit",
"@lua",
],
)

Expand All @@ -46,6 +45,7 @@ kong_template_genrule(
"//conditions:default": [
"@luarocks//:luarocks_host",
"@openresty//:luajit",
"@lua//:lua",
],
}),
is_executable = True,
Expand All @@ -58,6 +58,7 @@ kong_template_genrule(
"@kong//:any-cross": [
"@luarocks//:luarocks_host",
"@openresty//:luajit",
"@lua//:lua",
],
"//conditions:default": [],
}),
Expand Down Expand Up @@ -86,6 +87,7 @@ kong_template_genrule(
"//conditions:default": [
"@luarocks//:luarocks_host",
"@openresty//:luajit",
"@lua//:lua",
],
}),
is_executable = True,
Expand All @@ -102,6 +104,7 @@ kong_template_genrule(
"@//:any-cross": [
"@luarocks//:luarocks_host",
"@openresty//:luajit",
"@lua//:lua",
],
"//conditions:default": [],
}),
Expand Down
16 changes: 16 additions & 0 deletions build/luarocks/lua/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")

exports_files(
[
"BUILD.lua.bazel",
],
visibility = ["//visibility:public"],
)

build_test(
name = "build",
targets = [
"@lua//:lua",
],
visibility = ["//:__pkg__"],
)
38 changes: 38 additions & 0 deletions build/luarocks/lua/BUILD.lua.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@kong_bindings//:variables.bzl", "KONG_VAR")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")

filegroup(
name = "all_srcs",
srcs = glob(
include = ["**"],
exclude = ["*.bazel"],
),
)

make(
name = "lua",
args = select({
"@platforms//os:macos": [
"AR=/usr/bin/ar",
],
"//conditions:default": [
],
}),
lib_source = ":all_srcs",
out_binaries = [
"lua",
],
targets = [
"posix -j" + KONG_VAR["NPROC"], # use posix instead linux to be able to cross compile
"install INSTALL_TOP=$$INSTALLDIR",
],
visibility = ["//visibility:public"],
)

filegroup(
name = "lua_dir",
srcs = [
":lua",
],
output_group = "gen_dir",
)
18 changes: 18 additions & 0 deletions build/luarocks/lua/lua_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""A module defining the third party dependency LUA"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def lua_repositories():
maybe(
http_archive,
name = "lua",
build_file = "//build/luarocks/lua:BUILD.lua.bazel",
strip_prefix = "lua-5.1.5",
sha256 = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333",
urls = [
"https://www.lua.org/ftp/lua-5.1.5.tar.gz",
],
patches = ["//build/luarocks/lua:patches/lua-cross.patch"],
patch_args = ["-p1"],
)
13 changes: 13 additions & 0 deletions build/luarocks/lua/patches/lua-cross.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/Makefile b/src/Makefile
index e0d4c9f..23f8273 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,7 +7,7 @@
# Your platform. See PLATS for possible values.
PLAT= none

-CC= gcc
+CC?= gcc
CFLAGS= -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
3 changes: 3 additions & 0 deletions build/luarocks/luarocks_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""A module defining the third party dependency luarocks"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//build/luarocks/lua:lua_repositories.bzl", "lua_repositories")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

def luarocks_repositories():
lua_repositories()

version = KONG_VAR["LUAROCKS"]

http_archive(
Expand Down
18 changes: 12 additions & 6 deletions build/luarocks/templates/luarocks_exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libxml2_path="invalid"
openssl_path="{{@@openssl//:openssl}}"
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
luajit_path="{{@@openresty//:luajit}}"
lua_path="{{@@lua//:lua}}"
kongrocks_path="invalid"
cross_deps_libyaml_path="{{@@cross_deps_libyaml//:libyaml}}"
CC={{CC}}
Expand Down Expand Up @@ -72,23 +73,28 @@ if [[ $CC != /* ]]; then
LD=$root_path/$LD
fi

echo "
cat << EOF > $ROCKS_CONFIG
rocks_trees = {
{ name = [[system]], root = [[$ROCKS_DIR]] }
}
local_cache = '$CACHE_DIR'
show_downloads = true
lua_version = "5.1";
lua_interpreter = "${luajit_path}/bin/luajit";
local_cache = '$CACHE_DIR';
show_downloads = true;
gcc_rpath = false -- disable default rpath, add our own
variables = {
CC = '$CC',
LD = '$LD',
LDFLAGS = '-Wl,-rpath,$LIB_RPATH',
LUA_DIR = [[$root_path/$luajit_path]],
LUA_INCDIR = [[$root_path/$luajit_path/include/luajit-2.1]],
LUA_BINDIR = [[$root_path/$luajit_path/bin]]
}
" > $ROCKS_CONFIG
EOF

LUAROCKS_HOST=$luarocks_host_path

host_luajit=$root_path/$luajit_path/bin/luajit
host_lua=$root_path/$lua_path/bin/lua

cat << EOF > $@
LIB_RPATH=$LIB_RPATH
Expand All @@ -114,7 +120,7 @@ fi
# force the interpreter here instead of invoking luarocks directly,
# some distros has BINPRM_BUF_SIZE smaller than the shebang generated,
# which is usually more than 160 bytes
$host_luajit $root_path/$LUAROCKS_HOST/bin/luarocks \$private_rocks_args \$@ \\
$host_lua $root_path/$LUAROCKS_HOST/bin/luarocks \$private_rocks_args \$@ \\
OPENSSL_DIR=$OPENSSL_DIR \\
CRYPTO_DIR=$OPENSSL_DIR \\
EXPAT_DIR=$EXPAT_DIR \\
Expand Down
13 changes: 8 additions & 5 deletions build/luarocks/templates/luarocks_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build_destdir="{{build_destdir}}"

luarocks_exec="{{@@luarocks//:luarocks_exec}}"
luajit_path="{{@@openresty//:luajit}}"
lua_path="{{@@lua//:lua}}"
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
luarocks_wrap_script="{{@@//build/luarocks:luarocks_wrap_script.lua}}"
# template variables ends
Expand Down Expand Up @@ -40,11 +41,12 @@ mkdir -p $rocks_tree/etc/luarocks
cat << EOF > $rocks_tree/etc/luarocks/config-5.1.lua
-- LuaRocks configuration
rocks_trees = {
{ name = "user", root = home .. "/.luarocks" };
{ name = "system", root = "$install_destdir" };
}
lua_interpreter = "luajit";
variables = {
{ name = "user", root = home .. "/.luarocks" };
{ name = "system", root = "$install_destdir" };
}
lua_version = "5.1";
lua_interpreter = "luajit";
variables = {
LUA_DIR = "$install_destdir/openresty/luajit";
LUA_INCDIR = "$install_destdir/openresty/luajit/include/luajit-2.1";
LUA_BINDIR = "$install_destdir/openresty/luajit/bin";
Expand All @@ -53,6 +55,7 @@ EOF

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
sed -i -e "s|openresty/luajit/bin/luajit|kong/bin/lua|" $rocks_tree/bin/luarocks

# only generate the output when the command succeeds
mv $@.tmp $@
1 change: 1 addition & 0 deletions build/templates/venv-commons
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ echo "
rocks_trees = {
{ name = [[system]], root = [[$ROCKS_ROOT]] }
}
lua_version = [[5.1]]
" >| "$LUAROCKS_CONFIG"

# duplicate package.[c]path even though we have set in resty-cli, so luajit and kong can consume
Expand Down
38 changes: 38 additions & 0 deletions scripts/upgrade-tests/luarocks-system-lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/lua
package.loaded["luarocks.core.hardcoded"] = { SYSCONFDIR = [[/usr/local/etc/luarocks]], LUA_VERSION = "5.1" }
package.path=[[/usr/local/share/lua/5.1/?.lua;]] .. package.path
local list = package.searchers or package.loaders; table.insert(list, 1, function(name) if name:match("^luarocks%.") then return loadfile([[/usr/local/share/lua/5.1/]] .. name:gsub([[%.]], [[/]]) .. [[.lua]]) end end)

-- Load cfg first so that the loader knows it is running inside LuaRocks
local cfg = require("luarocks.core.cfg")

local loader = require("luarocks.loader")
local cmd = require("luarocks.cmd")

local description = "LuaRocks main command-line interface"

local commands = {
init = "luarocks.cmd.init",
pack = "luarocks.cmd.pack",
unpack = "luarocks.cmd.unpack",
build = "luarocks.cmd.build",
install = "luarocks.cmd.install",
search = "luarocks.cmd.search",
list = "luarocks.cmd.list",
remove = "luarocks.cmd.remove",
make = "luarocks.cmd.make",
download = "luarocks.cmd.download",
path = "luarocks.cmd.path",
show = "luarocks.cmd.show",
new_version = "luarocks.cmd.new_version",
lint = "luarocks.cmd.lint",
write_rockspec = "luarocks.cmd.write_rockspec",
purge = "luarocks.cmd.purge",
doc = "luarocks.cmd.doc",
upload = "luarocks.cmd.upload",
config = "luarocks.cmd.config",
which = "luarocks.cmd.which",
test = "luarocks.cmd.test",
}

cmd.run_command(description, commands, "luarocks.cmd.external", ...)
3 changes: 3 additions & 0 deletions scripts/upgrade-tests/test-upgrade-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ function prepare_container() {
docker exec $1 apt-get install -y build-essential curl m4 unzip git
docker exec $1 bash -c "ln -sf /usr/local/kong/include/* /usr/include"
docker exec $1 bash -c "ln -sf /usr/local/kong/lib/* /usr/lib"
# the following two lines will not be needed on 3.11+
docker exec -u 0 $1 apt-get install -y lua5.1
docker cp scripts/upgrade-tests/luarocks-system-lua $1:/usr/local/bin/luarocks
}

function build_containers() {
Expand Down
Loading