Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
20 changes: 7 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -36,13 +31,12 @@ 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);

const test_step = b.step("test", "Run zstbi tests");

Expand All @@ -52,7 +46,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);
Expand Down