From d1eecd6b7bd2ac02c6356b6ea1755269796aa00e Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 21 Jan 2024 22:23:33 +0800 Subject: fix: keep up with zig master --- build.zig | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/build.zig b/build.zig index 8b8ae3e..f1f78e7 100644 --- a/build.zig +++ b/build.zig @@ -1,9 +1,10 @@ const std = @import("std"); const builtin = @import("builtin"); +const Step = std.Build.Step; -var sqlite3: ?*std.Build.Step.Compile = null; +var sqlite3: ?*Step.Compile = null; -fn linkSqlite(b: *std.Build.Step.Compile) void { +fn linkSqlite(b: *Step.Compile) void { if (sqlite3) |lib| { b.linkLibrary(lib); } else { @@ -12,22 +13,19 @@ fn linkSqlite(b: *std.Build.Step.Compile) void { } } -fn getTarget(original_target: std.zig.CrossTarget, bundled: bool) std.zig.CrossTarget { +fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build.ResolvedTarget { if (bundled) { var tmp = original_target; - if (tmp.isGnuLibC()) { + if (tmp.result.isGnuLibC()) { const min_glibc_version = std.SemanticVersion{ .major = 2, .minor = 28, .patch = 0, }; - if (tmp.glibc_version) |ver| { - if (ver.order(min_glibc_version) == .lt) { - std.debug.panic("sqlite requires glibc version >= 2.28", .{}); - } - } else { - tmp.setGnuLibCVersion(2, 28, 0); + const ver = tmp.result.os.version_range.linux.glibc; + if (ver.order(min_glibc_version) == .lt) { + std.debug.panic("sqlite requires glibc version >= 2.28", .{}); } } @@ -38,7 +36,7 @@ fn getTarget(original_target: std.zig.CrossTarget, bundled: bool) std.zig.CrossT } const TestTarget = struct { - target: std.zig.CrossTarget = @as(std.zig.CrossTarget, .{}), + target: std.Build.ResolvedTarget, single_threaded: bool = false, bundled: bool, }; @@ -106,7 +104,7 @@ const ci_targets = switch (builtin.target.cpu.arch) { }, else => [_]TestTarget{ TestTarget{ - .target = .{}, + .target = .{ .query = .{}, .result = comptime std.zig.system.resolveTargetQuery(.{}) catch @panic("") }, .bundled = false, }, }, @@ -245,7 +243,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, }; -fn computeTestTargets(target: std.zig.CrossTarget, ci: ?bool) ?[]const TestTarget { +fn computeTestTargets(target: std.Build.ResolvedTarget, ci: ?bool) ?[]const TestTarget { if (ci != null and ci.?) return &ci_targets; if (target.isNative()) { @@ -266,7 +264,7 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - _ = b.addModule("sqlite", .{ .source_file = .{ .path = "sqlite.zig" } }); + _ = b.addModule("sqlite", .{ .root_source_file = .{ .path = "sqlite.zig" } }); const sqlite_lib = b.addStaticLibrary(.{ .name = "sqlite", @@ -318,7 +316,7 @@ pub fn build(b: *std.Build) !void { const cross_target = getTarget(test_target.target, bundled); const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; const test_name = b.fmt("{s}-{s}-{s}", .{ - try cross_target.zigTriple(b.allocator), + try cross_target.result.zigTriple(b.allocator), @tagName(optimize), single_threaded_txt, }); @@ -359,7 +357,7 @@ pub fn build(b: *std.Build) !void { linkSqlite(lib); const tests_options = b.addOptions(); - tests.addOptions("build_options", tests_options); + tests.root_module.addImport("build_options", tests_options.createModule()); tests_options.addOption(bool, "in_memory", in_memory); tests_options.addOption(?[]const u8, "dbfile", dbfile); @@ -392,9 +390,9 @@ pub fn build(b: *std.Build) !void { fuzz_lib.linkLibrary(lib); fuzz_lib.want_lto = true; fuzz_lib.bundle_compiler_rt = true; - fuzz_lib.addAnonymousModule("sqlite", .{ - .source_file = .{ .path = "sqlite.zig" }, - }); + fuzz_lib.root_module.addImport("sqlite", b.createModule(.{ + .root_source_file = .{ .path = "sqlite.zig" }, + })); // Setup the output name const fuzz_executable_name = "fuzz"; @@ -423,9 +421,9 @@ pub fn build(b: *std.Build) !void { }); fuzz_debug_exe.addIncludePath(.{ .path = "c" }); fuzz_debug_exe.linkLibrary(lib); - fuzz_debug_exe.addAnonymousModule("sqlite", .{ - .source_file = .{ .path = "sqlite.zig" }, - }); + fuzz_debug_exe.root_module.addImport("sqlite", b.createModule(.{ + .root_source_file = .{ .path = "sqlite.zig" }, + })); // Only install fuzz-debug when the fuzz step is run const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe, .{}); @@ -446,11 +444,11 @@ pub fn build(b: *std.Build) !void { .target = getTarget(target, true), .optimize = optimize, }); - zigcrypto_loadable_ext.force_pic = true; + // zigcrypto_loadable_ext.force_pic = true; zigcrypto_loadable_ext.addIncludePath(.{ .path = "c" }); - zigcrypto_loadable_ext.addAnonymousModule("sqlite", .{ - .source_file = .{ .path = "sqlite.zig" }, - }); + zigcrypto_loadable_ext.root_module.addImport("sqlite", b.createModule(.{ + .root_source_file = .{ .path = "sqlite.zig" }, + })); zigcrypto_loadable_ext.linkLibrary(lib); const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext, .{}); @@ -462,9 +460,9 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); zigcrypto_test.addIncludePath(.{ .path = "c" }); - zigcrypto_test.addAnonymousModule("sqlite", .{ - .source_file = .{ .path = "sqlite.zig" }, - }); + zigcrypto_test.root_module.addImport("sqlite", b.createModule(.{ + .root_source_file = .{ .path = "sqlite.zig" }, + })); zigcrypto_test.linkLibrary(lib); const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test, .{}); -- cgit v1.2.3 From 6674066839ac268c91ac109f843f1277477908f5 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 28 Jan 2024 09:47:41 +0800 Subject: refactor TestTarget --- build.zig | 73 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/build.zig b/build.zig index f1f78e7..56832dd 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,8 @@ const std = @import("std"); const builtin = @import("builtin"); const Step = std.Build.Step; +const ResolvedTarget = std.Build.ResolvedTarget; +const Query = std.Target.Query; var sqlite3: ?*Step.Compile = null; @@ -13,7 +15,7 @@ fn linkSqlite(b: *Step.Compile) void { } } -fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build.ResolvedTarget { +fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { if (bundled) { var tmp = original_target; @@ -36,7 +38,7 @@ fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build } const TestTarget = struct { - target: std.Build.ResolvedTarget, + query: Query, single_threaded: bool = false, bundled: bool, }; @@ -46,18 +48,18 @@ const ci_targets = switch (builtin.target.cpu.arch) { .linux => [_]TestTarget{ // Targets linux but other CPU archs. TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .abi = .musl, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86, .abi = .musl, }, @@ -66,14 +68,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { }, .windows => [_]TestTarget{ TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .abi = .gnu, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86, .abi = .gnu, }, @@ -82,14 +84,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { }, .macos => [_]TestTarget{ TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, }, .bundled = true, }, // TODO(vincent): this fails for some reason // TestTarget{ - // .target = .{ + // .query =.{ // .cpu_arch = .aarch64, // }, // .bundled = true, @@ -97,14 +99,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { }, else => [_]TestTarget{ TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, }, }, else => [_]TestTarget{ TestTarget{ - .target = .{ .query = .{}, .result = comptime std.zig.system.resolveTargetQuery(.{}) catch @panic("") }, + .query = .{}, .bundled = false, }, }, @@ -115,39 +117,39 @@ const all_test_targets = switch (builtin.target.cpu.arch) { .linux => [_]TestTarget{ // Targets linux but other CPU archs. TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .abi = .musl, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86, .abi = .musl, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .aarch64, .abi = .musl, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .riscv64, .abi = .musl, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .mips, .abi = .musl, }, @@ -155,7 +157,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, // TODO(vincent): failing for some time for unknown reasons // TestTarget{ - // .target = .{ + // .query =.{ // .cpu_arch = .arm, // .abi = .musleabihf, // }, @@ -163,14 +165,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { // }, // Targets windows TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .os_tag = .windows, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86, .os_tag = .windows, }, @@ -178,14 +180,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, // Targets macOS TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .os_tag = .macos, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .aarch64, .os_tag = .macos, }, @@ -194,14 +196,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, .windows => [_]TestTarget{ TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, .abi = .gnu, }, .bundled = true, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86, .abi = .gnu, }, @@ -210,11 +212,11 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, .freebsd => [_]TestTarget{ TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, }, .bundled = true, @@ -222,7 +224,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, .macos => [_]TestTarget{ TestTarget{ - .target = .{ + .query = .{ .cpu_arch = .x86_64, }, .bundled = true, @@ -230,23 +232,23 @@ const all_test_targets = switch (builtin.target.cpu.arch) { }, else => [_]TestTarget{ TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, }, }, else => [_]TestTarget{ TestTarget{ - .target = .{}, + .query = .{}, .bundled = false, }, }, }; -fn computeTestTargets(target: std.Build.ResolvedTarget, ci: ?bool) ?[]const TestTarget { +fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget { if (ci != null and ci.?) return &ci_targets; - if (target.isNative()) { + if (isNative) { // If the target is native we assume the user didn't change it with -Dtarget and run all test targets. return &all_test_targets; } @@ -261,7 +263,8 @@ pub fn build(b: *std.Build) !void { const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); const ci = b.option(bool, "ci", "Build and test in the CI on GitHub"); - const target = b.standardTargetOptions(.{}); + const query = b.standardTargetOptionsQueryOnly(.{}); + const target = b.resolveTargetQuery(query); const optimize = b.standardOptimizeOption(.{}); _ = b.addModule("sqlite", .{ .root_source_file = .{ .path = "sqlite.zig" } }); @@ -300,8 +303,8 @@ pub fn build(b: *std.Build) !void { const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool); preprocess_files_run.dependOn(&preprocess_files_tool_run.step); - const test_targets = computeTestTargets(target, ci) orelse &[_]TestTarget{.{ - .target = target, + const test_targets = computeTestTargets(query.isNative(), ci) orelse &[_]TestTarget{.{ + .query = query, .bundled = use_bundled orelse false, }}; const test_step = b.step("test", "Run library tests"); @@ -313,7 +316,7 @@ pub fn build(b: *std.Build) !void { for (test_targets) |test_target| { const bundled = use_bundled orelse test_target.bundled; - const cross_target = getTarget(test_target.target, bundled); + const cross_target = getTarget(b.resolveTargetQuery(test_target.query), bundled); const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; const test_name = b.fmt("{s}-{s}-{s}", .{ try cross_target.result.zigTriple(b.allocator), -- cgit v1.2.3 From 21a05912cb058a2b8f429eecf95045a03c29e3a5 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 28 Jan 2024 09:52:17 +0800 Subject: pie --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 56832dd..24d3be6 100644 --- a/build.zig +++ b/build.zig @@ -447,7 +447,7 @@ pub fn build(b: *std.Build) !void { .target = getTarget(target, true), .optimize = optimize, }); - // zigcrypto_loadable_ext.force_pic = true; + zigcrypto_loadable_ext.pie = true; zigcrypto_loadable_ext.addIncludePath(.{ .path = "c" }); zigcrypto_loadable_ext.root_module.addImport("sqlite", b.createModule(.{ .root_source_file = .{ .path = "sqlite.zig" }, -- cgit v1.2.3