Skip to content

Commit

Permalink
chore: build deps using Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
ADD-SP committed Mar 3, 2024
1 parent 924bb5b commit 0312dd7
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 495 deletions.
4 changes: 3 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Enable Bzlmod for every Bazel command
common --enable_bzlmod
common --verbose_failures
common --registry=https://bcr.bazel.build

build --compilation_mode=dbg
build --copt="-g3"
build --strip=never

build:release --compilation_mode=opt
build:release --copt="-g3"
build:release --strip=never
build:release --strip=never
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.2
7.0.2
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
submodules: true
- uses: actions/setup-python@v4
with:
python-version: '3.x'
Expand Down Expand Up @@ -88,12 +89,15 @@ jobs:
- name: Configure ${{ matrix.install-type }}
run: |
make parser
bazel build --config release //:dependencies --verbose_failures
bazel build --config release --registry=file://$(realpath ngx_waf_deps) //:deps
pushd bazel-bin
tar -zxf ngx_waf_deps.tar.gz
export LIB_INJECTION=$(realpath ngx_waf_deps)/libinjection
export LIB_SODIUM=$(realpath ngx_waf_deps)/libsodium
export LIB_UTHASH=$(realpath ngx_waf_deps)/uthash
tar -zxf deps.tar.gz
echo "$(realpath deps/libinjection/lib)" | sudo tee -a /etc/ld.so.conf.d/ngx_waf.conf
echo "$(realpath deps/libsodium/lib)" | sudo tee -a /etc/ld.so.conf.d/ngx_waf.conf
sudo ldconfig
export LIB_INJECTION=$(realpath deps/libinjection)
export LIB_SODIUM=$(realpath deps/libsodium)
export LIB_UTHASH=$(realpath deps/uthash)
popd
cd nginx-src
Expand Down Expand Up @@ -124,7 +128,7 @@ jobs:
docker:
runs-on: ubuntu-latest
if: ${{ false && github.event_name != 'schedule' }}
if: false
strategy:
matrix:
version: ['stable', 'mainline']
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ngx_waf_deps"]
path = ngx_waf_deps
url = https://github.com/ADD-SP/ngx_waf_deps.git
60 changes: 40 additions & 20 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@

genrule(
name = "dependencies",
name = "deps",
srcs = [
"@libinjection",
"@libinjection//:src/libinjection.h",
"@libinjection//:src/libinjection_sqli.h",
"@libinjection//:src/libinjection_sqli_data.h",
"@libinjection//:src/libinjection_xss.h",
"@libinjection//:src/libinjection_html5.h",
"@uthash//:include/utarray.h",
"@uthash//:include/uthash.h",
"@uthash//:include/utlist.h",
"@uthash//:include/utringbuffer.h",
"@uthash//:include/utstack.h",
"@uthash//:include/utstring.h",
"@libsodium",
"@uthash",
],
outs = [
"ngx_waf_deps.tar.gz"
"deps.tar.gz"
],
cmd = """
mkdir -p ngx_waf_deps/libinjection/include
mkdir -p ngx_waf_deps/libinjection/lib
mkdir -p ngx_waf_deps/libsodium/include
mkdir -p ngx_waf_deps/libsodium/lib
mkdir -p ngx_waf_deps/uthash/include
mkdir -p deps/libinjection/include
mkdir -p deps/libinjection/lib
mkdir -p deps/libsodium/include
mkdir -p deps/libsodium/lib
mkdir -p deps/uthash/include
libinjection_dir=$$(dirname $$(echo '$(locations @libinjection)' | awk '{print $$1}'))
cp -L -r $$libinjection_dir/include/* ngx_waf_deps/libinjection/include
cp -L -r $$libinjection_dir/lib/* ngx_waf_deps/libinjection/lib
for f in $(locations @libinjection); do
cp -Lr $$f deps/libinjection/lib
done
libsodium_dir=$$(dirname $$(echo '$(locations @libsodium)' | awk '{print $$1}'))
cp -L -r $$libsodium_dir/include/* ngx_waf_deps/libsodium/include
cp -L -r $$libsodium_dir/lib/* ngx_waf_deps/libsodium/lib
cp -Lr $(location @libinjection//:src/libinjection.h) deps/libinjection/include
cp -Lr $(location @libinjection//:src/libinjection_sqli.h) deps/libinjection/include
cp -Lr $(location @libinjection//:src/libinjection_sqli_data.h) deps/libinjection/include
cp -Lr $(location @libinjection//:src/libinjection_xss.h) deps/libinjection/include
cp -Lr $(location @libinjection//:src/libinjection_html5.h) deps/libinjection/include
uthash_dir=$$(dirname $$(dirname $$(echo '$(locations @uthash)' | awk '{print $$1}')))
cp -L -r $$uthash_dir/include/* ngx_waf_deps/uthash/include
cp -Lr $(location @uthash//:include/utarray.h) deps/uthash/include
cp -Lr $(location @uthash//:include/uthash.h) deps/uthash/include
cp -Lr $(location @uthash//:include/utlist.h) deps/uthash/include
cp -Lr $(location @uthash//:include/utringbuffer.h) deps/uthash/include
cp -Lr $(location @uthash//:include/utstack.h) deps/uthash/include
cp -Lr $(location @uthash//:include/utstring.h) deps/uthash/include
libsodium_base=$$(dirname $$(echo '$(locations @libsodium)' | awk '{print $$1}'))
cp -Lr $$libsodium_base/include/* deps/libsodium/include
cp -Lr $$libsodium_base/lib/* deps/libsodium/lib
tar -zcvf $(RULEDIR)/ngx_waf_deps.tar.gz ngx_waf_deps
rm -rf ngx_waf_deps
rm -f $(RULEDIR)/deps.tar.gz
tar -zcvf $(RULEDIR)/deps.tar.gz deps
rm -rf deps
""",
)
)
27 changes: 3 additions & 24 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ module(
)

bazel_dep(name = "rules_foreign_cc", version = "0.10.1")

use_repo(
use_extension(
"//bazel/libinjection:extensions.bzl",
"libinjection",
),
"libinjection",
)

use_repo(
use_extension(
"//bazel/libsodium:extensions.bzl",
"libsodium",
),
"libsodium",
)

use_repo(
use_extension(
"//bazel/uthash:extensions.bzl",
"uthash",
),
"uthash",
)
bazel_dep(name = "uthash", version = "2.3.0")
bazel_dep(name = "libinjection", version = "3.10.0")
bazel_dep(name = "libsodium", version = "1.0.19")
Loading

0 comments on commit 0312dd7

Please sign in to comment.