Skip to content

Commit 18b7128

Browse files
committed
fix(ci): use PUC-Rio Lua to invoke luarocks
1 parent 746f301 commit 18b7128

File tree

7 files changed

+100
-14
lines changed

7 files changed

+100
-14
lines changed

build/luarocks/BUILD.luarocks.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ configure_make(
3232
],
3333
visibility = ["//visibility:public"],
3434
deps = [
35-
"@openresty//:luajit",
35+
"@lua",
36+
"@openresty//:luajit", # still need luajit for headers
3637
],
3738
)
3839

@@ -46,6 +47,7 @@ kong_template_genrule(
4647
"//conditions:default": [
4748
"@luarocks//:luarocks_host",
4849
"@openresty//:luajit",
50+
"@lua//:lua",
4951
],
5052
}),
5153
is_executable = True,
@@ -58,6 +60,7 @@ kong_template_genrule(
5860
"@kong//:any-cross": [
5961
"@luarocks//:luarocks_host",
6062
"@openresty//:luajit",
63+
"@lua//:lua",
6164
],
6265
"//conditions:default": [],
6366
}),
@@ -86,6 +89,7 @@ kong_template_genrule(
8689
"//conditions:default": [
8790
"@luarocks//:luarocks_host",
8891
"@openresty//:luajit",
92+
"@lua//:lua",
8993
],
9094
}),
9195
is_executable = True,
@@ -102,6 +106,7 @@ kong_template_genrule(
102106
"@//:any-cross": [
103107
"@luarocks//:luarocks_host",
104108
"@openresty//:luajit",
109+
"@lua//:lua",
105110
],
106111
"//conditions:default": [],
107112
}),

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+
"-j" + KONG_VAR["NPROC"],
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
load("@kong_bindings//:variables.bzl", "KONG_VAR")
6+
7+
def lua_repositories():
8+
maybe(
9+
http_archive,
10+
name = "lua",
11+
build_file = "//build/luarocks/lua:BUILD.lua.bazel",
12+
strip_prefix = "lua-5.4.7",
13+
sha256 = "9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30",
14+
urls = [
15+
"https://www.lua.org/ftp/lua-5.4.7.tar.gz",
16+
],
17+
)

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";
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 = [[$luajit_path]],
90+
LUA_INCDIR = [[$luajit_path/include/luajit-2.1]],
91+
LUA_BINDIR = [[$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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ install_destdir="{{install_destdir}}"
66
build_destdir="{{build_destdir}}"
77

88
luarocks_exec="{{@@luarocks//:luarocks_exec}}"
9-
luajit_path="{{@@openresty//:luajit}}"
9+
lua_path="{{@@lua//:lua}}"
1010
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
1111
luarocks_wrap_script="{{@@//build/luarocks:luarocks_wrap_script.lua}}"
1212
# template variables ends
@@ -19,7 +19,7 @@ $luarocks_exec install "luarocks $luarocks_version"
1919

2020
# use host configuration to invoke luarocks API to wrap a correct bin/luarocks script
2121
rocks_tree=$(dirname $luarocks_exec)/luarocks_tree
22-
host_luajit=$luajit_path/bin/luajit
22+
host_lua=$lua_path/bin/lua
2323

2424
host_luarocks_tree=$luarocks_host_path
2525
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;;"
@@ -32,7 +32,7 @@ rocks_trees = {
3232
EOF
3333
export LUAROCKS_CONFIG=$ROCKS_CONFIG
3434

35-
$host_luajit $luarocks_wrap_script \
35+
$host_lua $luarocks_wrap_script \
3636
luarocks $rocks_tree $install_destdir > $@.tmp 2>&1
3737

3838
# write the luarocks config with host configuration
@@ -42,13 +42,14 @@ cat << EOF > $rocks_tree/etc/luarocks/config-5.1.lua
4242
rocks_trees = {
4343
{ name = "user", root = home .. "/.luarocks" };
4444
{ name = "system", root = "$install_destdir" };
45-
}
46-
lua_interpreter = "luajit";
47-
variables = {
45+
};
46+
lua_version = "5.1";
47+
lua_interpreter = "luajit";
48+
variables = {
4849
LUA_DIR = "$install_destdir/openresty/luajit";
4950
LUA_INCDIR = "$install_destdir/openresty/luajit/include/luajit-2.1";
5051
LUA_BINDIR = "$install_destdir/openresty/luajit/bin";
51-
}
52+
};
5253
EOF
5354

5455
sed -i -e "s|$build_destdir|$install_destdir|g" $rocks_tree/bin/luarocks

0 commit comments

Comments
 (0)