zgpu

git clone git://git.electrosoup.com/zgpu
Log | Files | Refs | Submodules | README

build.zig (4136B)


      1 const std = @import("std");
      2 
      3 // Although this function looks imperative, note that its job is to
      4 // declaratively construct a build graph that will be executed by an external
      5 // runner.
      6 pub fn build(b: *std.Build) void {
      7     // Standard target options allows the person running `zig build` to choose
      8     // what target to build for. Here we do not override the defaults, which
      9     // means any target is allowed, and the default is native. Other options
     10     // for restricting supported target set are available.
     11     const target = b.standardTargetOptions(.{});
     12 
     13     // Standard optimization options allow the person running `zig build` to select
     14     // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
     15     // set a preferred release mode, allowing the user to decide how to optimize.
     16     const optimize = b.standardOptimizeOption(.{});
     17 
     18     const glfw = b.addModule("glfw-bindings", .{
     19         .root_source_file = b.path("src/glfw.zig"),
     20     });
     21     glfw.addIncludePath(b.path("include"));
     22     glfw.addObjectFile(b.path("lib/libglfw3.a"));
     23     if (target.result.os.tag == .macos) {
     24         glfw.linkFramework("Cocoa", .{});
     25         glfw.linkFramework("IOKit", .{});
     26         glfw.linkFramework("Quartz", .{});
     27         glfw.linkFramework("Metal", .{});
     28     }
     29 
     30     const math = b.addModule("math", .{
     31         .root_source_file = b.path("src/math.zig"),
     32     });
     33 
     34     const wgpu = b.addModule("wgpu-bindings", .{
     35         .root_source_file = b.path("src/wgpu-bindings/root.zig"),
     36     });
     37     wgpu.addIncludePath(b.path("include"));
     38     wgpu.addObjectFile(b.path("lib/libwgpu_native.a"));
     39 
     40     const wgpu_bindings_exe = b.addExecutable(.{
     41         .name = "wgpu-bindings-example",
     42         .root_source_file = b.path("src/wgpu-bindings/main.zig"),
     43         .target = target,
     44         .optimize = optimize,
     45     });
     46     wgpu_bindings_exe.root_module.addImport("glfw", glfw);
     47     wgpu_bindings_exe.root_module.addImport("wgpu", wgpu);
     48     wgpu_bindings_exe.linkLibCpp();
     49     b.installArtifact(wgpu_bindings_exe);
     50 
     51     // This *creates* a Run step in the build graph, to be executed when another
     52     // step is evaluated that depends on it. The next line below will establish
     53     // such a dependency.
     54     const run_cmd = b.addRunArtifact(wgpu_bindings_exe);
     55 
     56     // By making the run step depend on the install step, it will be run from the
     57     // installation directory rather than directly from within the cache directory.
     58     // This is not necessary, however, if the application depends on other installed
     59     // files, this ensures they will be present and in the expected location.
     60     run_cmd.step.dependOn(b.getInstallStep());
     61 
     62     // This allows the user to pass arguments to the application in the build
     63     // command itself, like this: `zig build run -- arg1 arg2 etc`
     64     if (b.args) |args| {
     65         run_cmd.addArgs(args);
     66     }
     67 
     68     // This creates a build step. It will be visible in the `zig build --help` menu,
     69     // and can be selected like this: `zig build run`
     70     // This will evaluate the `run` step rather than the default, which is "install".
     71     const run_step = b.step("run", "Run the app");
     72     run_step.dependOn(&run_cmd.step);
     73 
     74     const sandbox_exe = b.addExecutable(.{
     75         .name = "shader-sandbox",
     76         .root_source_file = b.path("src/shader-sandbox/main.zig"),
     77         .target = target,
     78         .optimize = optimize,
     79     });
     80     sandbox_exe.root_module.addImport("glfw", glfw);
     81     sandbox_exe.root_module.addImport("wgpu", wgpu);
     82     sandbox_exe.root_module.addImport("math", math);
     83     sandbox_exe.linkLibCpp();
     84     b.installArtifact(sandbox_exe);
     85     const run_sandbox_cmd = b.addRunArtifact(sandbox_exe);
     86     run_sandbox_cmd.step.dependOn(b.getInstallStep());
     87     const run_sandbox_step = b.step("sandbox", "Run shader sandbox");
     88     run_sandbox_step.dependOn(&run_sandbox_cmd.step);
     89 
     90     const test_step = b.step("test", "Run unit tests");
     91     const tests = b.addTest(.{
     92         .root_source_file = b.path("src/math.zig"),
     93         .target = target,
     94         .optimize = optimize,
     95     });
     96     const run_tests = b.addRunArtifact(tests);
     97     test_step.dependOn(&run_tests.step);
     98 }