Skip to content

Commit

Permalink
fix(build): build wasmx support on macos (#10371)
Browse files Browse the repository at this point in the history
* fix(build): build on macos

* style(build) fix bazel files formatting

* fix(templates): do not check nil size
  • Loading branch information
locao committed Jul 14, 2023
1 parent e47e10e commit 3eaa37b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
19 changes: 19 additions & 0 deletions build/kong_bindings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ def _load_vars(ctx):

content += '"OPENRESTY_PATCHES": [%s],' % (", ".join(patches))

# wasm runtime options
if ctx.os.name == "mac os x":
content += '"V8_OS": "darwin",'
content += '"WASMER_OS": "darwin",'
content += '"WASMTIME_OS": "macos",'
elif ctx.os.name == "linux":
content += '"V8_OS": "linux",'
content += '"WASMER_OS": "linux",'
content += '"WASMTIME_OS": "linux",'

if ctx.os.arch == "amd64" or ctx.os.arch == "x86_64":
content += '"V8_ARCH": "x86_64",'
content += '"WASMER_ARCH": "amd64",'
content += '"WASMTIME_ARCH": "x86_64",'
elif ctx.os.arch == "aarch64":
content += '"V8_ARCH": "FIXME",' # no releases available atm
content += '"WASMER_ARCH": "aarch64",'
content += '"WASMTIME_ARCH": "aarch64",'

ctx.file("BUILD.bazel", "")
ctx.file("variables.bzl", "KONG_VAR = {\n" + content + "\n}")

Expand Down
21 changes: 15 additions & 6 deletions build/openresty/wasmx/wasmx_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def wasmx_repositories():
wasmtime_version = KONG_VAR["WASMTIME_VERSION"]
wasmer_version = KONG_VAR["WASMER_VERSION"]
v8_version = KONG_VAR["V8_VERSION"]
wasmtime_os = KONG_VAR["WASMTIME_OS"]
wasmer_os = KONG_VAR["WASMER_OS"]
v8_os = KONG_VAR["V8_OS"]
wasmtime_arch = KONG_VAR["WASMTIME_ARCH"]
wasmer_arch = KONG_VAR["WASMER_ARCH"]
v8_arch = KONG_VAR["V8_ARCH"]

maybe(
new_git_repository,
Expand Down Expand Up @@ -41,23 +47,25 @@ filegroup(
http_archive,
name = "v8",
urls = [
"https://github.com/Kong/ngx_wasm_runtimes/releases/download/latest/ngx_wasm_runtime-v8-" + v8_version + "-linux-x86_64.tar.gz",
"https://github.com/Kong/ngx_wasm_runtimes/releases/download/latest/ngx_wasm_runtime-v8-" +
v8_version + "-" + v8_os + "-" + v8_arch + ".tar.gz",
],
strip_prefix = "v8-" + v8_version + "-linux-x86_64",
strip_prefix = "v8-" + v8_version + "-" + v8_os + "-" + v8_arch,
build_file_content = """
filegroup(
name = "all_srcs",
srcs = glob(["include/**", "lib/**"]),
visibility = ["//visibility:public"]
)
"""
""",
)

maybe(
http_archive,
name = "wasmer",
urls = [
"https://github.com/wasmerio/wasmer/releases/download/v" + wasmer_version + "/wasmer-linux-amd64.tar.gz",
"https://github.com/wasmerio/wasmer/releases/download/v" +
wasmer_version + "/wasmer-" + wasmer_os + "-" + wasmer_arch + ".tar.gz",
],
build_file_content = """
filegroup(
Expand All @@ -72,9 +80,10 @@ filegroup(
http_archive,
name = "wasmtime",
urls = [
"https://github.com/bytecodealliance/wasmtime/releases/download/v" + wasmtime_version + "/wasmtime-v" + wasmtime_version + "-x86_64-linux-c-api.tar.xz",
"https://github.com/bytecodealliance/wasmtime/releases/download/v" +
wasmtime_version + "/wasmtime-v" + wasmtime_version + "-" + wasmtime_arch + "-" + wasmtime_os + "-c-api.tar.xz",
],
strip_prefix = "wasmtime-v" + wasmtime_version + "-x86_64-linux-c-api",
strip_prefix = "wasmtime-v" + wasmtime_version + "-" + wasmtime_arch + "-" + wasmtime_os + "-c-api",
build_file_content = """
filegroup(
name = "all_srcs",
Expand Down
2 changes: 1 addition & 1 deletion kong/templates/nginx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ events {
> end
}
> if #wasm_modules_parsed > 0 then
> if wasm_modules_parsed and #wasm_modules_parsed > 0 then
wasm {
shm_kv kong_wasm_rate_limiting_counters 12m;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/custom_nginx.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ events {
> end
}

> if #wasm_modules_parsed > 0 then
> if wasm_modules_parsed and #wasm_modules_parsed > 0 then
wasm {
shm_kv kong_wasm_rate_limiting_counters 12m;

Expand Down

0 comments on commit 3eaa37b

Please sign in to comment.