From 33bfea2503a300d7ca4a1513b97182225af55aca Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Thu, 12 Sep 2024 10:32:44 -0300 Subject: [PATCH] updated to zig v0.12.0 - v0.14.0-dev compat --- .github/workflows/CI.yml | 4 +-- .gitignore | 2 +- README.md | 2 +- build.zig | 53 +++++++++++++++++++++++----------------- build.zig.zon | 4 +-- examples/tutorial1.zig | 2 +- examples/tutorial2.zig | 4 +-- 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a2bcb9f..393b8a7 100755 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,9 +14,7 @@ jobs: with: submodules: recursive fetch-depth: 0 - - uses: goto-bus-stop/setup-zig@v2 - with: - version: 0.11.0 + - uses: mlugg/setup-zig@v1 - name: Build Summary run: zig build --summary all -freference-trace \ No newline at end of file diff --git a/.gitignore b/.gitignore index ffdb12e..937e9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -zig-* \ No newline at end of file +*zig-* diff --git a/README.md b/README.md index 6a82d79..9a79909 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Excel. It cannot be used to modify an existing file. ## Requirements -- [zig v0.11.0 or higher](https://ziglang.org/download) +- [zig v0.12.0 or higher](https://ziglang.org/download) - [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter) diff --git a/build.zig b/build.zig index b6a52c4..6ac77f6 100644 --- a/build.zig +++ b/build.zig @@ -9,45 +9,52 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .USE_SYSTEM_MINIZIP = true, }); - const xlsxwriter = xlsxwriter_dep.artifact("xlsxwriter"); - _ = b.addModule("xlsxwriter", .{ - .source_file = .{ - .path = "src/xlsxwriter.zig", - }, + const xlsxwriter_module = b.addModule("xlsxwriter", .{ + .root_source_file = b.path("src/xlsxwriter.zig"), }); + // get libxlsxwriter + xlsxwriter_module.linkLibrary(xlsxwriter_dep.artifact("xlsxwriter")); + xlsxwriter_module.link_libc = true; + makeExample(b, .{ .path = "examples/tutorial1.zig", - .lib = xlsxwriter, + .module = xlsxwriter_module, + .target = target, + .optimize = optimize, }); makeExample(b, .{ .path = "examples/tutorial2.zig", - .lib = xlsxwriter, + .module = xlsxwriter_module, + .target = target, + .optimize = optimize, }); makeExample(b, .{ .path = "examples/array_formula.zig", - .lib = xlsxwriter, + .module = xlsxwriter_module, + .target = target, + .optimize = optimize, }); makeExample(b, .{ .path = "examples/chart.zig", - .lib = xlsxwriter, + .module = xlsxwriter_module, + .target = target, + .optimize = optimize, }); } -fn makeExample(b: *std.build, property: BuildInfo) void { +fn makeExample(b: *std.Build, options: BuildInfo) void { const example = b.addExecutable(.{ - .name = property.filename(), - .root_source_file = .{ .path = property.path }, - .target = property.lib.target, - .optimize = property.lib.optimize, + .name = options.filename(), + .root_source_file = b.path(options.path), + .target = options.target, + .optimize = options.optimize, }); - for (property.lib.include_dirs.items) |include| { - example.include_dirs.append(include) catch {}; + for (options.module.include_dirs.items) |include| { + example.root_module.include_dirs.append(b.allocator, include) catch {}; } - example.addModule("xlsxwriter", b.modules.get("xlsxwriter").?); - example.linkLibrary(property.lib); - example.linkLibC(); + example.root_module.addImport("xlsxwriter", options.module); b.installArtifact(example); @@ -57,13 +64,15 @@ fn makeExample(b: *std.build, property: BuildInfo) void { run_cmd.addArgs(args); } - const descr = b.fmt("Run the {s} example", .{property.filename()}); - const run_step = b.step(property.filename(), descr); + const descr = b.fmt("Run the {s} example", .{options.filename()}); + const run_step = b.step(options.filename(), descr); run_step.dependOn(&run_cmd.step); } const BuildInfo = struct { - lib: *std.Build.Step.Compile, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + module: *std.Build.Module, path: []const u8, fn filename(self: BuildInfo) []const u8 { diff --git a/build.zig.zon b/build.zig.zon index 9fd4304..a118472 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,8 +3,8 @@ .version = "0.1.0", .dependencies = .{ .xlsxwriter = .{ - .url = "https://github.com/jmcnamara/libxlsxwriter/archive/6a2364c42cac3bb6cf80ac501c3d5b3c2910bd17.tar.gz", - .hash = "1220ec59ba47b272a7f1f7b10fccd68c25cedc32ebb68c2e4b29e6998067008e3ad7", + .url = "git+https://github.com/kassane/libxlsxwriter?ref=zig-build#3d258a4c7418c4d27d712d1d0b99692dd300e9fe", + .hash = "1220b6b099174e25a087c75884789c155cba82f2d81b7137624c69cb628b1abb7b70", }, }, .paths = .{""}, diff --git a/examples/tutorial1.zig b/examples/tutorial1.zig index ffceb50..497c03d 100644 --- a/examples/tutorial1.zig +++ b/examples/tutorial1.zig @@ -20,7 +20,7 @@ pub fn main() void { // Start from the first cell. Rows and columns are zero indexed. var row: u32 = 0; - var col: u16 = 0; + const col: u16 = 0; // Iterate over the data and write it out element by element. while (row < 4) { diff --git a/examples/tutorial2.zig b/examples/tutorial2.zig index b6aa0e7..5b6fc23 100644 --- a/examples/tutorial2.zig +++ b/examples/tutorial2.zig @@ -21,8 +21,8 @@ pub fn main() void { // Start from the first cell. Rows and columns are zero indexed. var row: u32 = 0; - var col: u16 = 0; - var index: usize = 0; + const col: u16 = 0; + const index: usize = 0; // Add a bold format to use to highlight cells. const bold: ?*xlsxwriter.lxw_format = xlsxwriter.workbook_add_format(workbook);