Posted on 

how to build apisix@MacBookM2

this script will download the deps of apisix, and build the new openresty to /usr/local/openresty

1
brew install openresty-openssl111 go lua@5.1 pcre2 pcre

compile the openresty

the new openresty will apply some patchs from apisix project, and it can runing at M2 machine.

Dont’t forget set the PATH var to keep the /usr/local/openresty/* path will find firstly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash

set -e

version="0.0.0"
OR_PREFIX="/usr/local/openresty"
lj_ver="2.1-20230119"
openresty_ver="1.21.4.1"

function install_openresty()
{
rm -rf openresty-${openresty_ver}

if [ ! -f LuaJIT-$lj_ver.tar.gz ]; then
wget "https://github.com/openresty/luajit2/archive/v$lj_ver.tar.gz" -O "LuaJIT-$lj_ver.tar.gz"
fi
tar -zxvf LuaJIT-$lj_ver.tar.gz > /dev/null

if [ ! -f openresty-${openresty_ver}.tar.gz ]; then
wget --no-check-certificate https://openresty.org/download/openresty-${openresty_ver}.tar.gz
fi
tar -zxvpf openresty-${openresty_ver}.tar.gz > /dev/null

rm -rf openresty-${openresty_ver}/bundle/LuaJIT-$lj_ver
mv luajit2-$lj_ver openresty-${openresty_ver}/bundle/

return 0
}

function clone_repo() {
local repos=(
"ngx_multi_upstream_module"
"mod_dubbo"
"apisix-nginx-module"
"wasm-nginx-module"
"lua-var-nginx-module"
"grpc-client-nginx-module"
"amesh"
)

echo "cloning repos"

if [ "$1" == "update" ]; then
for repo in "${repos[@]}"; do
if [ -d "$repo" ]; then
echo "updating $repo"
pushd "$repo"
git pull
popd
else
git clone "https://github.com/api7/$repo.git" || exit 1
fi
done
else
for repo in "${repos[@]}"; do
if [ ! -d "$repo" ]; then
git clone "https://github.com/api7/$repo.git" || exit 1
fi
done
fi

return 0
}

function patch_openresty() {
pushd ngx_multi_upstream_module || exit 1
./patch.sh ../openresty-${openresty_ver}
popd

pushd apisix-nginx-module/patch || exit 1
./patch.sh ../../openresty-${openresty_ver}
popd

return 0
}

function build_openresty() {
pushd openresty-${openresty_ver} || exit 1

luajit_xcflags=${luajit_xcflags:="-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT"}
grpc_engine_path="-DNGX_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so -DNGX_HTTP_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so"
cc_opt=${cc_opt:""}
ld_opt=${ld_opt:""}

./configure --prefix="$OR_PREFIX" \
--with-cc-opt="-DAPISIX_BASE_VER=$version $grpc_engine_path -I/opt/homebrew/opt/openresty-openssl111/include $cc_opt" \
--with-ld-opt="-Wl,-rpath,$OR_PREFIX/wasmtime-c-api/lib -L/opt/homebrew/opt/openresty-openssl111/lib $ld_opt" \
--add-module=../mod_dubbo \
--add-module=../ngx_multi_upstream_module \
--add-module=../apisix-nginx-module \
--add-module=../apisix-nginx-module/src/stream \
--add-module=../apisix-nginx-module/src/meta \
--add-module=../wasm-nginx-module \
--add-module=../lua-var-nginx-module \
--add-module=../grpc-client-nginx-module \
--with-poll_module \
--with-pcre-jit \
--without-http_rds_json_module \
--without-http_rds_csv_module \
--without-lua_rds_parser \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-http_v2_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_secure_link_module \
--with-http_random_index_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-threads \
--with-compat \
--with-luajit-xcflags="$luajit_xcflags" \
$no_pool_patch \
-j`nproc`

make -j`nproc`

sudo make install

popd
}

function install_wasmtime() {
pushd wasm-nginx-module || exit 1
if [ ! -d lib/ ]; then
./install-wasmtime.sh
fi
popd
return 0
}

function install_api7_module() {
if [ ! -d /usr/local/openresty/lualib/resty/apisix/stream/xrpc ]; then
pushd apisix-nginx-module || exit 1
sudo OPENRESTY_PREFIX="$OR_PREFIX" make install
popd
fi

if [ ! -d /usr/local/openresty/wasmtime-c-api/ ]; then
pushd wasm-nginx-module || exit 1
sudo OPENRESTY_PREFIX="$OR_PREFIX" make install
popd
fi

pushd grpc-client-nginx-module/grpc-engine/
go build -o libgrpc_engine.so -buildmode=c-shared main.go
sudo install -m 664 ./libgrpc_engine.so /usr/local/openresty
sudo install -m 664 ../lib/resty/*.lua /usr/local/openresty/lualib/resty/
popd
}


function main() {
if [ $(type -P nproc) == "" ]; then
echo "need install nproc"
exit 1
fi

case "$1" in
"install")
echo "new install for dev apisix"
if [ -d ./build-apisix-dev ]; then
pushd ./build-apisix-dev
else
mkdir ./build-apisix-dev
pushd ./build-apisix-dev
fi

clone_repo
install_openresty
install_wasmtime
patch_openresty
build_openresty
install_api7_module

popd
;;
"update")
echo "only clone repo"
clone_repo update
;;
*)
echo "only support install/repo"
exit 1
;;
esac
}

main "$@"

install apisix

before to running apisix, you should install some packages by yourself.

just clone the repo from apache/apisix

1
2
3
4
~/w/apisix *master> git remote show origin
* remote origin
Fetch URL: git@github.com:apache/apisix.git
Push URL: git@github.com:apache/apisix.git

and try to make deps && make run command.