Skip to content

Commit 4fce0ee

Browse files
authored
Merge pull request #4 from ckrowland/main
Modulize zstbi
2 parents 2517d3f + 561c697 commit 4fce0ee

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn build(b: *std.Build) void {
2727
2828
const zstbi = b.dependency("zstbi", .{});
2929
exe.root_module.addImport("zstbi", zstbi.module("root"));
30-
exe.linkLibrary(zstbi.artifact("zstbi"));
3130
}
3231
```
3332
Now in your code you may import and use `zstbi`.

build.zig

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ pub fn build(b: *std.Build) void {
44
const optimize = b.standardOptimizeOption(.{});
55
const target = b.standardTargetOptions(.{});
66

7-
_ = b.addModule("root", .{
7+
const zstbi = b.addModule("root", .{
88
.root_source_file = b.path("src/zstbi.zig"),
99
});
1010

11-
const zstbi_lib = b.addStaticLibrary(.{
12-
.name = "zstbi",
13-
.target = target,
14-
.optimize = optimize,
15-
});
16-
zstbi_lib.addIncludePath(b.path("libs/stbi"));
11+
zstbi.addIncludePath(b.path("libs/stbi"));
1712
if (optimize == .Debug) {
1813
// TODO: Workaround for Zig bug.
19-
zstbi_lib.addCSourceFile(.{
14+
zstbi.addCSourceFile(.{
2015
.file = b.path("src/zstbi.c"),
2116
.flags = &.{
2217
"-std=c99",
@@ -26,7 +21,7 @@ pub fn build(b: *std.Build) void {
2621
},
2722
});
2823
} else {
29-
zstbi_lib.addCSourceFile(.{
24+
zstbi.addCSourceFile(.{
3025
.file = b.path("src/zstbi.c"),
3126
.flags = &.{
3227
"-std=c99",
@@ -36,13 +31,12 @@ pub fn build(b: *std.Build) void {
3631
}
3732

3833
if (target.result.os.tag == .emscripten) {
39-
zstbi_lib.addIncludePath(.{
34+
zstbi.addIncludePath(.{
4035
.cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/include" }),
4136
});
4237
} else {
43-
zstbi_lib.linkLibC();
38+
zstbi.link_libc = true;
4439
}
45-
b.installArtifact(zstbi_lib);
4640

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

@@ -52,7 +46,7 @@ pub fn build(b: *std.Build) void {
5246
.target = target,
5347
.optimize = optimize,
5448
});
55-
tests.linkLibrary(zstbi_lib);
49+
tests.root_module.addImport("zstbi", zstbi);
5650
b.installArtifact(tests);
5751

5852
test_step.dependOn(&b.addRunArtifact(tests).step);

0 commit comments

Comments
 (0)