From 1642c7c9a533bcd05c6e593c44bc30cd93352b2f Mon Sep 17 00:00:00 2001 From: Connor Rowland Date: Fri, 21 Feb 2025 20:22:06 -0800 Subject: [PATCH 1/2] Make zstbi a module --- README.md | 1 - build.zig | 21 ++++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9e8816c..3f93656 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ pub fn build(b: *std.Build) void { const zstbi = b.dependency("zstbi", .{}); exe.root_module.addImport("zstbi", zstbi.module("root")); - exe.linkLibrary(zstbi.artifact("zstbi")); } ``` Now in your code you may import and use `zstbi`. diff --git a/build.zig b/build.zig index b12a124..d5ad8e8 100644 --- a/build.zig +++ b/build.zig @@ -4,19 +4,14 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); - _ = b.addModule("root", .{ + const zstbi = b.addModule("root", .{ .root_source_file = b.path("src/zstbi.zig"), }); - const zstbi_lib = b.addStaticLibrary(.{ - .name = "zstbi", - .target = target, - .optimize = optimize, - }); - zstbi_lib.addIncludePath(b.path("libs/stbi")); + zstbi.addIncludePath(b.path("libs/stbi")); if (optimize == .Debug) { // TODO: Workaround for Zig bug. - zstbi_lib.addCSourceFile(.{ + zstbi.addCSourceFile(.{ .file = b.path("src/zstbi.c"), .flags = &.{ "-std=c99", @@ -26,7 +21,7 @@ pub fn build(b: *std.Build) void { }, }); } else { - zstbi_lib.addCSourceFile(.{ + zstbi.addCSourceFile(.{ .file = b.path("src/zstbi.c"), .flags = &.{ "-std=c99", @@ -36,13 +31,13 @@ pub fn build(b: *std.Build) void { } if (target.result.os.tag == .emscripten) { - zstbi_lib.addIncludePath(.{ + zstbi.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/include" }), }); } else { - zstbi_lib.linkLibC(); + zstbi.link_libc = true; } - b.installArtifact(zstbi_lib); + b.installArtifact(zstbi); const test_step = b.step("test", "Run zstbi tests"); @@ -52,7 +47,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, }); - tests.linkLibrary(zstbi_lib); + tests.root_module.addImport("zstbi", zstbi); b.installArtifact(tests); test_step.dependOn(&b.addRunArtifact(tests).step); From 561c6978c6d13e98f031758f87b7e1f72a775b78 Mon Sep 17 00:00:00 2001 From: Connor Rowland Date: Fri, 21 Feb 2025 20:24:32 -0800 Subject: [PATCH 2/2] Remove install step --- build.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/build.zig b/build.zig index d5ad8e8..cebdc6b 100644 --- a/build.zig +++ b/build.zig @@ -37,7 +37,6 @@ pub fn build(b: *std.Build) void { } else { zstbi.link_libc = true; } - b.installArtifact(zstbi); const test_step = b.step("test", "Run zstbi tests");