Created
September 21, 2020 07:59
-
-
Save MasterQ32/10cb7a8c3ce1105f870b2713b952ab4e to your computer and use it in GitHub Desktop.
build.zig example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const pkgs = struct { | |
const sdl2 = std.build.Pkg{ | |
.name = "sdl2", | |
.path = "./lib/SDL.zig/src/lib.zig", | |
}; | |
const zlm = std.build.Pkg{ | |
.name = "zlm", | |
.path = "./lib/zlm/zlm.zig", | |
}; | |
const zgl = std.build.Pkg{ | |
.name = "zgl", | |
.path = "./lib/zgl/zgl.zig", | |
}; | |
const navmesh = std.build.Pkg{ | |
.name = "navmesh", | |
.path = "./lib/navmesh/src/navmesh.zig", | |
}; | |
const wavefront_obj = std.build.Pkg{ | |
.name = "wavefront-obj", | |
.path = "./lib/zig-gamedev-lib/src/wavefront-obj.zig", | |
.dependencies = &[_]std.build.Pkg{ | |
zlm, | |
}, | |
}; | |
const game = std.build.Pkg{ | |
.name = "game", | |
.path = "./src/main.zig", | |
.dependencies = &[_]std.build.Pkg{ | |
zlm, zgl, sdl2, navmesh, | |
}, | |
}; | |
}; | |
pub fn build(b: *std.build.Builder) !void { | |
// Standard target options allows the person running `zig build` to choose | |
// what target to build for. Here we do not override the defaults, which | |
// means any target is allowed, and the default is native. Other options | |
// for restricting supported target set are available. | |
const target = b.standardTargetOptions(.{}); | |
// Standard release options allow the person running `zig build` to select | |
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | |
const mode = b.standardReleaseOptions(); | |
const game_exe = b.addExecutable("digital-scavenger-again", "src/main.zig"); | |
game_exe.setTarget(target); | |
game_exe.setBuildMode(mode); | |
game_exe.addPackage(pkgs.sdl2); | |
game_exe.addPackage(pkgs.zlm); | |
game_exe.addPackage(pkgs.zgl); | |
game_exe.linkLibC(); | |
game_exe.linkSystemLibrary("sdl2"); | |
game_exe.linkSystemLibrary("epoxy"); | |
game_exe.addIncludeDir("./lib/stb"); | |
game_exe.addCSourceFile("./src/stbi.c", &[_][]const u8{ | |
"-std=c99", | |
}); | |
game_exe.install(); | |
const modelconv_exe = b.addExecutable("model-converter", "./tools/convert-model.zig"); | |
modelconv_exe.addPackage(pkgs.wavefront_obj); | |
modelconv_exe.addPackage(pkgs.zlm); | |
modelconv_exe.addPackage(pkgs.game); | |
for (model_files) |input_file| { | |
const output_file = try std.mem.join(b.allocator, "", &[_][]const u8{ | |
"./src/assets/models/", | |
removeExtension(std.fs.path.basename(input_file)), | |
".m", | |
}); | |
const conv_step = modelconv_exe.run(); | |
conv_step.addArg(input_file); | |
conv_step.addArg(output_file); | |
game_exe.step.dependOn(&conv_step.step); | |
} | |
const navmesh_exe = b.addExecutable("navmesh-converter", "./tools/convert-navmesh.zig"); | |
navmesh_exe.addPackage(pkgs.wavefront_obj); | |
navmesh_exe.addPackage(pkgs.zlm); | |
navmesh_exe.addPackage(pkgs.navmesh); | |
navmesh_exe.addPackage(pkgs.game); | |
for (navmesh_files) |input_file| { | |
const output_file = try std.mem.join(b.allocator, "", &[_][]const u8{ | |
"./src/assets/navmesh/", | |
removeExtension(std.fs.path.basename(input_file)), | |
".nav", | |
}); | |
const conv_step = navmesh_exe.run(); | |
conv_step.addArg(input_file); | |
conv_step.addArg(output_file); | |
game_exe.step.dependOn(&conv_step.step); | |
} | |
const run_cmd = game_exe.run(); | |
run_cmd.step.dependOn(b.getInstallStep()); | |
const run_step = b.step("run", "Run the app"); | |
run_step.dependOn(&run_cmd.step); | |
} | |
fn removeExtension(in: []const u8) []const u8 { | |
return if (std.mem.lastIndexOf(u8, in, ".")) |i| | |
in[0..i] | |
else | |
in; | |
} | |
const model_files = [_][]const u8{ | |
"./assets/models/mesh_normaldorf.obj", | |
"./assets/models/water-plane.obj", | |
}; | |
const navmesh_files = [_][]const u8{ | |
"./assets/models/navmesh_normaldorf.obj", | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment