diff options
| author | 2024-04-14 20:50:44 +0200 | |
|---|---|---|
| committer | 2024-04-14 20:50:44 +0200 | |
| commit | 19dd52b7b7e9fa5ec029c4ac3bd53fb41e5be12c (patch) | |
| tree | 453f927a6926b4f778a4be2a14164896734a60f0 /build.zig | |
| parent | Merge pull request #157 from vrischmann/update-latest-zig (diff) | |
| parent | ci: run with -fqemu and -frosetta (diff) | |
| download | zig-sqlite-19dd52b7b7e9fa5ec029c4ac3bd53fb41e5be12c.tar.gz zig-sqlite-19dd52b7b7e9fa5ec029c4ac3bd53fb41e5be12c.tar.xz zig-sqlite-19dd52b7b7e9fa5ec029c4ac3bd53fb41e5be12c.zip | |
Merge pull request #158 from vrischmann/workaround-sqlite-transient
Workaround SQLITE_TRANSIENT
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 140 |
1 files changed, 39 insertions, 101 deletions
| @@ -4,17 +4,6 @@ const Step = std.Build.Step; | |||
| 4 | const ResolvedTarget = std.Build.ResolvedTarget; | 4 | const ResolvedTarget = std.Build.ResolvedTarget; |
| 5 | const Query = std.Target.Query; | 5 | const Query = std.Target.Query; |
| 6 | 6 | ||
| 7 | var sqlite3: ?*Step.Compile = null; | ||
| 8 | |||
| 9 | fn linkSqlite(b: *Step.Compile) void { | ||
| 10 | if (sqlite3) |lib| { | ||
| 11 | b.linkLibrary(lib); | ||
| 12 | } else { | ||
| 13 | b.linkLibC(); | ||
| 14 | b.linkSystemLibrary("sqlite3"); | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { | 7 | fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { |
| 19 | if (bundled) { | 8 | if (bundled) { |
| 20 | var tmp = original_target; | 9 | var tmp = original_target; |
| @@ -46,70 +35,21 @@ const TestTarget = struct { | |||
| 46 | const ci_targets = switch (builtin.target.cpu.arch) { | 35 | const ci_targets = switch (builtin.target.cpu.arch) { |
| 47 | .x86_64 => switch (builtin.target.os.tag) { | 36 | .x86_64 => switch (builtin.target.os.tag) { |
| 48 | .linux => [_]TestTarget{ | 37 | .linux => [_]TestTarget{ |
| 49 | // Targets linux but other CPU archs. | 38 | TestTarget{ .query = .{ .cpu_arch = .x86_64, .abi = .musl }, .bundled = true }, |
| 50 | TestTarget{ | 39 | TestTarget{ .query = .{ .cpu_arch = .x86, .abi = .musl }, .bundled = true }, |
| 51 | .query = .{}, | 40 | TestTarget{ .query = .{ .cpu_arch = .aarch64, .abi = .musl }, .bundled = true }, |
| 52 | .bundled = false, | ||
| 53 | }, | ||
| 54 | TestTarget{ | ||
| 55 | .query = .{ | ||
| 56 | .cpu_arch = .x86_64, | ||
| 57 | .abi = .musl, | ||
| 58 | }, | ||
| 59 | .bundled = true, | ||
| 60 | }, | ||
| 61 | TestTarget{ | ||
| 62 | .query = .{ | ||
| 63 | .cpu_arch = .x86, | ||
| 64 | .abi = .musl, | ||
| 65 | }, | ||
| 66 | .bundled = true, | ||
| 67 | }, | ||
| 68 | }, | 41 | }, |
| 69 | .windows => [_]TestTarget{ | 42 | .windows => [_]TestTarget{ |
| 70 | TestTarget{ | 43 | TestTarget{ .query = .{ .cpu_arch = .x86_64, .abi = .gnu }, .bundled = true }, |
| 71 | .query = .{ | 44 | TestTarget{ .query = .{ .cpu_arch = .x86, .abi = .gnu }, .bundled = true }, |
| 72 | .cpu_arch = .x86_64, | ||
| 73 | .abi = .gnu, | ||
| 74 | }, | ||
| 75 | .bundled = true, | ||
| 76 | }, | ||
| 77 | TestTarget{ | ||
| 78 | .query = .{ | ||
| 79 | .cpu_arch = .x86, | ||
| 80 | .abi = .gnu, | ||
| 81 | }, | ||
| 82 | .bundled = true, | ||
| 83 | }, | ||
| 84 | }, | 45 | }, |
| 85 | .macos => [_]TestTarget{ | 46 | .macos => [_]TestTarget{ |
| 86 | TestTarget{ | 47 | TestTarget{ .query = .{ .cpu_arch = .x86_64 }, .bundled = true }, |
| 87 | .query = .{ | 48 | TestTarget{ .query = .{ .cpu_arch = .aarch64 }, .bundled = true }, |
| 88 | .cpu_arch = .x86_64, | ||
| 89 | }, | ||
| 90 | .bundled = true, | ||
| 91 | }, | ||
| 92 | // TODO(vincent): this fails for some reason | ||
| 93 | // TestTarget{ | ||
| 94 | // .query =.{ | ||
| 95 | // .cpu_arch = .aarch64, | ||
| 96 | // }, | ||
| 97 | // .bundled = true, | ||
| 98 | // }, | ||
| 99 | }, | ||
| 100 | else => [_]TestTarget{ | ||
| 101 | TestTarget{ | ||
| 102 | .query = .{}, | ||
| 103 | .bundled = false, | ||
| 104 | }, | ||
| 105 | }, | ||
| 106 | }, | ||
| 107 | else => [_]TestTarget{ | ||
| 108 | TestTarget{ | ||
| 109 | .query = .{}, | ||
| 110 | .bundled = false, | ||
| 111 | }, | 49 | }, |
| 50 | else => unreachable, | ||
| 112 | }, | 51 | }, |
| 52 | else => unreachable, | ||
| 113 | }; | 53 | }; |
| 114 | 54 | ||
| 115 | const all_test_targets = switch (builtin.target.cpu.arch) { | 55 | const all_test_targets = switch (builtin.target.cpu.arch) { |
| @@ -267,6 +207,8 @@ pub fn build(b: *std.Build) !void { | |||
| 267 | const target = b.resolveTargetQuery(query); | 207 | const target = b.resolveTargetQuery(query); |
| 268 | const optimize = b.standardOptimizeOption(.{}); | 208 | const optimize = b.standardOptimizeOption(.{}); |
| 269 | 209 | ||
| 210 | const c_flags = &[_][]const u8{"-std=c99"}; | ||
| 211 | |||
| 270 | const sqlite_lib = b.addStaticLibrary(.{ | 212 | const sqlite_lib = b.addStaticLibrary(.{ |
| 271 | .name = "sqlite", | 213 | .name = "sqlite", |
| 272 | .target = target, | 214 | .target = target, |
| @@ -274,9 +216,12 @@ pub fn build(b: *std.Build) !void { | |||
| 274 | }); | 216 | }); |
| 275 | 217 | ||
| 276 | sqlite_lib.addIncludePath(.{ .path = "c/" }); | 218 | sqlite_lib.addIncludePath(.{ .path = "c/" }); |
| 277 | sqlite_lib.addCSourceFile(.{ | 219 | sqlite_lib.addCSourceFiles(.{ |
| 278 | .file = .{ .path = "c/sqlite3.c" }, | 220 | .files = &[_][]const u8{ |
| 279 | .flags = &[_][]const u8{"-std=c99"}, | 221 | "c/sqlite3.c", |
| 222 | "c/workaround.c", | ||
| 223 | }, | ||
| 224 | .flags = c_flags, | ||
| 280 | }); | 225 | }); |
| 281 | sqlite_lib.linkLibC(); | 226 | sqlite_lib.linkLibC(); |
| 282 | sqlite_lib.installHeader(.{ .path = "c/sqlite3.h" }, "sqlite3.h"); | 227 | sqlite_lib.installHeader(.{ .path = "c/sqlite3.h" }, "sqlite3.h"); |
| @@ -330,6 +275,20 @@ pub fn build(b: *std.Build) !void { | |||
| 330 | single_threaded_txt, | 275 | single_threaded_txt, |
| 331 | }); | 276 | }); |
| 332 | 277 | ||
| 278 | const test_sqlite_lib = b.addStaticLibrary(.{ | ||
| 279 | .name = "sqlite", | ||
| 280 | .target = cross_target, | ||
| 281 | .optimize = optimize, | ||
| 282 | }); | ||
| 283 | test_sqlite_lib.addCSourceFiles(.{ | ||
| 284 | .files = &[_][]const u8{ | ||
| 285 | "c/sqlite3.c", | ||
| 286 | "c/workaround.c", | ||
| 287 | }, | ||
| 288 | .flags = c_flags, | ||
| 289 | }); | ||
| 290 | test_sqlite_lib.linkLibC(); | ||
| 291 | |||
| 333 | const tests = b.addTest(.{ | 292 | const tests = b.addTest(.{ |
| 334 | .name = test_name, | 293 | .name = test_name, |
| 335 | .target = cross_target, | 294 | .target = cross_target, |
| @@ -337,40 +296,22 @@ pub fn build(b: *std.Build) !void { | |||
| 337 | .root_source_file = .{ .path = "sqlite.zig" }, | 296 | .root_source_file = .{ .path = "sqlite.zig" }, |
| 338 | .single_threaded = test_target.single_threaded, | 297 | .single_threaded = test_target.single_threaded, |
| 339 | }); | 298 | }); |
| 340 | const run_tests = b.addRunArtifact(tests); | 299 | tests.addIncludePath(.{ .path = "c" }); |
| 341 | |||
| 342 | if (bundled) { | 300 | if (bundled) { |
| 343 | const lib = b.addStaticLibrary(.{ | 301 | tests.linkLibrary(test_sqlite_lib); |
| 344 | .name = "sqlite", | 302 | } else { |
| 345 | .target = cross_target, | 303 | tests.linkLibC(); |
| 346 | .optimize = optimize, | 304 | tests.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags }); |
| 347 | }); | 305 | tests.linkSystemLibrary("sqlite3"); |
| 348 | lib.addCSourceFile(.{ | ||
| 349 | .file = .{ .path = "c/sqlite3.c" }, | ||
| 350 | .flags = &[_][]const u8{"-std=c99"}, | ||
| 351 | }); | ||
| 352 | lib.linkLibC(); | ||
| 353 | sqlite3 = lib; | ||
| 354 | } | 306 | } |
| 355 | 307 | ||
| 356 | if (bundled) tests.addIncludePath(.{ .path = "c" }); | ||
| 357 | linkSqlite(tests); | ||
| 358 | |||
| 359 | const lib = b.addStaticLibrary(.{ | ||
| 360 | .name = "zig-sqlite", | ||
| 361 | .root_source_file = .{ .path = "sqlite.zig" }, | ||
| 362 | .target = cross_target, | ||
| 363 | .optimize = optimize, | ||
| 364 | }); | ||
| 365 | if (bundled) lib.addIncludePath(.{ .path = "c" }); | ||
| 366 | linkSqlite(lib); | ||
| 367 | |||
| 368 | const tests_options = b.addOptions(); | 308 | const tests_options = b.addOptions(); |
| 369 | tests.root_module.addImport("build_options", tests_options.createModule()); | 309 | tests.root_module.addImport("build_options", tests_options.createModule()); |
| 370 | 310 | ||
| 371 | tests_options.addOption(bool, "in_memory", in_memory); | 311 | tests_options.addOption(bool, "in_memory", in_memory); |
| 372 | tests_options.addOption(?[]const u8, "dbfile", dbfile); | 312 | tests_options.addOption(?[]const u8, "dbfile", dbfile); |
| 373 | 313 | ||
| 314 | const run_tests = b.addRunArtifact(tests); | ||
| 374 | test_step.dependOn(&run_tests.step); | 315 | test_step.dependOn(&run_tests.step); |
| 375 | } | 316 | } |
| 376 | 317 | ||
| @@ -381,10 +322,7 @@ pub fn build(b: *std.Build) !void { | |||
| 381 | .target = getTarget(target, true), | 322 | .target = getTarget(target, true), |
| 382 | .optimize = optimize, | 323 | .optimize = optimize, |
| 383 | }); | 324 | }); |
| 384 | lib.addCSourceFile(.{ | 325 | lib.addCSourceFile(.{ .file = .{ .path = "c/sqlite3.c" }, .flags = c_flags }); |
| 385 | .file = .{ .path = "c/sqlite3.c" }, | ||
| 386 | .flags = &[_][]const u8{"-std=c99"}, | ||
| 387 | }); | ||
| 388 | lib.addIncludePath(.{ .path = "c" }); | 326 | lib.addIncludePath(.{ .path = "c" }); |
| 389 | lib.linkLibC(); | 327 | lib.linkLibC(); |
| 390 | 328 | ||