diff options
| author | 2024-01-21 22:23:33 +0800 | |
|---|---|---|
| committer | 2024-01-21 22:23:33 +0800 | |
| commit | d1eecd6b7bd2ac02c6356b6ea1755269796aa00e (patch) | |
| tree | 2709ca5b64d88997586c6c3f25872b2e789cacdd /build.zig | |
| parent | update PR template (diff) | |
| download | zig-sqlite-d1eecd6b7bd2ac02c6356b6ea1755269796aa00e.tar.gz zig-sqlite-d1eecd6b7bd2ac02c6356b6ea1755269796aa00e.tar.xz zig-sqlite-d1eecd6b7bd2ac02c6356b6ea1755269796aa00e.zip | |
fix: keep up with zig master
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 56 |
1 files changed, 27 insertions, 29 deletions
| @@ -1,9 +1,10 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const Step = std.Build.Step; | ||
| 3 | 4 | ||
| 4 | var sqlite3: ?*std.Build.Step.Compile = null; | 5 | var sqlite3: ?*Step.Compile = null; |
| 5 | 6 | ||
| 6 | fn linkSqlite(b: *std.Build.Step.Compile) void { | 7 | fn linkSqlite(b: *Step.Compile) void { |
| 7 | if (sqlite3) |lib| { | 8 | if (sqlite3) |lib| { |
| 8 | b.linkLibrary(lib); | 9 | b.linkLibrary(lib); |
| 9 | } else { | 10 | } else { |
| @@ -12,22 +13,19 @@ fn linkSqlite(b: *std.Build.Step.Compile) void { | |||
| 12 | } | 13 | } |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | fn getTarget(original_target: std.zig.CrossTarget, bundled: bool) std.zig.CrossTarget { | 16 | fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build.ResolvedTarget { |
| 16 | if (bundled) { | 17 | if (bundled) { |
| 17 | var tmp = original_target; | 18 | var tmp = original_target; |
| 18 | 19 | ||
| 19 | if (tmp.isGnuLibC()) { | 20 | if (tmp.result.isGnuLibC()) { |
| 20 | const min_glibc_version = std.SemanticVersion{ | 21 | const min_glibc_version = std.SemanticVersion{ |
| 21 | .major = 2, | 22 | .major = 2, |
| 22 | .minor = 28, | 23 | .minor = 28, |
| 23 | .patch = 0, | 24 | .patch = 0, |
| 24 | }; | 25 | }; |
| 25 | if (tmp.glibc_version) |ver| { | 26 | const ver = tmp.result.os.version_range.linux.glibc; |
| 26 | if (ver.order(min_glibc_version) == .lt) { | 27 | if (ver.order(min_glibc_version) == .lt) { |
| 27 | std.debug.panic("sqlite requires glibc version >= 2.28", .{}); | 28 | std.debug.panic("sqlite requires glibc version >= 2.28", .{}); |
| 28 | } | ||
| 29 | } else { | ||
| 30 | tmp.setGnuLibCVersion(2, 28, 0); | ||
| 31 | } | 29 | } |
| 32 | } | 30 | } |
| 33 | 31 | ||
| @@ -38,7 +36,7 @@ fn getTarget(original_target: std.zig.CrossTarget, bundled: bool) std.zig.CrossT | |||
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | const TestTarget = struct { | 38 | const TestTarget = struct { |
| 41 | target: std.zig.CrossTarget = @as(std.zig.CrossTarget, .{}), | 39 | target: std.Build.ResolvedTarget, |
| 42 | single_threaded: bool = false, | 40 | single_threaded: bool = false, |
| 43 | bundled: bool, | 41 | bundled: bool, |
| 44 | }; | 42 | }; |
| @@ -106,7 +104,7 @@ const ci_targets = switch (builtin.target.cpu.arch) { | |||
| 106 | }, | 104 | }, |
| 107 | else => [_]TestTarget{ | 105 | else => [_]TestTarget{ |
| 108 | TestTarget{ | 106 | TestTarget{ |
| 109 | .target = .{}, | 107 | .target = .{ .query = .{}, .result = comptime std.zig.system.resolveTargetQuery(.{}) catch @panic("") }, |
| 110 | .bundled = false, | 108 | .bundled = false, |
| 111 | }, | 109 | }, |
| 112 | }, | 110 | }, |
| @@ -245,7 +243,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 245 | }, | 243 | }, |
| 246 | }; | 244 | }; |
| 247 | 245 | ||
| 248 | fn computeTestTargets(target: std.zig.CrossTarget, ci: ?bool) ?[]const TestTarget { | 246 | fn computeTestTargets(target: std.Build.ResolvedTarget, ci: ?bool) ?[]const TestTarget { |
| 249 | if (ci != null and ci.?) return &ci_targets; | 247 | if (ci != null and ci.?) return &ci_targets; |
| 250 | 248 | ||
| 251 | if (target.isNative()) { | 249 | if (target.isNative()) { |
| @@ -266,7 +264,7 @@ pub fn build(b: *std.Build) !void { | |||
| 266 | const target = b.standardTargetOptions(.{}); | 264 | const target = b.standardTargetOptions(.{}); |
| 267 | const optimize = b.standardOptimizeOption(.{}); | 265 | const optimize = b.standardOptimizeOption(.{}); |
| 268 | 266 | ||
| 269 | _ = b.addModule("sqlite", .{ .source_file = .{ .path = "sqlite.zig" } }); | 267 | _ = b.addModule("sqlite", .{ .root_source_file = .{ .path = "sqlite.zig" } }); |
| 270 | 268 | ||
| 271 | const sqlite_lib = b.addStaticLibrary(.{ | 269 | const sqlite_lib = b.addStaticLibrary(.{ |
| 272 | .name = "sqlite", | 270 | .name = "sqlite", |
| @@ -318,7 +316,7 @@ pub fn build(b: *std.Build) !void { | |||
| 318 | const cross_target = getTarget(test_target.target, bundled); | 316 | const cross_target = getTarget(test_target.target, bundled); |
| 319 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; | 317 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; |
| 320 | const test_name = b.fmt("{s}-{s}-{s}", .{ | 318 | const test_name = b.fmt("{s}-{s}-{s}", .{ |
| 321 | try cross_target.zigTriple(b.allocator), | 319 | try cross_target.result.zigTriple(b.allocator), |
| 322 | @tagName(optimize), | 320 | @tagName(optimize), |
| 323 | single_threaded_txt, | 321 | single_threaded_txt, |
| 324 | }); | 322 | }); |
| @@ -359,7 +357,7 @@ pub fn build(b: *std.Build) !void { | |||
| 359 | linkSqlite(lib); | 357 | linkSqlite(lib); |
| 360 | 358 | ||
| 361 | const tests_options = b.addOptions(); | 359 | const tests_options = b.addOptions(); |
| 362 | tests.addOptions("build_options", tests_options); | 360 | tests.root_module.addImport("build_options", tests_options.createModule()); |
| 363 | 361 | ||
| 364 | tests_options.addOption(bool, "in_memory", in_memory); | 362 | tests_options.addOption(bool, "in_memory", in_memory); |
| 365 | tests_options.addOption(?[]const u8, "dbfile", dbfile); | 363 | tests_options.addOption(?[]const u8, "dbfile", dbfile); |
| @@ -392,9 +390,9 @@ pub fn build(b: *std.Build) !void { | |||
| 392 | fuzz_lib.linkLibrary(lib); | 390 | fuzz_lib.linkLibrary(lib); |
| 393 | fuzz_lib.want_lto = true; | 391 | fuzz_lib.want_lto = true; |
| 394 | fuzz_lib.bundle_compiler_rt = true; | 392 | fuzz_lib.bundle_compiler_rt = true; |
| 395 | fuzz_lib.addAnonymousModule("sqlite", .{ | 393 | fuzz_lib.root_module.addImport("sqlite", b.createModule(.{ |
| 396 | .source_file = .{ .path = "sqlite.zig" }, | 394 | .root_source_file = .{ .path = "sqlite.zig" }, |
| 397 | }); | 395 | })); |
| 398 | 396 | ||
| 399 | // Setup the output name | 397 | // Setup the output name |
| 400 | const fuzz_executable_name = "fuzz"; | 398 | const fuzz_executable_name = "fuzz"; |
| @@ -423,9 +421,9 @@ pub fn build(b: *std.Build) !void { | |||
| 423 | }); | 421 | }); |
| 424 | fuzz_debug_exe.addIncludePath(.{ .path = "c" }); | 422 | fuzz_debug_exe.addIncludePath(.{ .path = "c" }); |
| 425 | fuzz_debug_exe.linkLibrary(lib); | 423 | fuzz_debug_exe.linkLibrary(lib); |
| 426 | fuzz_debug_exe.addAnonymousModule("sqlite", .{ | 424 | fuzz_debug_exe.root_module.addImport("sqlite", b.createModule(.{ |
| 427 | .source_file = .{ .path = "sqlite.zig" }, | 425 | .root_source_file = .{ .path = "sqlite.zig" }, |
| 428 | }); | 426 | })); |
| 429 | 427 | ||
| 430 | // Only install fuzz-debug when the fuzz step is run | 428 | // Only install fuzz-debug when the fuzz step is run |
| 431 | const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe, .{}); | 429 | const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe, .{}); |
| @@ -446,11 +444,11 @@ pub fn build(b: *std.Build) !void { | |||
| 446 | .target = getTarget(target, true), | 444 | .target = getTarget(target, true), |
| 447 | .optimize = optimize, | 445 | .optimize = optimize, |
| 448 | }); | 446 | }); |
| 449 | zigcrypto_loadable_ext.force_pic = true; | 447 | // zigcrypto_loadable_ext.force_pic = true; |
| 450 | zigcrypto_loadable_ext.addIncludePath(.{ .path = "c" }); | 448 | zigcrypto_loadable_ext.addIncludePath(.{ .path = "c" }); |
| 451 | zigcrypto_loadable_ext.addAnonymousModule("sqlite", .{ | 449 | zigcrypto_loadable_ext.root_module.addImport("sqlite", b.createModule(.{ |
| 452 | .source_file = .{ .path = "sqlite.zig" }, | 450 | .root_source_file = .{ .path = "sqlite.zig" }, |
| 453 | }); | 451 | })); |
| 454 | zigcrypto_loadable_ext.linkLibrary(lib); | 452 | zigcrypto_loadable_ext.linkLibrary(lib); |
| 455 | 453 | ||
| 456 | const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext, .{}); | 454 | const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext, .{}); |
| @@ -462,9 +460,9 @@ pub fn build(b: *std.Build) !void { | |||
| 462 | .optimize = optimize, | 460 | .optimize = optimize, |
| 463 | }); | 461 | }); |
| 464 | zigcrypto_test.addIncludePath(.{ .path = "c" }); | 462 | zigcrypto_test.addIncludePath(.{ .path = "c" }); |
| 465 | zigcrypto_test.addAnonymousModule("sqlite", .{ | 463 | zigcrypto_test.root_module.addImport("sqlite", b.createModule(.{ |
| 466 | .source_file = .{ .path = "sqlite.zig" }, | 464 | .root_source_file = .{ .path = "sqlite.zig" }, |
| 467 | }); | 465 | })); |
| 468 | zigcrypto_test.linkLibrary(lib); | 466 | zigcrypto_test.linkLibrary(lib); |
| 469 | 467 | ||
| 470 | const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test, .{}); | 468 | const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test, .{}); |