Skip to content

Commit

Permalink
updated to zig v0.12.0 - v0.14.0-dev compat
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Sep 12, 2024
1 parent 98727fc commit 33bfea2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
zig-*
*zig-*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
53 changes: 31 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{""},
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 33bfea2

Please sign in to comment.