diff options
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/build.zig b/build.zig index f701451..c9f6cb9 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,5 @@ // Build recipe -// Copyright (C) 2021 Nguyễn Gia Phong +// Copyright (C) 2021-2023 Nguyễn Gia Phong // // This file is part of gfz. // @@ -16,36 +16,47 @@ // You should have received a copy of the GNU Lesser General Public License // along with gfz. If not, see <https://www.gnu.org/licenses/>. -const std = @import("std"); -const Builder = std.build.Builder; -const LibExeObjStep = std.build.LibExeObjStep; +const Build = @import("std").Build; +const Compile = Build.Step.Compile; /// Link given library, executable, or object with shared libraries. -pub fn link(lib_exe_obj: *LibExeObjStep) void { - lib_exe_obj.linkSystemLibrary("glfw"); - lib_exe_obj.linkSystemLibrary("c"); +pub fn link(compile: *Compile) void { + compile.linkSystemLibrary("glfw"); + compile.linkSystemLibrary("c"); } -pub fn build(b: *Builder) void { - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); - - const lib = b.addStaticLibrary("gfz", "src/gfz.zig"); +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" }, + .target = target, + .optimize = optimize, + }); link(lib); - lib.setBuildMode(mode); - lib.install(); - - const example = b.addExecutable("gfz-context", "examples/context.zig"); - example.addPackagePath("gfz", "src/gfz.zig"); - example.linkLibrary(lib); - example.setBuildMode(mode); - example.install(); - var main_tests = b.addTest("src/gfz.zig"); + var main_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/gfz.zig" }, + .target = target, + .optimize = optimize, + }); main_tests.linkLibrary(lib); - main_tests.setBuildMode(mode); + b.step("test", "Run library tests").dependOn(&main_tests.step); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + const example = b.addExecutable(.{ + .name = "gfz-context", + .root_source_file = .{ .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); } |