summary refs log tree commit diff
path: root/build.zig
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2025-03-11 16:20:35 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2025-03-11 16:20:35 +0900
commit7580c25a081e39732afaaa7a630d7f58005d5ab1 (patch)
treeecfb353f669af3d5df23bc099e514a7460ca4b73 /build.zig
parenteb65c5633e1bfae26ae95c6183cc74c2b5937943 (diff)
downloadzeal-0.1.0.tar.gz
Port to Zig 0.14 0.1.0
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig40
1 files changed, 12 insertions, 28 deletions
diff --git a/build.zig b/build.zig
index aa7fbff..5998a56 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 zeal.
 //
@@ -19,31 +19,22 @@
 const std = @import("std");
 const Build = std.Build;
 const Compile = Build.Step.Compile;
-const CrossTarget = std.zig.CrossTarget;
+const ResolvedTarget = Build.ResolvedTarget;
 const Module = Build.Module;
 const OptimizeMode = std.builtin.OptimizeMode;
 
-/// Link given library, executable, or object with shared libraries.
-pub fn link(compile: *Compile) void {
-    compile.linkSystemLibrary("openal");
-    compile.linkSystemLibrary("sndfile");
-    compile.linkSystemLibrary("c");
-}
-
 fn addExampleStep(comptime name: []const u8, description: []const u8,
                   b: *Build, module: *Module,
-                  target: CrossTarget, optimize: OptimizeMode) void {
+                  target: ResolvedTarget, optimize: OptimizeMode) void {
     const bin = b.addExecutable(.{
         .name = name,
-        .root_source_file = .{ .path = "examples/" ++ name ++ ".zig" },
+        .root_source_file = b.path("examples/" ++ name ++ ".zig"),
         .target = target,
         .optimize = optimize,
     });
-    bin.addModule("zeal", module);
-    link(bin);
+    bin.root_module.addImport("zeal", module);
 
     const cmd = b.addRunArtifact(bin);
-    cmd.step.dependOn(b.getInstallStep());
     if (b.args) |args|
         cmd.addArgs(args);
     b.step(name, description).dependOn(&cmd.step);
@@ -52,25 +43,18 @@ fn addExampleStep(comptime name: []const u8, description: []const u8,
 pub fn build(b: *Build) void {
     const target = b.standardTargetOptions(.{});
     const optimize = b.standardOptimizeOption(.{});
-    const lib = b.addStaticLibrary(.{
-        .name = "zeal",
-        .root_source_file = .{ .path = "src/zeal.zig" },
+    const module = b.addModule("zeal", .{
+        .root_source_file = b.path("src/zeal.zig"),
         .target = target,
         .optimize = optimize,
     });
-    link(lib);
+    module.linkSystemLibrary("openal", .{});
+    module.linkSystemLibrary("sndfile", .{});
+    module.linkSystemLibrary("c", .{});
 
-    var main_tests = b.addTest(.{
-        .root_source_file = .{ .path = "src/zeal.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 module = b.createModule(.{
-        .source_file = .{ .path = "src/zeal.zig" },
-    });
     addExampleStep("play", "Play audio", b, module, target, optimize);
     addExampleStep("hrtf", "Play audio with HRTF", b, module, target, optimize);
 }