From 96f83b9104edf64c8c0228da818345a9c7912ce4 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Fri, 8 May 2020 18:16:05 +1000 Subject: [PATCH] Make build file more readable --- build.zig | 85 ++++++++++++++----------------------------------------- 1 file changed, 22 insertions(+), 63 deletions(-) diff --git a/build.zig b/build.zig index f0bd440..6ad06fc 100755 --- a/build.zig +++ b/build.zig @@ -5,47 +5,34 @@ // Date: 2020-02-15 // -const Builder = @import("std").build.Builder; +const std = @import("std"); +const Builder = std.build.Builder; -pub fn build(b: *Builder) void +pub fn createExe(b: *Builder, name: []const u8, source: []const u8, desc: []const u8) *std.build.LibExeObjStep { const mode = b.standardReleaseOptions(); - var basicWindow = b.addExecutable("basic_window", "examples/core/basic_window.zig"); - basicWindow.setBuildMode(mode); - basicWindow.linkSystemLibrary("raylib"); - basicWindow.addPackagePath("raylib", "lib/raylib-zig.zig"); + var exe = b.addExecutable(name, source); + exe.setBuildMode(mode); + exe.linkSystemLibrary("raylib"); + exe.addPackagePath("raylib", "lib/raylib-zig.zig"); + exe.addPackagePath("raylib-math", "lib/raylib-zig-math.zig"); - var inputKeys = b.addExecutable("input_keys", "examples/core/input_keys.zig"); - inputKeys.setBuildMode(mode); - inputKeys.linkSystemLibrary("raylib"); - inputKeys.addPackagePath("raylib", "lib/raylib-zig.zig"); + const runExe = exe.run(); + const exeStep = b.step(name, desc); + exeStep.dependOn(&runExe.step); + return exe; +} - var inputMouse = b.addExecutable("input_mouse", "examples/core/input_mouse.zig"); - inputMouse.setBuildMode(mode); - inputMouse.linkSystemLibrary("raylib"); - inputMouse.addPackagePath("raylib", "lib/raylib-zig.zig"); - - var inputMouseWheel = b.addExecutable("input_mouse_wheel", "examples/core/input_mouse_wheel.zig"); - inputMouseWheel.setBuildMode(mode); - inputMouseWheel.linkSystemLibrary("raylib"); - inputMouseWheel.addPackagePath("raylib", "lib/raylib-zig.zig"); - - var inputMultitouch = b.addExecutable("input_multitouch", "examples/core/input_multitouch.zig"); - inputMultitouch.setBuildMode(mode); - inputMultitouch.linkSystemLibrary("raylib"); - inputMultitouch.addPackagePath("raylib", "lib/raylib-zig.zig"); - - var twoDCamera = b.addExecutable("2d_camera", "examples/core/2d_camera.zig"); - twoDCamera.setBuildMode(mode); - twoDCamera.linkSystemLibrary("raylib"); - twoDCamera.addPackagePath("raylib", "lib/raylib-zig.zig"); - twoDCamera.addPackagePath("raylib-math", "lib/raylib-zig-math.zig"); - - var modelsLoading = b.addExecutable("models_loading", "examples/models/models_loading.zig"); - modelsLoading.setBuildMode(mode); - modelsLoading.linkSystemLibrary("raylib"); - modelsLoading.addPackagePath("raylib", "lib/raylib-zig.zig"); +pub fn build(b: *Builder) void +{ + var basicWindow = createExe(b, "basic_window" , "examples/core/basic_window.zig" , "Creates a basic window with text"); + var inputKeys = createExe(b, "input_keys" , "examples/core/input_keys.zig" , "Simple keyboard input"); + var inputMouse = createExe(b, "input_mouse" , "examples/core/input_mouse.zig" , "Simple mouse input"); + var inputMouseWheel = createExe(b, "input_mouse_wheel", "examples/core/input_mouse_wheel.zig", "Mouse wheel input"); + var inputMultitouch = createExe(b, "input_multitouch" , "examples/core/input_multitouch.zig" , "Multitouch input"); + var twoDCamera = createExe(b, "2d_camera" , "examples/core/2d_camera.zig" , "Shows the functionality of a 2D camera"); + var modelsLoading = createExe(b, "models_loading" , "examples/models/models_loading.zig" , "Loads a model and renders it"); const examplesStep = b.step("examples", "Builds all the examples"); examplesStep.dependOn(&basicWindow.step); @@ -55,32 +42,4 @@ pub fn build(b: *Builder) void examplesStep.dependOn(&inputMultitouch.step); examplesStep.dependOn(&twoDCamera.step); examplesStep.dependOn(&modelsLoading.step); - - const runBasicWindow = basicWindow.run(); - const basicWindowStep = b.step("basic_window", "Creates a basic window with text"); - basicWindowStep.dependOn(&runBasicWindow.step); - - const runInputKeys = inputKeys.run(); - const inputKeysStep = b.step("input_keys", "Simple keyboard input"); - inputKeysStep.dependOn(&runInputKeys.step); - - const runInputMouse = inputMouse.run(); - const inputMouseStep = b.step("input_mouse", "Simple mouse input"); - inputMouseStep.dependOn(&runInputMouse.step); - - const runInputMouseWheel = inputMouseWheel.run(); - const inputMouseWheelStep = b.step("input_mouse_wheel", "Mouse wheel input"); - inputMouseWheelStep.dependOn(&runInputMouseWheel.step); - - const runInputMultitouch = inputMultitouch.run(); - const inputMultitouchStep = b.step("input_multitouch", "Multitouch (duh)"); - inputMultitouchStep.dependOn(&runInputMultitouch.step); - - const run2DCamera = twoDCamera.run(); - const twoDCameraStep = b.step("2d_camera", "Shows the functionality of a 2D camera"); - twoDCameraStep.dependOn(&run2DCamera.step); - - const runModelsLoading= modelsLoading.run(); - const modelsLoadingStep = b.step("models_loading", "Loads a model and renders it"); - modelsLoadingStep.dependOn(&runModelsLoading.step); }