Skip to content

Commit b724fc7

Browse files
fffonionAndyZhang0707
authored andcommitted
fix(ci): use PUC-Rio Lua to invoke luarocks
(cherry picked from commit f13e7f8)
1 parent e54aa15 commit b724fc7

File tree

10 files changed

+128
-17
lines changed

10 files changed

+128
-17
lines changed

build/BUILD.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ kong_rules_group(
5555
"@brotli",
5656
"@pcre",
5757
"@openresty",
58+
"@lua",
5859
],
5960
visibility = ["//visibility:public"],
6061
)
@@ -233,6 +234,12 @@ kong_rules_group(
233234
visibility = ["//visibility:public"],
234235
)
235236

237+
kong_install(
238+
name = "install-lua",
239+
src = "@lua",
240+
exclude = ["include"], # skip install headers
241+
)
242+
236243
# Wrap up : )
237244

238245
kong_rules_group(
@@ -244,6 +251,7 @@ kong_rules_group(
244251
":install-openresty",
245252
":install-static-assets",
246253
":install-tools",
254+
":install-lua",
247255
],
248256
visibility = ["//visibility:public"],
249257
)
@@ -265,8 +273,10 @@ kong_genrule(
265273
rm -rf ${BUILD_DESTDIR}/share ${BUILD_DESTDIR}/lib ${BUILD_DESTDIR}/etc
266274
LUAROCKS=$(dirname '$(location @luarocks//:luarocks_make)')/luarocks_tree
267275
cp -r ${LUAROCKS}/share ${LUAROCKS}/lib ${LUAROCKS}/etc ${BUILD_DESTDIR}/.
268-
cp ${LUAROCKS}/bin/luarocks ${BUILD_DESTDIR}/bin/.
269-
cp ${LUAROCKS}/bin/luarocks-admin ${BUILD_DESTDIR}/bin/.
276+
277+
TARGET_LUAROCKS=$(dirname '$(location @luarocks//:luarocks_target)')/luarocks_tree
278+
cp ${TARGET_LUAROCKS}/bin/luarocks ${BUILD_DESTDIR}/bin/.
279+
cp ${TARGET_LUAROCKS}/bin/luarocks-admin ${BUILD_DESTDIR}/bin/.
270280
271281
mkdir -p ${BUILD_DESTDIR}/etc/kong/
272282
cp ${WORKSPACE_PATH}/kong.conf.default ${BUILD_DESTDIR}/etc/kong/kong.conf.default

build/luarocks/BUILD.luarocks.bazel

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ configure_make(
1818
configure_command = "configure",
1919
configure_in_place = True,
2020
configure_options = [
21-
"--lua-suffix=jit",
22-
"--with-lua=$$EXT_BUILD_DEPS/luajit",
23-
"--with-lua-include=$$EXT_BUILD_DEPS/luajit/include/luajit-2.1",
21+
"--with-lua=$$EXT_BUILD_DEPS/lua",
22+
"--with-lua-include=$$EXT_BUILD_DEPS/lua/include",
2423
],
2524
lib_source = ":all_srcs",
2625
out_bin_dir = "",
@@ -32,7 +31,7 @@ configure_make(
3231
],
3332
visibility = ["//visibility:public"],
3433
deps = [
35-
"@openresty//:luajit",
34+
"@lua",
3635
],
3736
)
3837

@@ -46,6 +45,7 @@ kong_template_genrule(
4645
"//conditions:default": [
4746
"@luarocks//:luarocks_host",
4847
"@openresty//:luajit",
48+
"@lua//:lua",
4949
],
5050
}),
5151
is_executable = True,
@@ -58,6 +58,7 @@ kong_template_genrule(
5858
"@kong//:any-cross": [
5959
"@luarocks//:luarocks_host",
6060
"@openresty//:luajit",
61+
"@lua//:lua",
6162
],
6263
"//conditions:default": [],
6364
}),
@@ -86,6 +87,7 @@ kong_template_genrule(
8687
"//conditions:default": [
8788
"@luarocks//:luarocks_host",
8889
"@openresty//:luajit",
90+
"@lua//:lua",
8991
],
9092
}),
9193
is_executable = True,
@@ -102,6 +104,7 @@ kong_template_genrule(
102104
"@//:any-cross": [
103105
"@luarocks//:luarocks_host",
104106
"@openresty//:luajit",
107+
"@lua//:lua",
105108
],
106109
"//conditions:default": [],
107110
}),

build/luarocks/lua/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
3+
exports_files(
4+
[
5+
"BUILD.lua.bazel",
6+
],
7+
visibility = ["//visibility:public"],
8+
)
9+
10+
build_test(
11+
name = "build",
12+
targets = [
13+
"@lua//:lua",
14+
],
15+
visibility = ["//:__pkg__"],
16+
)

build/luarocks/lua/BUILD.lua.bazel

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("@kong_bindings//:variables.bzl", "KONG_VAR")
2+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
3+
4+
filegroup(
5+
name = "all_srcs",
6+
srcs = glob(
7+
include = ["**"],
8+
exclude = ["*.bazel"],
9+
),
10+
)
11+
12+
make(
13+
name = "lua",
14+
args = select({
15+
"@platforms//os:macos": [
16+
"AR=/usr/bin/ar",
17+
],
18+
"//conditions:default": [
19+
],
20+
}),
21+
lib_source = ":all_srcs",
22+
out_binaries = [
23+
"lua",
24+
],
25+
targets = [
26+
"posix -j" + KONG_VAR["NPROC"], # use posix instead linux to be able to cross compile
27+
"install INSTALL_TOP=$$INSTALLDIR",
28+
],
29+
visibility = ["//visibility:public"],
30+
)
31+
32+
filegroup(
33+
name = "lua_dir",
34+
srcs = [
35+
":lua",
36+
],
37+
output_group = "gen_dir",
38+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""A module defining the third party dependency LUA"""
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
6+
def lua_repositories():
7+
maybe(
8+
http_archive,
9+
name = "lua",
10+
build_file = "//build/luarocks/lua:BUILD.lua.bazel",
11+
strip_prefix = "lua-5.1.5",
12+
sha256 = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333",
13+
urls = [
14+
"https://www.lua.org/ftp/lua-5.1.5.tar.gz",
15+
],
16+
patches = ["//build/luarocks/lua:patches/lua-cross.patch"],
17+
patch_args = ["-p1"],
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/Makefile b/src/Makefile
2+
index e0d4c9f..23f8273 100644
3+
--- a/src/Makefile
4+
+++ b/src/Makefile
5+
@@ -7,7 +7,7 @@
6+
# Your platform. See PLATS for possible values.
7+
PLAT= none
8+
9+
-CC= gcc
10+
+CC?= gcc
11+
CFLAGS= -O2 -Wall $(MYCFLAGS)
12+
AR= ar rcu
13+
RANLIB= ranlib

build/luarocks/luarocks_repositories.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""A module defining the third party dependency luarocks"""
22

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

67
def luarocks_repositories():
8+
lua_repositories()
9+
710
version = KONG_VAR["LUAROCKS"]
811

912
http_archive(

build/luarocks/templates/luarocks_exec.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ libxml2_path="invalid"
66
openssl_path="{{@@openssl//:openssl}}"
77
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
88
luajit_path="{{@@openresty//:luajit}}"
9+
lua_path="{{@@lua//:lua}}"
910
kongrocks_path="invalid"
1011
cross_deps_libyaml_path="{{@@cross_deps_libyaml//:libyaml}}"
1112
CC={{CC}}
@@ -72,23 +73,28 @@ if [[ $CC != /* ]]; then
7273
LD=$root_path/$LD
7374
fi
7475

75-
echo "
76+
cat << EOF > $ROCKS_CONFIG
7677
rocks_trees = {
7778
{ name = [[system]], root = [[$ROCKS_DIR]] }
7879
}
79-
local_cache = '$CACHE_DIR'
80-
show_downloads = true
80+
lua_version = "5.1";
81+
lua_interpreter = "${luajit_path}/bin/luajit";
82+
local_cache = '$CACHE_DIR';
83+
show_downloads = true;
8184
gcc_rpath = false -- disable default rpath, add our own
8285
variables = {
8386
CC = '$CC',
8487
LD = '$LD',
8588
LDFLAGS = '-Wl,-rpath,$LIB_RPATH',
89+
LUA_DIR = [[$root_path/$luajit_path]],
90+
LUA_INCDIR = [[$root_path/$luajit_path/include/luajit-2.1]],
91+
LUA_BINDIR = [[$root_path/$luajit_path/bin]]
8692
}
87-
" > $ROCKS_CONFIG
93+
EOF
8894

8995
LUAROCKS_HOST=$luarocks_host_path
9096

91-
host_luajit=$root_path/$luajit_path/bin/luajit
97+
host_lua=$root_path/$lua_path/bin/lua
9298

9399
cat << EOF > $@
94100
LIB_RPATH=$LIB_RPATH
@@ -114,7 +120,7 @@ fi
114120
# force the interpreter here instead of invoking luarocks directly,
115121
# some distros has BINPRM_BUF_SIZE smaller than the shebang generated,
116122
# which is usually more than 160 bytes
117-
$host_luajit $root_path/$LUAROCKS_HOST/bin/luarocks \$private_rocks_args \$@ \\
123+
$host_lua $root_path/$LUAROCKS_HOST/bin/luarocks \$private_rocks_args \$@ \\
118124
OPENSSL_DIR=$OPENSSL_DIR \\
119125
CRYPTO_DIR=$OPENSSL_DIR \\
120126
EXPAT_DIR=$EXPAT_DIR \\

build/luarocks/templates/luarocks_target.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build_destdir="{{build_destdir}}"
77

88
luarocks_exec="{{@@luarocks//:luarocks_exec}}"
99
luajit_path="{{@@openresty//:luajit}}"
10+
lua_path="{{@@lua//:lua}}"
1011
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
1112
luarocks_wrap_script="{{@@//build/luarocks:luarocks_wrap_script.lua}}"
1213
# template variables ends
@@ -40,11 +41,12 @@ mkdir -p $rocks_tree/etc/luarocks
4041
cat << EOF > $rocks_tree/etc/luarocks/config-5.1.lua
4142
-- LuaRocks configuration
4243
rocks_trees = {
43-
{ name = "user", root = home .. "/.luarocks" };
44-
{ name = "system", root = "$install_destdir" };
45-
}
46-
lua_interpreter = "luajit";
47-
variables = {
44+
{ name = "user", root = home .. "/.luarocks" };
45+
{ name = "system", root = "$install_destdir" };
46+
}
47+
lua_version = "5.1";
48+
lua_interpreter = "luajit";
49+
variables = {
4850
LUA_DIR = "$install_destdir/openresty/luajit";
4951
LUA_INCDIR = "$install_destdir/openresty/luajit/include/luajit-2.1";
5052
LUA_BINDIR = "$install_destdir/openresty/luajit/bin";
@@ -53,6 +55,7 @@ EOF
5355

5456
sed -i -e "s|$build_destdir|$install_destdir|g" $rocks_tree/bin/luarocks
5557
sed -i -e "s|$rocks_tree|$install_destdir|g" $rocks_tree/bin/luarocks
58+
sed -i -e "s|openresty/luajit/bin/luajit|kong/bin/lua|" $rocks_tree/bin/luarocks
5659

5760
# only generate the output when the command succeeds
5861
mv $@.tmp $@

build/templates/venv-commons

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ echo "
3232
rocks_trees = {
3333
{ name = [[system]], root = [[$ROCKS_ROOT]] }
3434
}
35+
lua_version = [[5.1]]
3536
" >| "$LUAROCKS_CONFIG"
3637

3738
# duplicate package.[c]path even though we have set in resty-cli, so luajit and kong can consume

0 commit comments

Comments
 (0)