Skip to content

Commit 8f84056

Browse files
committed
sqlite3 build script
0 parents  commit 8f84056

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
pull_request:
8+
branches: [main]
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Zig
21+
uses: mlugg/setup-zig@v2
22+
23+
- name: Run `build`
24+
run: zig build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.zig-cache/
2+
zig-out/

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025 LeRoyce Pearson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this build script and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to use,
6+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7+
Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice (including the next
11+
paragraph) shall be included in all copies or substantial portions of the
12+
Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
This build script takes the SQLite source code amalgam and exposes a statically
2+
linked `sqlite3` library and the `sqlite3` shell executable.
3+
4+
To add it to your `build.zig.zon`:
5+
6+
```
7+
zig fetch --save git+https://github.com/allyourcodebase/sqlite3
8+
```
9+
10+
Using it in your build script:
11+
12+
```zig
13+
const sqlite3 = b.dependency("sqlite3", .{
14+
.target = target,
15+
.optimize = optimize,
16+
});
17+
const sqlite3_lib = b.artifact("sqlite3");
18+
const sqlite3_exe = b.artifact("shell");
19+
```
20+
21+
[This build script is licensed under the MIT License](./LICENSE).
22+
23+
[SQLite itself is dedicated to the public domain](https://sqlite.org/copyright.html).

build.zig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const run_step = b.step("run", "run sqlite shell");
5+
6+
const target = b.standardTargetOptions(.{});
7+
const optimize = b.standardOptimizeOption(.{});
8+
9+
const src = b.dependency("sqlite3", .{});
10+
11+
const lib = b.addLibrary(.{
12+
.name = "sqlite3",
13+
.root_module = b.createModule(.{
14+
.target = target,
15+
.optimize = optimize,
16+
.link_libc = true,
17+
}),
18+
});
19+
lib.root_module.addCSourceFile(.{
20+
.file = src.path("sqlite3.c"),
21+
});
22+
lib.installHeader(src.path("sqlite3.h"), "sqlite3.h");
23+
lib.installHeader(src.path("sqlite3ext.h"), "sqlite3ext.h");
24+
b.installArtifact(lib);
25+
26+
const shell = b.addExecutable(.{
27+
.name = "shell",
28+
.root_module = b.createModule(.{
29+
.target = target,
30+
.optimize = optimize,
31+
}),
32+
});
33+
shell.root_module.addCSourceFile(.{
34+
.file = src.path("shell.c"),
35+
});
36+
shell.linkLibrary(lib);
37+
const shell_install = b.addInstallArtifact(shell, .{
38+
.dest_sub_path = "sqlite3",
39+
});
40+
b.getInstallStep().dependOn(&shell_install.step);
41+
42+
const shell_run = b.addRunArtifact(shell);
43+
if (b.args) |args| {
44+
shell_run.addArgs(args);
45+
}
46+
run_step.dependOn(&shell_run.step);
47+
}

build.zig.zon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.{
2+
.name = .sqlite3,
3+
.version = "3.51.0",
4+
.dependencies = .{
5+
.sqlite3 = .{
6+
.url = "https://sqlite.org/2025/sqlite-amalgamation-3510000.zip",
7+
.hash = "N-V-__8AALNYqgDpBBECZ3Jn_VpVGjX4xX7uTSZg00tYjmy3",
8+
},
9+
},
10+
.minimum_zig_version = "0.15.2",
11+
.paths = .{""},
12+
.fingerprint = 0x6edcd7115a4bcc0c,
13+
}

0 commit comments

Comments
 (0)