|
| 1 | +const std = @import("std"); |
| 2 | +const builtin = @import("builtin"); |
| 3 | + |
| 4 | +const min_zig_version = std.SemanticVersion.parse("0.14.0-dev.1911") catch @panic("Where is .zigversion?"); |
| 5 | +const version = std.SemanticVersion.parse(@embedFile(".version")) catch @panic("Where is .version?"); |
| 6 | + |
| 7 | +const cetech1_build = @import("cetech1"); |
| 8 | + |
| 9 | +const enabled_cetech_modules = cetech1_build.core_modules ++ cetech1_build.editor_modules; |
| 10 | + |
| 11 | +pub const modules = [_][]const u8{ |
| 12 | + // Minimal |
| 13 | + "minimal", |
| 14 | +}; |
| 15 | + |
| 16 | +pub fn build(b: *std.Build) !void { |
| 17 | + try ensureZigVersion(); |
| 18 | + |
| 19 | + const target = b.standardTargetOptions(.{}); |
| 20 | + const optimize = b.standardOptimizeOption(.{}); |
| 21 | + |
| 22 | + // |
| 23 | + // OPTIONS |
| 24 | + // |
| 25 | + |
| 26 | + const options = .{ |
| 27 | + .externals_optimize = b.option(std.builtin.OptimizeMode, "externals_optimize", "Optimize for externals libs") orelse .ReleaseFast, |
| 28 | + .dynamic_modules = b.option(bool, "dynamic_modules", "build all modules in dynamic mode.") orelse true, |
| 29 | + //.static_modules = b.option(bool, "static_modules", "build all modules in static mode.") orelse false, |
| 30 | + |
| 31 | + // Tracy options |
| 32 | + .enable_tracy = b.option(bool, "with_tracy", "build with tracy.") orelse true, |
| 33 | + .tracy_on_demand = b.option(bool, "tracy_on_demand", "build tracy with TRACY_ON_DEMAND") orelse true, |
| 34 | + |
| 35 | + .enable_shaderc = b.option(bool, "with_shaderc", "build with shaderc support") orelse true, |
| 36 | + }; |
| 37 | + |
| 38 | + const options_step = b.addOptions(); |
| 39 | + options_step.addOption(std.SemanticVersion, "version", version); |
| 40 | + |
| 41 | + // add build args |
| 42 | + inline for (std.meta.fields(@TypeOf(options))) |field| { |
| 43 | + options_step.addOption(field.type, field.name, @field(options, field.name)); |
| 44 | + } |
| 45 | + const options_module = options_step.createModule(); |
| 46 | + _ = options_module; // autofix |
| 47 | + |
| 48 | + // |
| 49 | + // Extrnals |
| 50 | + // |
| 51 | + |
| 52 | + // Cetech1 |
| 53 | + const cetech1 = b.dependency( |
| 54 | + "cetech1", |
| 55 | + .{ |
| 56 | + .target = target, |
| 57 | + .optimize = optimize, |
| 58 | + .externals_optimize = options.externals_optimize, |
| 59 | + |
| 60 | + .with_tracy = options.enable_tracy, |
| 61 | + .tracy_on_demand = options.tracy_on_demand, |
| 62 | + |
| 63 | + .with_shaderc = options.enable_shaderc, |
| 64 | + |
| 65 | + //.static_modules = options.static_modules, |
| 66 | + .dynamic_modules = options.dynamic_modules, |
| 67 | + }, |
| 68 | + ); |
| 69 | + |
| 70 | + // |
| 71 | + // TOOLS |
| 72 | + // |
| 73 | + |
| 74 | + const generate_vscode_tool = b.addExecutable(.{ |
| 75 | + .name = "generate_vscode", |
| 76 | + .root_source_file = b.path("tools/generate_vscode.zig"), |
| 77 | + .target = target, |
| 78 | + }); |
| 79 | + generate_vscode_tool.root_module.addAnonymousImport("generate_vscode", .{ |
| 80 | + .root_source_file = b.path("externals/cetech1/src/tools/generate_vscode.zig"), |
| 81 | + }); |
| 82 | + |
| 83 | + // |
| 84 | + // Init repository step |
| 85 | + // |
| 86 | + const init_step = b.step("init", "init repository"); |
| 87 | + cetech1_build.initStep(b, init_step, "externals/cetech1/"); |
| 88 | + |
| 89 | + // |
| 90 | + // Gen vscode |
| 91 | + // |
| 92 | + const vscode_step = b.step("vscode", "init/update vscode configs"); |
| 93 | + const gen_vscode = b.addRunArtifact(generate_vscode_tool); |
| 94 | + gen_vscode.addDirectoryArg(b.path(".vscode/")); |
| 95 | + vscode_step.dependOn(&gen_vscode.step); |
| 96 | + |
| 97 | + if (options.enable_shaderc) { |
| 98 | + b.installArtifact(cetech1.artifact("shaderc")); |
| 99 | + } |
| 100 | + |
| 101 | + if (options.dynamic_modules) { |
| 102 | + b.installArtifact(cetech1.artifact("cetech1")); |
| 103 | + |
| 104 | + var buff: [256:0]u8 = undefined; |
| 105 | + |
| 106 | + // CETech modules |
| 107 | + for (enabled_cetech_modules) |m| { |
| 108 | + const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m}); |
| 109 | + const art = cetech1.artifact(artifact_name); |
| 110 | + const step = b.addInstallArtifact(art, .{}); |
| 111 | + b.default_step.dependOn(&step.step); |
| 112 | + } |
| 113 | + |
| 114 | + // Project modules |
| 115 | + for (modules) |m| { |
| 116 | + const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m}); |
| 117 | + const art = b.dependency(m, .{ |
| 118 | + .target = target, |
| 119 | + .optimize = optimize, |
| 120 | + }).artifact(artifact_name); |
| 121 | + |
| 122 | + const step = b.addInstallArtifact(art, .{}); |
| 123 | + b.default_step.dependOn(&step.step); |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +fn ensureZigVersion() !void { |
| 129 | + var installed_ver = builtin.zig_version; |
| 130 | + installed_ver.build = null; |
| 131 | + |
| 132 | + if (installed_ver.order(min_zig_version) == .lt) { |
| 133 | + std.log.err("\n" ++ |
| 134 | + \\--------------------------------------------------------------------------- |
| 135 | + \\ |
| 136 | + \\Installed Zig compiler version is too old. |
| 137 | + \\ |
| 138 | + \\Min. required version: {any} |
| 139 | + \\Installed version: {any} |
| 140 | + \\ |
| 141 | + \\Please install newer version and try again. |
| 142 | + \\zig/get_zig.sh <ARCH> |
| 143 | + \\ |
| 144 | + \\--------------------------------------------------------------------------- |
| 145 | + \\ |
| 146 | + , .{ min_zig_version, installed_ver }); |
| 147 | + return error.ZigIsTooOld; |
| 148 | + } |
| 149 | +} |
0 commit comments