diff options
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/build.zig b/build.zig index c9f6cb9..f0172b8 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,5 @@ // Build recipe -// Copyright (C) 2021-2023 Nguyễn Gia Phong +// Copyright (C) 2021-2023, 2025 Nguyễn Gia Phong // // This file is part of gfz. // @@ -17,46 +17,27 @@ // along with gfz. If not, see <https://www.gnu.org/licenses/>. const Build = @import("std").Build; -const Compile = Build.Step.Compile; - -/// Link given library, executable, or object with shared libraries. -pub fn link(compile: *Compile) void { - compile.linkSystemLibrary("glfw"); - compile.linkSystemLibrary("c"); -} pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const lib = b.addStaticLibrary(.{ - .name = "gfz", - .root_source_file = .{ .path = "src/gfz.zig" }, + const module = b.addModule("gfz", .{ + .root_source_file = b.path("src/gfz.zig"), .target = target, .optimize = optimize, }); - link(lib); + module.linkSystemLibrary("glfw", .{}); + module.linkSystemLibrary("c", .{}); - var main_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/gfz.zig" }, - .target = target, - .optimize = optimize, - }); - main_tests.linkLibrary(lib); - b.step("test", "Run library tests").dependOn(&main_tests.step); + const tests = b.addTest(.{ .root_module = module }); + b.step("test", "Run library tests").dependOn(&b.addRunArtifact(tests).step); const example = b.addExecutable(.{ .name = "gfz-context", - .root_source_file = .{ .path = "examples/context.zig" }, + .root_source_file = b.path("examples/context.zig"), .target = target, .optimize = optimize, }); - example.addModule("gfz", b.createModule(.{ - .source_file = .{ .path = "src/gfz.zig" }, - })); - link(example); - const run_example = b.addRunArtifact(example); - run_example.step.dependOn(b.getInstallStep()); - if (b.args) |args| - run_example.addArgs(args); - b.step("example", "Run example").dependOn(&run_example.step); + example.root_module.addImport("gfz", module); + b.step("example", "Run example").dependOn(&b.addRunArtifact(example).step); } |