diff options
Diffstat (limited to '')
| -rw-r--r-- | build.zig | 35 | ||||
| -rw-r--r-- | build/Preprocessor.zig | 22 |
2 files changed, 38 insertions, 19 deletions
| @@ -110,10 +110,15 @@ fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget { | |||
| 110 | 110 | ||
| 111 | // This creates a SQLite static library from the SQLite dependency code. | 111 | // This creates a SQLite static library from the SQLite dependency code. |
| 112 | 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 { | 112 | 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(.{ | 113 | const mod = b.addModule("lib-sqlite", .{ |
| 114 | .name = "sqlite", | ||
| 115 | .target = target, | 114 | .target = target, |
| 116 | .optimize = optimize, | 115 | .optimize = optimize, |
| 116 | .link_libc = true, | ||
| 117 | }); | ||
| 118 | const lib = b.addLibrary(.{ | ||
| 119 | .name = "sqlite", | ||
| 120 | .linkage = .dynamic, | ||
| 121 | .root_module = mod, | ||
| 117 | }); | 122 | }); |
| 118 | 123 | ||
| 119 | lib.addIncludePath(dep.path(".")); | 124 | lib.addIncludePath(dep.path(".")); |
| @@ -128,7 +133,6 @@ fn makeSQLiteLib(b: *std.Build, dep: *std.Build.Dependency, c_flags: []const []c | |||
| 128 | .file = b.path("c/workaround.c"), | 133 | .file = b.path("c/workaround.c"), |
| 129 | .flags = c_flags, | 134 | .flags = c_flags, |
| 130 | }); | 135 | }); |
| 131 | lib.linkLibC(); | ||
| 132 | 136 | ||
| 133 | return lib; | 137 | return lib; |
| 134 | } | 138 | } |
| @@ -225,13 +229,17 @@ pub fn build(b: *std.Build) !void { | |||
| 225 | 229 | ||
| 226 | const test_sqlite_lib = makeSQLiteLib(b, sqlite_dep, c_flags, cross_target, optimize, .with); | 230 | const test_sqlite_lib = makeSQLiteLib(b, sqlite_dep, c_flags, cross_target, optimize, .with); |
| 227 | 231 | ||
| 228 | const tests = b.addTest(.{ | 232 | const mod = b.addModule(test_name, .{ |
| 229 | .name = test_name, | ||
| 230 | .target = cross_target, | 233 | .target = cross_target, |
| 231 | .optimize = optimize, | 234 | .optimize = optimize, |
| 232 | .root_source_file = b.path("sqlite.zig"), | 235 | .root_source_file = b.path("sqlite.zig"), |
| 233 | .single_threaded = test_target.single_threaded, | 236 | .single_threaded = test_target.single_threaded, |
| 234 | }); | 237 | }); |
| 238 | |||
| 239 | const tests = b.addTest(.{ | ||
| 240 | .name = test_name, | ||
| 241 | .root_module = mod, | ||
| 242 | }); | ||
| 235 | tests.addIncludePath(b.path("c")); | 243 | tests.addIncludePath(b.path("c")); |
| 236 | tests.addIncludePath(sqlite_dep.path(".")); | 244 | tests.addIncludePath(sqlite_dep.path(".")); |
| 237 | tests.linkLibrary(test_sqlite_lib); | 245 | tests.linkLibrary(test_sqlite_lib); |
| @@ -282,13 +290,17 @@ fn addPreprocessStep(b: *std.Build, sqlite_dep: *std.Build.Dependency) void { | |||
| 282 | } | 290 | } |
| 283 | 291 | ||
| 284 | fn addZigcrypto(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.InstallArtifact { | 292 | 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(.{ | 293 | const mod = b.addModule("zigcryto", .{ |
| 286 | .name = "zigcrypto", | ||
| 287 | .root_source_file = b.path("examples/zigcrypto.zig"), | 294 | .root_source_file = b.path("examples/zigcrypto.zig"), |
| 288 | .version = null, | ||
| 289 | .target = getTarget(target), | 295 | .target = getTarget(target), |
| 290 | .optimize = optimize, | 296 | .optimize = optimize, |
| 291 | }); | 297 | }); |
| 298 | const exe = b.addLibrary(.{ | ||
| 299 | .name = "zigcrypto", | ||
| 300 | .root_module = mod, | ||
| 301 | .version = null, | ||
| 302 | .linkage = .dynamic, | ||
| 303 | }); | ||
| 292 | exe.root_module.addImport("sqlite", sqlite_mod); | 304 | exe.root_module.addImport("sqlite", sqlite_mod); |
| 293 | 305 | ||
| 294 | const install_artifact = b.addInstallArtifact(exe, .{}); | 306 | const install_artifact = b.addInstallArtifact(exe, .{}); |
| @@ -298,12 +310,15 @@ fn addZigcrypto(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build. | |||
| 298 | } | 310 | } |
| 299 | 311 | ||
| 300 | fn addZigcryptoTestRun(b: *std.Build, sqlite_mod: *std.Build.Module, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Run { | 312 | 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(.{ | 313 | const mod = b.addModule("zigcryto-test", .{ |
| 302 | .name = "zigcrypto-test", | ||
| 303 | .root_source_file = b.path("examples/zigcrypto_test.zig"), | 314 | .root_source_file = b.path("examples/zigcrypto_test.zig"), |
| 304 | .target = getTarget(target), | 315 | .target = getTarget(target), |
| 305 | .optimize = optimize, | 316 | .optimize = optimize, |
| 306 | }); | 317 | }); |
| 318 | const zigcrypto_test = b.addExecutable(.{ | ||
| 319 | .name = "zigcrypto-test", | ||
| 320 | .root_module = mod, | ||
| 321 | }); | ||
| 307 | zigcrypto_test.root_module.addImport("sqlite", sqlite_mod); | 322 | zigcrypto_test.root_module.addImport("sqlite", sqlite_mod); |
| 308 | 323 | ||
| 309 | const install = b.addInstallArtifact(zigcrypto_test, .{}); | 324 | const install = b.addInstallArtifact(zigcrypto_test, .{}); |
diff --git a/build/Preprocessor.zig b/build/Preprocessor.zig index a069523..f3d0dc6 100644 --- a/build/Preprocessor.zig +++ b/build/Preprocessor.zig | |||
| @@ -27,10 +27,10 @@ const mem = std.mem; | |||
| 27 | fn readOriginalData(allocator: mem.Allocator, path: []const u8) ![]const u8 { | 27 | fn readOriginalData(allocator: mem.Allocator, path: []const u8) ![]const u8 { |
| 28 | var file = try std.fs.cwd().openFile(path, .{}); | 28 | var file = try std.fs.cwd().openFile(path, .{}); |
| 29 | defer file.close(); | 29 | defer file.close(); |
| 30 | var buf: [1024]u8 = undefined; | ||
| 31 | var reader = file.reader(&buf); | ||
| 30 | 32 | ||
| 31 | var reader = file.reader(); | 33 | const data = reader.interface.readAlloc(allocator, 1024 * 1024); |
| 32 | |||
| 33 | const data = reader.readAllAlloc(allocator, 1024 * 1024); | ||
| 34 | return data; | 34 | return data; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| @@ -127,13 +127,13 @@ const Processor = struct { | |||
| 127 | switch (range) { | 127 | switch (range) { |
| 128 | .delete => |dr| { | 128 | .delete => |dr| { |
| 129 | const to_write = self.data[pos..dr.start]; | 129 | const to_write = self.data[pos..dr.start]; |
| 130 | try writer.writeAll(to_write); | 130 | try writer.interface.writeAll(to_write); |
| 131 | pos = dr.end; | 131 | pos = dr.end; |
| 132 | }, | 132 | }, |
| 133 | .replace => |rr| { | 133 | .replace => |rr| { |
| 134 | const to_write = self.data[pos..rr.start]; | 134 | const to_write = self.data[pos..rr.start]; |
| 135 | try writer.writeAll(to_write); | 135 | try writer.interface.writeAll(to_write); |
| 136 | try writer.writeAll(rr.replacement); | 136 | try writer.interface.writeAll(rr.replacement); |
| 137 | pos = rr.end; | 137 | pos = rr.end; |
| 138 | }, | 138 | }, |
| 139 | } | 139 | } |
| @@ -148,7 +148,7 @@ const Processor = struct { | |||
| 148 | // Finally append the remaining data in the buffer (the last range will probably not be the end of the file) | 148 | // Finally append the remaining data in the buffer (the last range will probably not be the end of the file) |
| 149 | if (pos < self.data.len) { | 149 | if (pos < self.data.len) { |
| 150 | const remaining_data = self.data[pos..]; | 150 | const remaining_data = self.data[pos..]; |
| 151 | try writer.writeAll(remaining_data); | 151 | try writer.interface.writeAll(remaining_data); |
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | }; | 154 | }; |
| @@ -196,7 +196,9 @@ pub fn sqlite3(allocator: mem.Allocator, input_path: []const u8, output_path: [] | |||
| 196 | defer output_file.close(); | 196 | defer output_file.close(); |
| 197 | 197 | ||
| 198 | try output_file.writeAll("/* sqlite3.h edited by the zig-sqlite build script */\n"); | 198 | 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); | ||
| 200 | } | 202 | } |
| 201 | 203 | ||
| 202 | pub fn sqlite3ext(allocator: mem.Allocator, input_path: []const u8, output_path: []const u8) !void { | 204 | 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: | |||
| 232 | defer output_file.close(); | 234 | defer output_file.close(); |
| 233 | 235 | ||
| 234 | try output_file.writeAll("/* sqlite3ext.h edited by the zig-sqlite build script */\n"); | 236 | 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); | ||
| 236 | } | 240 | } |