zig-webgpu-gen

git clone git://git.electrosoup.com/zig-webgpu-gen
Log | Files | Refs

build.zig (2736B)


      1 const std = @import("std");
      2 
      3 pub fn build(b: *std.Build) !void {
      4     const target = b.standardTargetOptions(.{});
      5     const optimize = b.standardOptimizeOption(.{});
      6 
      7     const webgpu_headers = b.lazyDependency("webgpu_headers", .{});
      8     const wgpu_native = try switch (target.result.os.tag) {
      9         .linux => switch (target.result.cpu.arch) {
     10             .x86_64 => switch (optimize) {
     11                 .Debug => b.lazyDependency(
     12                     "wgpu_native_linux_x86_64_debug",
     13                     .{},
     14                 ),
     15                 .ReleaseFast, .ReleaseSafe, .ReleaseSmall => b.lazyDependency(
     16                     "wgpu_native_linux_x86_64_release",
     17                     .{},
     18                 ),
     19             },
     20             else => error.NotSupported,
     21         },
     22         .macos => switch (target.result.cpu.arch) {
     23             .x86_64 => switch (optimize) {
     24                 .Debug => b.lazyDependency(
     25                     "wgpu_native_macos_x86_64_debug",
     26                     .{},
     27                 ),
     28                 .ReleaseFast, .ReleaseSafe, .ReleaseSmall => b.lazyDependency(
     29                     "wgpu_native_macos_x86_64_release",
     30                     .{},
     31                 ),
     32             },
     33             else => error.NotSupported,
     34         },
     35         else => error.NotSupported,
     36     };
     37 
     38     const exe_mod = b.createModule(.{
     39         .root_source_file = b.path("src/main.zig"),
     40         .target = target,
     41         .optimize = optimize,
     42     });
     43     const exe = b.addExecutable(.{
     44         .name = "webgpu-gen",
     45         .root_module = exe_mod,
     46     });
     47     const run_cmd = b.addRunArtifact(exe);
     48     if (webgpu_headers) |dep| {
     49         const webgpu_json = dep.path("webgpu.json");
     50         run_cmd.addFileArg(webgpu_json);
     51     }
     52     const gen_file = run_cmd.addOutputFileArg("webgpu.zig");
     53 
     54     const install_raw = b.addInstallFile(gen_file, "webgpu-raw.zig");
     55     install_raw.step.dependOn(&run_cmd.step);
     56     b.getInstallStep().dependOn(&install_raw.step);
     57 
     58     const fmt_cmd = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt" });
     59     fmt_cmd.addFileArg(gen_file);
     60 
     61     const install_fmt = b.addInstallFile(gen_file, "webgpu.zig");
     62     install_fmt.step.dependOn(&fmt_cmd.step);
     63     b.getInstallStep().dependOn(&install_fmt.step);
     64 
     65     const lib_mod = b.createModule(.{
     66         .root_source_file = gen_file,
     67         .target = target,
     68         .optimize = optimize,
     69         .link_libc = true,
     70     });
     71     const lib = b.addLibrary(.{
     72         .linkage = .static,
     73         .name = "webgpu",
     74         .root_module = lib_mod,
     75     });
     76     lib.step.dependOn(&fmt_cmd.step);
     77 
     78     if (wgpu_native) |dep| {
     79         const wgpu_lib = dep.path("lib/libwgpu_native.a");
     80         lib_mod.addObjectFile(wgpu_lib);
     81     }
     82 
     83     b.installArtifact(lib);
     84 }