Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable features without vendoring #161

Merged
merged 2 commits into from
Jun 23, 2024
Merged

Conversation

malcolmstill
Copy link
Contributor

@malcolmstill malcolmstill commented Jun 20, 2024

Description

This PR adds the ability to enable SQLite features (at this point only fts5) via build system options and in doing so allows customising SQLite features without resorting to vendoring (as per https://github.com/vrischmann/zig-sqlite?tab=readme-ov-file#using-the-bundled-sqlite-source-code-file).

This means for example you can take the example of installation via the official package manager (https://github.com/vrischmann/zig-sqlite?tab=readme-ov-file#official-package-manager) and simply add, e.g., .fts5 = true to the options to enable full text search:

const sqlite = b.dependency("sqlite", .{
    .target = target,
    .optimize = optimize,
    .fts5 = true,
});

exe.root_module.addImport("sqlite", sqlite.module("sqlite"));

// links the bundled sqlite3, so leave this out if you link the system one
exe.linkLibrary(sqlite.artifact("sqlite"));

A EnableOptions struct is added enumerating boolean options and instead of a static array with only -std=c99 as an option, we make the flags an ArrayList with the same initial content but use a comptime inline for to iterate over each field of EnableOptions to create a b.option and add to the flags ArrayList when the given flag has been enabled. As reference this is the approach taken in https://github.com/mitchellh/zig-build-libxml2/blob/main/build.zig.

As it stands this PR makes it easy to any SQLITE_ENABLE_* options by adding to the EnableOptions struct. This could be expanded to handle other options and indeed non-boolean options.

Also updates std.rand -> std.Random as introduced in recent zig master.

@vrischmann
Copy link
Owner

Thanks ! this looks great.

@malcolmstill
Copy link
Contributor Author

malcolmstill commented Jun 23, 2024

Looks like a recent zig master has moved std.rand to std.Random...I've updated the PR.

@vrischmann
Copy link
Owner

Thank you. I'll merge as is because the windows tests failing have nothing to do with your PR.

@vrischmann vrischmann merged commit 878f8cf into vrischmann:master Jun 23, 2024
4 of 5 checks passed
@malcolmstill
Copy link
Contributor Author

Amazing, thanks @vrischmann!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants