diff options
| author | 2025-01-12 18:31:10 +0100 | |
|---|---|---|
| committer | 2025-02-16 00:02:44 +0100 | |
| commit | 4a0483910c9752d69bbd91af1ab12a6443d3b0a6 (patch) | |
| tree | a0bcaee9d1b3f902f3b580210205ba6cd1f63515 /build/Preprocessor.zig | |
| parent | Merge pull request #180 from nektro/patch-1 (diff) | |
| download | zig-sqlite-4a0483910c9752d69bbd91af1ab12a6443d3b0a6.tar.gz zig-sqlite-4a0483910c9752d69bbd91af1ab12a6443d3b0a6.tar.xz zig-sqlite-4a0483910c9752d69bbd91af1ab12a6443d3b0a6.zip | |
stop vendoring the sqlite C code, rework the build
* Use the zig package manager to fetch sqlite directly from upstream
* Integrate the preprocessing tool directly into the build script
This makes it simpler to upgrade the SQLite source code:
* use `zig fetch`
* run `zig build preprocess-headers`
Diffstat (limited to '')
| -rw-r--r-- | build/Preprocessor.zig (renamed from tools/preprocess_files.zig) | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/tools/preprocess_files.zig b/build/Preprocessor.zig index 2bb8eb7..a069523 100644 --- a/tools/preprocess_files.zig +++ b/build/Preprocessor.zig | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const debug = std.debug; | 2 | const debug = std.debug; |
| 3 | const fmt = std.fmt; | ||
| 4 | const heap = std.heap; | ||
| 5 | const mem = std.mem; | 3 | const mem = std.mem; |
| 6 | 4 | ||
| 7 | // This tool is used to preprocess the sqlite3 headers to make them usable to build loadable extensions. | 5 | // This tool is used to preprocess the sqlite3 headers to make them usable to build loadable extensions. |
| @@ -155,14 +153,8 @@ const Processor = struct { | |||
| 155 | } | 153 | } |
| 156 | }; | 154 | }; |
| 157 | 155 | ||
| 158 | fn preprocessSqlite3HeaderFile(gpa: mem.Allocator) !void { | 156 | pub fn sqlite3(allocator: mem.Allocator, input_path: []const u8, output_path: []const u8) !void { |
| 159 | var arena = heap.ArenaAllocator.init(gpa); | 157 | const data = try readOriginalData(allocator, input_path); |
| 160 | defer arena.deinit(); | ||
| 161 | const allocator = arena.allocator(); | ||
| 162 | |||
| 163 | // | ||
| 164 | |||
| 165 | const data = try readOriginalData(allocator, "c/sqlite3.h"); | ||
| 166 | 158 | ||
| 167 | var processor = try Processor.init(allocator, data); | 159 | var processor = try Processor.init(allocator, data); |
| 168 | 160 | ||
| @@ -198,21 +190,17 @@ fn preprocessSqlite3HeaderFile(gpa: mem.Allocator) !void { | |||
| 198 | processor.rangeDelete(); | 190 | processor.rangeDelete(); |
| 199 | } | 191 | } |
| 200 | 192 | ||
| 201 | // Write the result to the file | 193 | // Write the result |
| 202 | var output_file = try std.fs.cwd().createFile("./c/loadable-ext-sqlite3.h", .{ .mode = 0o0644 }); | 194 | |
| 195 | var output_file = try std.fs.cwd().createFile(output_path, .{ .mode = 0o0644 }); | ||
| 203 | defer output_file.close(); | 196 | defer output_file.close(); |
| 204 | 197 | ||
| 198 | try output_file.writeAll("/* sqlite3.h edited by the zig-sqlite build script */\n"); | ||
| 205 | try processor.dump(output_file.writer()); | 199 | try processor.dump(output_file.writer()); |
| 206 | } | 200 | } |
| 207 | 201 | ||
| 208 | fn preprocessSqlite3ExtHeaderFile(gpa: mem.Allocator) !void { | 202 | pub fn sqlite3ext(allocator: mem.Allocator, input_path: []const u8, output_path: []const u8) !void { |
| 209 | var arena = heap.ArenaAllocator.init(gpa); | 203 | const data = try readOriginalData(allocator, input_path); |
| 210 | defer arena.deinit(); | ||
| 211 | const allocator = arena.allocator(); | ||
| 212 | |||
| 213 | // | ||
| 214 | |||
| 215 | const data = try readOriginalData(allocator, "c/sqlite3ext.h"); | ||
| 216 | 204 | ||
| 217 | var processor = try Processor.init(allocator, data); | 205 | var processor = try Processor.init(allocator, data); |
| 218 | 206 | ||
| @@ -238,17 +226,11 @@ fn preprocessSqlite3ExtHeaderFile(gpa: mem.Allocator) !void { | |||
| 238 | processor.rangeDelete(); | 226 | processor.rangeDelete(); |
| 239 | } | 227 | } |
| 240 | 228 | ||
| 241 | // Write the result to the file | 229 | // Write the result |
| 242 | var output_file = try std.fs.cwd().createFile("./c/loadable-ext-sqlite3ext.h", .{ .mode = 0o0644 }); | 230 | |
| 231 | var output_file = try std.fs.cwd().createFile(output_path, .{ .mode = 0o0644 }); | ||
| 243 | defer output_file.close(); | 232 | defer output_file.close(); |
| 244 | 233 | ||
| 234 | try output_file.writeAll("/* sqlite3ext.h edited by the zig-sqlite build script */\n"); | ||
| 245 | try processor.dump(output_file.writer()); | 235 | try processor.dump(output_file.writer()); |
| 246 | } | 236 | } |
| 247 | |||
| 248 | pub fn main() !void { | ||
| 249 | var gpa = heap.GeneralPurposeAllocator(.{}){}; | ||
| 250 | defer if (gpa.deinit() == .leak) debug.panic("leaks detected\n", .{}); | ||
| 251 | |||
| 252 | try preprocessSqlite3HeaderFile(gpa.allocator()); | ||
| 253 | try preprocessSqlite3ExtHeaderFile(gpa.allocator()); | ||
| 254 | } | ||