Skip to content

Commit 6cca6c0

Browse files
authored
Merge pull request #191 from Tesseract22/master
Update to zig 0.15
2 parents be8b496 + e011e34 commit 6cca6c0

File tree

8 files changed

+132
-117
lines changed

8 files changed

+132
-117
lines changed

build.zig

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,15 @@ fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget {
110110

111111
// This creates a SQLite static library from the SQLite dependency code.
112112
fn makeSQLiteLib(b: *std.Build, dep: *std.Build.Dependency, c_flags: []const []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, sqlite_c: enum { with, without }) *std.Build.Step.Compile {
113-
const lib = b.addStaticLibrary(.{
114-
.name = "sqlite",
113+
const mod = b.addModule("lib-sqlite", .{
115114
.target = target,
116115
.optimize = optimize,
116+
.link_libc = true,
117+
});
118+
const lib = b.addLibrary(.{
119+
.name = "sqlite",
120+
.linkage = .dynamic,
121+
.root_module = mod,
117122
});
118123

119124
lib.addIncludePath(dep.path("."));
@@ -128,7 +133,6 @@ fn makeSQLiteLib(b: *std.Build, dep: *std.Build.Dependency, c_flags: []const []c
128133
.file = b.path("c/workaround.c"),
129134
.flags = c_flags,
130135
});
131-
lib.linkLibC();
132136

133137
return lib;
134138
}
@@ -225,13 +229,17 @@ pub fn build(b: *std.Build) !void {
225229

226230
const test_sqlite_lib = makeSQLiteLib(b, sqlite_dep, c_flags, cross_target, optimize, .with);
227231

228-
const tests = b.addTest(.{
229-
.name = test_name,
232+
const mod = b.addModule(test_name, .{
230233
.target = cross_target,
231234
.optimize = optimize,
232235
.root_source_file = b.path("sqlite.zig"),
233236
.single_threaded = test_target.single_threaded,
234237
});
238+
239+
const tests = b.addTest(.{
240+
.name = test_name,
241+
.root_module = mod,
242+
});
235243
tests.addIncludePath(b.path("c"));
236244
tests.addIncludePath(sqlite_dep.path("."));
237245
tests.linkLibrary(test_sqlite_lib);
@@ -282,13 +290,17 @@ fn addPreprocessStep(b: *std.Build, sqlite_dep: *std.Build.Dependency) void {
282290
}
283291

284292
fn addZigcrypto(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.InstallArtifact {
285-
const exe = b.addSharedLibrary(.{
286-
.name = "zigcrypto",
293+
const mod = b.addModule("zigcryto", .{
287294
.root_source_file = b.path("examples/zigcrypto.zig"),
288-
.version = null,
289295
.target = getTarget(target),
290296
.optimize = optimize,
291297
});
298+
const exe = b.addLibrary(.{
299+
.name = "zigcrypto",
300+
.root_module = mod,
301+
.version = null,
302+
.linkage = .dynamic,
303+
});
292304
exe.root_module.addImport("sqlite", sqlite_mod);
293305

294306
const install_artifact = b.addInstallArtifact(exe, .{});
@@ -298,12 +310,15 @@ fn addZigcrypto(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build.
298310
}
299311

300312
fn addZigcryptoTestRun(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Run {
301-
const zigcrypto_test = b.addExecutable(.{
302-
.name = "zigcrypto-test",
313+
const mod = b.addModule("zigcryto-test", .{
303314
.root_source_file = b.path("examples/zigcrypto_test.zig"),
304315
.target = getTarget(target),
305316
.optimize = optimize,
306317
});
318+
const zigcrypto_test = b.addExecutable(.{
319+
.name = "zigcrypto-test",
320+
.root_module = mod,
321+
});
307322
zigcrypto_test.root_module.addImport("sqlite", sqlite_mod);
308323

309324
const install = b.addInstallArtifact(zigcrypto_test, .{});

build/Preprocessor.zig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ const mem = std.mem;
2727
fn readOriginalData(allocator: mem.Allocator, path: []const u8) ![]const u8 {
2828
var file = try std.fs.cwd().openFile(path, .{});
2929
defer file.close();
30+
var buf: [1024]u8 = undefined;
31+
var reader = file.reader(&buf);
3032

31-
var reader = file.reader();
32-
33-
const data = reader.readAllAlloc(allocator, 1024 * 1024);
33+
const data = reader.interface.readAlloc(allocator, 1024 * 1024);
3434
return data;
3535
}
3636

@@ -127,13 +127,13 @@ const Processor = struct {
127127
switch (range) {
128128
.delete => |dr| {
129129
const to_write = self.data[pos..dr.start];
130-
try writer.writeAll(to_write);
130+
try writer.interface.writeAll(to_write);
131131
pos = dr.end;
132132
},
133133
.replace => |rr| {
134134
const to_write = self.data[pos..rr.start];
135-
try writer.writeAll(to_write);
136-
try writer.writeAll(rr.replacement);
135+
try writer.interface.writeAll(to_write);
136+
try writer.interface.writeAll(rr.replacement);
137137
pos = rr.end;
138138
},
139139
}
@@ -148,7 +148,7 @@ const Processor = struct {
148148
// Finally append the remaining data in the buffer (the last range will probably not be the end of the file)
149149
if (pos < self.data.len) {
150150
const remaining_data = self.data[pos..];
151-
try writer.writeAll(remaining_data);
151+
try writer.interface.writeAll(remaining_data);
152152
}
153153
}
154154
};
@@ -196,7 +196,9 @@ pub fn sqlite3(allocator: mem.Allocator, input_path: []const u8, output_path: []
196196
defer output_file.close();
197197

198198
try output_file.writeAll("/* sqlite3.h edited by the zig-sqlite build script */\n");
199-
try processor.dump(output_file.writer());
199+
var buf: [1024]u8 = undefined;
200+
var out_writer = output_file.writer(&buf);
201+
try processor.dump(&out_writer);
200202
}
201203

202204
pub fn sqlite3ext(allocator: mem.Allocator, input_path: []const u8, output_path: []const u8) !void {
@@ -232,5 +234,7 @@ pub fn sqlite3ext(allocator: mem.Allocator, input_path: []const u8, output_path:
232234
defer output_file.close();
233235

234236
try output_file.writeAll("/* sqlite3ext.h edited by the zig-sqlite build script */\n");
235-
try processor.dump(output_file.writer());
237+
var buf: [1024]u8 = undefined;
238+
var out_writer = output_file.writer(&buf);
239+
try processor.dump(&out_writer);
236240
}

0 commit comments

Comments
 (0)