Skip to content

Commit

Permalink
Add Bazel build to CI (#623)
Browse files Browse the repository at this point in the history
Add Bazel to CI using Bazelisk from the GitHub test runners.

Fix many things in the Bazel build file... and also add basic testing which executes pcre2test using RunTest.

---------

Co-authored-by: zaucy <[email protected]>
  • Loading branch information
NWilson and zaucy authored Dec 16, 2024
1 parent 4a268c9 commit 0ed421c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .bazelrc

This file was deleted.

25 changes: 23 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ jobs:
steps:
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y valgrind
sudo apt-get -qq update
sudo apt-get -qq install -y valgrind
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -274,6 +274,27 @@ jobs:
- name: Test
run: cd build && ctest -j3 --output-on-failure

bazel:
# Tests with: Bazel build system
name: Bazel
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
runs-on: ${{ matrix.os }}
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Build
run: bazelisk build //... --enable_runfiles --incompatible_strict_action_env

- name: Test
run: bazelisk test //... --enable_runfiles --incompatible_strict_action_env --test_output=all

heron:
# Job to verify that the tasks performed by PrepareRelease have been done. It is
# the committer's responsibility (currently) to run PrepareRelease themselves when
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ src/pcre2_chartables.c
src/stamp-h1

/bazel-*
*.bazel.lock

zig-out/
zig-cache/
Expand Down
110 changes: 103 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

copy_file(
name = "config_h_generic",
Expand Down Expand Up @@ -36,6 +37,7 @@ cc_library(
"src/pcre2_error.c",
"src/pcre2_extuni.c",
"src/pcre2_find_bracket.c",
"src/pcre2_jit_compile.c",
"src/pcre2_maketables.c",
"src/pcre2_match.c",
"src/pcre2_match_data.c",
Expand All @@ -53,24 +55,118 @@ cc_library(
"src/pcre2_valid_utf.c",
"src/pcre2_xclass.c",
":pcre2_chartables_c",
],
hdrs = glob(["src/*.h"]) + [
"src/pcre2_compile.h",
"src/pcre2_internal.h",
"src/pcre2_intmodedep.h",
"src/pcre2_ucp.h",
"src/pcre2_util.h",
":config_h_generic",
],
textual_hdrs = [
"src/pcre2_jit_match.c",
"src/pcre2_jit_misc.c",
"src/pcre2_ucptables.c",
],
hdrs = [
":pcre2_h_generic",
],
defines = [
local_defines = [
"HAVE_CONFIG_H",
"HAVE_MEMMOVE",
"PCRE2_CODE_UNIT_WIDTH=8",
"PCRE2_STATIC",
"SUPPORT_UNICODE",
],
includes = ["src"],
strip_include_prefix = "src",
visibility = ["//visibility:public"],
)

cc_binary(
name = "pcre2demo",
srcs = ["src/pcre2demo.c"],
cc_library(
name = "pcre2-posix",
srcs = [
"src/pcre2posix.c",
":config_h_generic",
],
hdrs = [
"src/pcre2posix.h",
],
local_defines = [
"HAVE_CONFIG_H",
"HAVE_MEMMOVE",
"PCRE2_CODE_UNIT_WIDTH=8",
"PCRE2_STATIC",
"SUPPORT_UNICODE",
],
includes = ["src"],
strip_include_prefix = "src",
visibility = ["//visibility:public"],
deps = [":pcre2"],
)

# Totally weird issue in Bazel. It won't let you #include any files unless they
# are declared to the build system. OK, fair enough. But - for a cc_binary it
# uses the file extension to determine whether it's a header or a compilation
# unit. But... we have several .c files which are #included, rather than treated
# as a compilation unit.
#
# For cc_library() above, we can overcome this with textual_hdrs. But that
# doesn't work for cc_binary(). Here's our workaround.
#
# https://github.com/bazelbuild/bazel/issues/680
cc_library(
name = "pcre2test_dotc_headers",
hdrs = [
"src/pcre2_chkdint.c",
"src/pcre2_printint.c",
"src/pcre2_tables.c",
"src/pcre2_ucd.c",
"src/pcre2_valid_utf.c",
],
strip_include_prefix = "src",
visibility = ["//visibility:private"],
)

cc_binary(
name = "pcre2test",
srcs = [
"src/pcre2test.c",
":config_h_generic",
],
local_defines = [
"HAVE_CONFIG_H",
"HAVE_MEMMOVE",
"HAVE_STRERROR",
"PCRE2_STATIC",
"SUPPORT_UNICODE",
"SUPPORT_PCRE2_8",
] + select({
"@platforms//os:windows": [],
"//conditions:default": ["HAVE_UNISTD_H"],
}),
linkopts = select({
"@platforms//os:windows": ["-STACK:2500000"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
deps = [":pcre2test_dotc_headers", ":pcre2", ":pcre2-posix"],
)

filegroup(
name = "testdata",
srcs = glob(["testdata/*"]),
)

native_test(
name = "pcre2_test",
src = select({
"@platforms//os:windows": "RunTest.bat",
"//conditions:default": "RunTest",
}),
out = select({
"@platforms//os:windows": "RunTest.bat",
"//conditions:default": "RunTest",
}),
data = [":pcre2test", ":testdata"],
size = "small",
)
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module(
name = "pcre2",
version = "10.40",
version = "10.45-DEV",
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "bazel_skylib", version = "1.2.1")
bazel_dep(name = "platforms", version = "0.0.4")
2 changes: 1 addition & 1 deletion RunTest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if exist ..\testdata\ set srcdir=..)
if [%srcdir%]==[] (
if exist ..\..\testdata\ set srcdir=..\..)
if NOT exist %srcdir%\testdata\ (
Error: echo distribution testdata folder not found!
echo Error: distribution testdata folder not found!
call :conferror
exit /b 1
goto :eof
Expand Down

0 comments on commit 0ed421c

Please sign in to comment.