summaryrefslogtreecommitdiff
path: root/build/Preprocessor.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2025-01-12 18:31:10 +0100
committerGravatar Vincent Rischmann2025-02-13 18:40:57 +0100
commitb1e1bc8ef8d8a039a45be998e9c15e086ae4c52d (patch)
treee535f062fae139c4ed568f0788c4ce0b031971a7 /build/Preprocessor.zig
parentfix tests for latest zig (diff)
downloadzig-sqlite-b1e1bc8ef8d8a039a45be998e9c15e086ae4c52d.tar.gz
zig-sqlite-b1e1bc8ef8d8a039a45be998e9c15e086ae4c52d.tar.xz
zig-sqlite-b1e1bc8ef8d8a039a45be998e9c15e086ae4c52d.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 @@
1const std = @import("std"); 1const std = @import("std");
2const debug = std.debug; 2const debug = std.debug;
3const fmt = std.fmt;
4const heap = std.heap;
5const mem = std.mem; 3const 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
158fn preprocessSqlite3HeaderFile(gpa: mem.Allocator) !void { 156pub 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
208fn preprocessSqlite3ExtHeaderFile(gpa: mem.Allocator) !void { 202pub 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
248pub 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}