From e6781af2891155f7d4abeb47dfda5864534ce28a Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Thu, 30 May 2024 22:16:33 +0300 Subject: [PATCH] feat(deps): add ada - whatwg-compliant and fast url parser ### Summary Adds libada and lua-resty-ada as a dependency. This is needed for: https://github.com/Kong/kong/pull/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 --- .requirements | 2 ++ build/BUILD.bazel | 5 +-- build/openresty/ada/BUILD.bazel | 18 +++++++++++ build/openresty/ada/ada_repositories.bzl | 19 +++++++++++ build/openresty/repositories.bzl | 2 ++ changelog/unreleased/kong/feat-add-ada.yml | 4 +++ kong-3.9.0-0.rockspec | 1 + .../fixtures/amazonlinux-2-amd64.txt | 7 ++++ .../fixtures/amazonlinux-2023-amd64.txt | 7 ++++ .../fixtures/amazonlinux-2023-arm64.txt | 7 ++++ .../fixtures/debian-11-amd64.txt | 7 ++++ .../fixtures/debian-12-amd64.txt | 7 ++++ .../explain_manifest/fixtures/el8-amd64.txt | 7 ++++ .../explain_manifest/fixtures/el9-amd64.txt | 7 ++++ .../explain_manifest/fixtures/el9-arm64.txt | 7 ++++ .../fixtures/ubuntu-20.04-amd64.txt | 7 ++++ .../fixtures/ubuntu-22.04-amd64.txt | 7 ++++ .../fixtures/ubuntu-22.04-arm64.txt | 7 ++++ scripts/explain_manifest/suites.py | 7 +++- spec/01-unit/31-ada-url_spec.lua | 32 +++++++++++++++++++ 20 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 build/openresty/ada/BUILD.bazel create mode 100644 build/openresty/ada/ada_repositories.bzl create mode 100644 changelog/unreleased/kong/feat-add-ada.yml create mode 100644 spec/01-unit/31-ada-url_spec.lua diff --git a/.requirements b/.requirements index a68a68eca89f..48472d5efef4 100644 --- a/.requirements +++ b/.requirements @@ -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 diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 008a71ffce57..05ea9aa880e0 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -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 ] diff --git a/build/openresty/ada/BUILD.bazel b/build/openresty/ada/BUILD.bazel new file mode 100644 index 000000000000..9a157965e6b3 --- /dev/null +++ b/build/openresty/ada/BUILD.bazel @@ -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"], +) diff --git a/build/openresty/ada/ada_repositories.bzl b/build/openresty/ada/ada_repositories.bzl new file mode 100644 index 000000000000..ae9777207a39 --- /dev/null +++ b/build/openresty/ada/ada_repositories.bzl @@ -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", + ) diff --git a/build/openresty/repositories.bzl b/build/openresty/repositories.bzl index 3b01aa23901c..bb1e7389f58a 100644 --- a/build/openresty/repositories.bzl +++ b/build/openresty/repositories.bzl @@ -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 = """ @@ -37,6 +38,7 @@ def openresty_repositories(): wasm_filters_repositories() brotli_repositories() snappy_repositories() + ada_repositories() openresty_version = KONG_VAR["OPENRESTY"] diff --git a/changelog/unreleased/kong/feat-add-ada.yml b/changelog/unreleased/kong/feat-add-ada.yml new file mode 100644 index 000000000000..891d77fa3dab --- /dev/null +++ b/changelog/unreleased/kong/feat-add-ada.yml @@ -0,0 +1,4 @@ +message: | + **Core**: Added Ada dependency - WHATWG-compliant and fast URL parser. +type: feature +scope: Core diff --git a/kong-3.9.0-0.rockspec b/kong-3.9.0-0.rockspec index cc4a204fee05..6bf6989b3334 100644 --- a/kong-3.9.0-0.rockspec +++ b/kong-3.9.0-0.rockspec @@ -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", diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt index 8a457c581daa..f75994009046 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt index 7b5c7a0bf8ec..1baf5d190001 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt index dc4f126bab70..807cec769697 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/debian-11-amd64.txt b/scripts/explain_manifest/fixtures/debian-11-amd64.txt index 7647cdfb4f13..768258ad6b1a 100644 --- a/scripts/explain_manifest/fixtures/debian-11-amd64.txt +++ b/scripts/explain_manifest/fixtures/debian-11-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/debian-12-amd64.txt b/scripts/explain_manifest/fixtures/debian-12-amd64.txt index ebeb6014fe24..31cb3a4d6c7e 100644 --- a/scripts/explain_manifest/fixtures/debian-12-amd64.txt +++ b/scripts/explain_manifest/fixtures/debian-12-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/el8-amd64.txt b/scripts/explain_manifest/fixtures/el8-amd64.txt index 629859f3ca62..ec2ba1998a3e 100644 --- a/scripts/explain_manifest/fixtures/el8-amd64.txt +++ b/scripts/explain_manifest/fixtures/el8-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/el9-amd64.txt b/scripts/explain_manifest/fixtures/el9-amd64.txt index d1b29e97cb7f..fb837ac0c0ea 100644 --- a/scripts/explain_manifest/fixtures/el9-amd64.txt +++ b/scripts/explain_manifest/fixtures/el9-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/el9-arm64.txt b/scripts/explain_manifest/fixtures/el9-arm64.txt index dc4f126bab70..807cec769697 100644 --- a/scripts/explain_manifest/fixtures/el9-arm64.txt +++ b/scripts/explain_manifest/fixtures/el9-arm64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt b/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt index dcaa0ef9271d..361c43bb7897 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt b/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt index 60d62a4563c6..e0cdc94ca3b3 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt @@ -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 diff --git a/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt b/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt index 0d875dde28b0..cb06affdd985 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt @@ -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 diff --git a/scripts/explain_manifest/suites.py b/scripts/explain_manifest/suites.py index e17854c044f3..7c5987968ddf 100644 --- a/scripts/explain_manifest/suites.py +++ b/scripts/explain_manifest/suites.py @@ -1,3 +1,4 @@ +import re import os wasm_filters = [] @@ -102,7 +103,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() diff --git a/spec/01-unit/31-ada-url_spec.lua b/spec/01-unit/31-ada-url_spec.lua new file mode 100644 index 000000000000..e75461fe95e2 --- /dev/null +++ b/spec/01-unit/31-ada-url_spec.lua @@ -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("")) + end) + it("accepts valid url", function() + is_table(ada.parse("http://www.google.com/")) + end) + end) + end) +end)