Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines +12 to +13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this require updating whenever a new version of the sljit submodule is committed?

a git clone is meant to be followed by git submodule update --init or equivalent; could zig or its package manager do that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes the sljit commit hash would have to be updated whenever gitmodules changes aswell and I'm not aware of a helper cmd which has that feature.

Rn, the maintainers would have to run
zig fetch --save=sljit "git+https://github.com/zherczeg/sljit.git#$(git ls-tree HEAD deps/sljit | awk '{print $3}')"
every time sljit's commit # is changed. If they aren't interested in doing that maybe I could setup a workflow to check for and update the zig package that if that's okay.

},
},
.paths = .{
"build.zig", "build.zig.zon",
"src/", "doc/",
Expand Down