Skip to content

Commit

Permalink
feat(deps): add ada - whatwg-compliant and fast url parser
Browse files Browse the repository at this point in the history
### Summary

Adds libada and lua-resty-ada as a dependency.

This is needed for:
#12758

But it may be great for many other uses too.

The `lua-resty-ada` LuaJIT FFI bindings can be found here:
https://github.com/bungle/lua-resty-ada

Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
  • Loading branch information
bungle committed Sep 3, 2024
1 parent 4e38b96 commit b751f78
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ OPENSSL=3.2.1
OPENSSL_SHA256=83c7329fe52c850677d75e5d0b0ca245309b97e8ecbcfdc1dfdc4ab9fac35b39
PCRE=10.44
PCRE_SHA256=86b9cb0aa3bcb7994faa88018292bc704cdbb708e785f7c74352ff6ea7d3175b
ADA=2.9.2
ADA_SHA256=b2cce630590b490d79ea4f4460ba77efd5fb29c5a87a4e8cb7ebc4859bc4b564
LIBEXPAT=2.6.2
LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3

Expand Down
5 changes: 3 additions & 2 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ clib_deps = [
"@openssl",
"@libexpat",
"@snappy",
"@ada",
]

[
kong_install(
name = "install-%s" % get_workspace_name(k),
src = k,
prefix = "kong/lib" if k in ("@passwdqc", "@snappy") else "kong",
strip_path = "snappy" if k == "@snappy" else "",
prefix = "kong/lib" if k in ("@passwdqc", "@snappy", "@ada") else "kong",
strip_path = "snappy" if k == "@snappy" else "ada" if k == "@ada" else "",
)
for k in clib_deps
]
Expand Down
18 changes: 18 additions & 0 deletions build/openresty/ada/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cc_library(
name = "ada-lib",
srcs = ["ada.cpp"],
hdrs = [
"ada.h",
"ada_c.h",
],
copts = [
"-std=c++17",
],
linkstatic = True,
)

cc_shared_library(
name = "ada",
visibility = ["//visibility:public"],
deps = [":ada-lib"],
)
19 changes: 19 additions & 0 deletions build/openresty/ada/ada_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""A module defining the third party dependency Ada"""

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

def ada_repositories():
"""Defines the ada repository"""

version = KONG_VAR["ADA"]

maybe(
http_archive,
name = "ada",
sha256 = KONG_VAR["ADA_SHA256"],
url = "https://github.com/ada-url/ada/releases/download/v" + version + "/singleheader.zip",
type = "zip",
build_file = "//build/openresty/ada:BUILD.bazel",
)
2 changes: 2 additions & 0 deletions build/openresty/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ load("//build/openresty/wasmx:wasmx_repositories.bzl", "wasmx_repositories")
load("//build/openresty/wasmx/filters:repositories.bzl", "wasm_filters_repositories")
load("//build/openresty/brotli:brotli_repositories.bzl", "brotli_repositories")
load("//build/openresty/snappy:snappy_repositories.bzl", "snappy_repositories")
load("//build/openresty/ada:ada_repositories.bzl", "ada_repositories")

# This is a dummy file to export the module's repository.
_NGINX_MODULE_DUMMY_FILE = """
Expand All @@ -37,6 +38,7 @@ def openresty_repositories():
wasm_filters_repositories()
brotli_repositories()
snappy_repositories()
ada_repositories()

openresty_version = KONG_VAR["OPENRESTY"]

Expand Down
4 changes: 4 additions & 0 deletions changelog/unreleased/kong/feat-add-ada.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
**Core**: Added Ada dependency - WHATWG-compliant and fast URL parser.
type: feature
scope: Core
1 change: 1 addition & 0 deletions kong-3.9.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = {
"lpeg == 1.1.0",
"lua-resty-ljsonschema == 1.1.6-2",
"lua-resty-snappy == 1.0-1",
"lua-resty-ada == 1.1.0",
}
build = {
type = "builtin",
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/debian-11-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/debian-12-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el8-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el9-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el9-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
- Path : /usr/local/kong/lib/engines-3/padlock.so
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libc.so.6
Expand Down
6 changes: 5 additions & 1 deletion scripts/explain_manifest/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ def common_suites(expect, libxcrypt_no_obsolete_api: bool = False, skip_libsimdj
expect("**/*.so", "dynamic libraries are compiled with OpenSSL 3.2.x") \
.version_requirement.key("libssl.so.3").less_than("OPENSSL_3.3.0") \
.version_requirement.key("libcrypto.so.3").less_than("OPENSSL_3.3.0") \


ADA_VERSION = read_requirements()["ADA"]
expect("**/*.so", "ada version is less than %s" % ADA_VERSION) \
.version_requirement.key("libada.so").is_not().greater_than("ADA_%s" % ADA_VERSION) \

# wasm filters
for f in wasm_filters:
expect("/usr/local/kong/wasm/%s" % f, "wasm filter %s is installed under kong/wasm" % f).exists()
Expand Down
32 changes: 32 additions & 0 deletions spec/01-unit/31-ada-url_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local ada = require("resty.ada")


local assert = assert
local describe = describe
local it = it


local equal = assert.equal
local is_nil = assert.is_nil
local is_table = assert.is_table


local function is_err(msg, ok, err)
is_nil(ok)
equal(msg, err)
return ok, err
end


describe("Ada", function()
describe("URL", function()
describe(".parse", function()
it("rejects invalid url", function()
is_err("invalid url", ada.parse("<invalid>"))
end)
it("accepts valid url", function()
is_table(ada.parse("http://www.google.com/"))
end)
end)
end)
end)

0 comments on commit b751f78

Please sign in to comment.