From 19981205119212b076f55a1c0b1e3389bfdd76c7 Mon Sep 17 00:00:00 2001 From: nankishre Date: Sun, 19 Jul 2026 20:46:55 +0530 Subject: [PATCH] Fetch SLJIT through the zig package manager for JIT builds Update workflow to change commit # on zig config at submodule commit change. Change SLJIT commit # to master for testing workflow Sync autogenerated files #noupdate Revert to pinned sljit commit hash Sync autogenerated files #noupdate --- .github/workflows/sync.yml | 4 ++++ build.zig | 24 +++++++++++++++++++++++- build.zig.zon | 7 ++++++- maint/UpdateAlways | 9 +++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 8eb355500..6ed6c32b2 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -37,6 +37,10 @@ jobs: startsWith(github.ref, 'refs/tags/pcre2-')) run: maint/UpdateDates.py + # The zig version from minimum_zig_version in build.zig.zon will be installed. + - name: Install zig + uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1 + - name: UpdateAlways run: maint/UpdateAlways diff --git a/build.zig b/build.zig index df589189e..bce694224 100644 --- a/build.zig +++ b/build.zig @@ -16,6 +16,24 @@ pub fn build(b: *std.Build) !void { const codeUnitWidth = b.option(CodeUnitWidth, "code-unit-width", "Sets the code unit width") orelse .@"8"; const jit = b.option(bool, "support_jit", "Enable/disable JIT compiler support") orelse false; + const jit_source = if (jit) blk: { + const sljit = b.lazyDependency("sljit", .{}) orelse + return error.MissingDependency; + + const files = b.addWriteFiles(); + + _ = files.addCopyDirectory( + sljit.path("sljit_src"), + "deps/sljit/sljit_src", + .{}, + ); + + break :blk files.addCopyFile( + b.path("src/pcre2_jit_compile.c"), + "src/pcre2_jit_compile.c", + ); + } else b.path("src/pcre2_jit_compile.c"); + const pcre2_h_dir = b.addWriteFiles(); const pcre2_h = pcre2_h_dir.addCopyFile(b.path("src/pcre2.h.generic"), "pcre2.h"); b.addNamedLazyPath("pcre2.h", pcre2_h); @@ -118,7 +136,6 @@ pub fn build(b: *std.Build) !void { "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", @@ -140,6 +157,11 @@ pub fn build(b: *std.Build) !void { .flags = cflags, }); + lib_mod.addCSourceFile(.{ + .file = jit_source, + .flags = cflags, + }); + const lib = b.addLibrary(.{ .name = b.fmt("pcre2-{t}", .{codeUnitWidth}), .root_module = lib_mod, diff --git a/build.zig.zon b/build.zig.zon index 447cc57e5..b20e3ad8a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -7,7 +7,12 @@ .fingerprint = 0x914b3d63ebab9e21, .minimum_zig_version = "0.15.2", - .dependencies = .{}, + .dependencies = .{ + .sljit = .{ + .url = "git+https://github.com/zherczeg/sljit.git#45f910b78c6605ebf5b53d3ec7cb00f2312fe417", + .hash = "N-V-__8AAIUFRABdZku3bW_1S5GOC4iaFh17LsRurEDR1lvv", + }, + }, .paths = .{ "build.zig", "build.zig.zon", "src/", "doc/", diff --git a/maint/UpdateAlways b/maint/UpdateAlways index a6e857941..524a0e9b3 100755 --- a/maint/UpdateAlways +++ b/maint/UpdateAlways @@ -331,6 +331,15 @@ perl maint/CheckTxt "${txt_files[@]}" perl maint/CheckTxt -ascii "${c_files[@]}" perl maint/CheckTxt -crlf "${crlf_files[@]}" +SLJIT_COMMIT=`git ls-tree HEAD deps/sljit | awk '{print $3}'` +if [ -z "$SLJIT_COMMIT" ] ; then + echo "Warning: could not find deps/sljit in the tree; not updating build.zig.zon" +elif ! grep -q "sljit.git#$SLJIT_COMMIT" build.zig.zon ; then + echo "Updating SLJIT pin in build.zig.zon to $SLJIT_COMMIT" + zig fetch --save=sljit "git+https://github.com/zherczeg/sljit.git#$SLJIT_COMMIT" + if [ $? != 0 ] ; then exit 1; fi +fi + # Verify the version number in the Bazel file if ! grep -E "version = \"$CURRENT_RELEASE\"" MODULE.bazel >/dev/null ; then echo "Version number in MODULE.bazel does not match current release"