From 672015ba6224b47fefabedaaf639e493a3b04340 Mon Sep 17 00:00:00 2001 From: Jiacai Liu Date: Sun, 7 Jan 2024 12:13:58 +0800 Subject: [PATCH] fix: adopt with upstream (#41) https://github.com/ziglang/zig/pull/18160 --- Makefile | 2 +- build.zig | 12 +++++------- build.zig.zon | 9 +++------ src/08-02.zig | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 52a11f7..7924668 100644 --- a/Makefile +++ b/Makefile @@ -29,4 +29,4 @@ endif .PHONY: clean clean: - rm -f zig-out zig-cache + rm -rf zig-out zig-cache diff --git a/build.zig b/build.zig index 4010a61..1ab45aa 100644 --- a/build.zig +++ b/build.zig @@ -9,13 +9,14 @@ pub fn build(b: *std.Build) !void { try addExample(b, run_all_step); } -fn addExample(b: *std.Build, run_all: *std.build.Step) !void { +fn addExample(b: *std.Build, run_all: *std.Build.Step) !void { const gt_zig_0_11 = builtin.zig_version.minor > 11; const src_dir = if (gt_zig_0_11) try fs.cwd().openDir("src", .{ .iterate = true }) else try fs.cwd().openIterableDir("src", .{}); + const target = b.standardTargetOptions(.{}); var it = src_dir.iterate(); while (try it.next()) |entry| { switch (entry.kind) { @@ -24,18 +25,15 @@ fn addExample(b: *std.Build, run_all: *std.build.Step) !void { const exe = b.addExecutable(.{ .name = try allocPrint(b.allocator, "examples-{s}", .{name}), .root_source_file = .{ .path = try allocPrint(b.allocator, "src/{s}.zig", .{name}) }, - .target = .{}, + .target = target, .optimize = .Debug, }); if (std.mem.eql(u8, "13-01", name) and gt_zig_0_11) { const zigcli = b.dependency("zigcli", .{}); - exe.addModule("simargs", zigcli.module("simargs")); + exe.root_module.addImport("simargs", zigcli.module("simargs")); } else if (std.mem.eql(u8, "14-01", name)) { exe.linkSystemLibrary("sqlite3"); exe.linkLibC(); - // const sqlite = b.dependency("sqlite", .{}); - // exe.addModule("sqlite", sqlite.module("sqlite")); - // exe.linkLibrary(sqlite.artifact("sqlite")); } else if (std.mem.eql(u8, "14-02", name)) { exe.linkSystemLibrary("libpq"); exe.linkLibC(); @@ -43,7 +41,7 @@ fn addExample(b: *std.Build, run_all: *std.build.Step) !void { const lib = b.addStaticLibrary(.{ .name = "regex_slim", .optimize = .Debug, - .target = .{}, + .target = target, }); lib.addIncludePath(.{ .path = "lib" }); if (gt_zig_0_11) { diff --git a/build.zig.zon b/build.zig.zon index 168d1a4..bf3dd26 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,17 +3,14 @@ .version = "0.1.0", .paths = .{ "src", + "lib", "build.zig", "build.zig.zon", }, .dependencies = .{ .zigcli = .{ - .url = "https://github.com/jiacai2050/zigcli/archive/d5db773.tar.gz", - .hash = "1220f4ba4de1b2574bc0f10977bcce464933f7c01c9a071b4484f1b0bda56de30a67", - }, - .sqlite = .{ - .url = "https://github.com/vrischmann/zig-sqlite/archive/aa6f95b.tar.gz", - .hash = "1220d751f09c5c18c45f0a42af71ff255e62ae73deb34567ca42e9e67c614a4daa5a", + .url = "https://github.com/jiacai2050/zigcli/archive/1e83260.tar.gz", + .hash = "12202a9e207619ea538b0d60456391a4699864a432dfdad236bfd6cfc691663b67e8", }, }, } diff --git a/src/08-02.zig b/src/08-02.zig index ce2e5f8..99f49c9 100644 --- a/src/08-02.zig +++ b/src/08-02.zig @@ -32,7 +32,7 @@ pub fn main() !void { try child.collectOutput(&stdout, &stderr, 1024); const term = try child.wait(); - try std.testing.expectEqual(term, .{ .Exited = 0 }); + try std.testing.expectEqual(term.Exited, 0); try std.testing.expectEqualStrings("hello world", stdout.items); try std.testing.expectEqualStrings("", stderr.items); }