| 1 |
const std = @import("std"); |
| 2 |
const rl = @import("raylib"); |
| 3 |
|
| 4 |
pub fn build(b: *std.Build) !void { |
| 5 |
const target = b.standardTargetOptions(.{}); |
| 6 |
const optimize = b.standardOptimizeOption(.{}); |
| 7 |
const platform = b.option(rl.PlatformBackend, "platform", "select the platform") orelse rl.PlatformBackend.glfw; |
| 8 |
const zig = b.option(bool, "zig", "compile zig code") orelse false; |
| 9 |
|
| 10 |
const raylib_dep = b.dependency("raylib", .{ |
| 11 |
.target = target, |
| 12 |
.optimize = optimize, |
| 13 |
.platform = platform, |
| 14 |
}); |
| 15 |
const raylib_artifact = raylib_dep.artifact("raylib"); |
| 16 |
|
| 17 |
if (platform == .sdl3) { |
| 18 |
if (b.lazyDependency("sdl3", .{ .optimize = optimize, .target = target })) |dep| { |
| 19 |
raylib_artifact.root_module.linkLibrary(dep.artifact("SDL3")); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
var exe_mod: *std.Build.Module = undefined; |
| 24 |
|
| 25 |
if (zig) { |
| 26 |
exe_mod = b.createModule(.{ |
| 27 |
.root_source_file = b.path("src/core_basic_window.zig"), |
| 28 |
.target = target, |
| 29 |
.optimize = optimize, |
| 30 |
}); |
| 31 |
exe_mod.addImport("raylib", raylib_dep.module("raylib")); |
| 32 |
} else { |
| 33 |
exe_mod = b.createModule(.{ |
| 34 |
.target = target, |
| 35 |
.optimize = optimize, |
| 36 |
.link_libc = true, |
| 37 |
}); |
| 38 |
exe_mod.addCSourceFile(.{ .file = b.path("src/core_basic_window.c") }); |
| 39 |
exe_mod.linkLibrary(raylib_artifact); |
| 40 |
} |
| 41 |
|
| 42 |
const run_step = b.step("run", "Run the app"); |
| 43 |
|
| 44 |
// web exports are completely separate |
| 45 |
if (target.query.os_tag == .emscripten) { |
| 46 |
const emsdk = rl.emsdk; |
| 47 |
const wasm = b.addLibrary(.{ |
| 48 |
.name = "core_basic_window_web", |
| 49 |
.root_module = exe_mod, |
| 50 |
}); |
| 51 |
|
| 52 |
const install_dir: std.Build.InstallDir = .{ .custom = "web" }; |
| 53 |
const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{ .optimize = optimize }); |
| 54 |
const emcc_settings = emsdk.emccDefaultSettings(b.allocator, .{ .optimize = optimize }); |
| 55 |
|
| 56 |
const emcc_step = emsdk.emccStep(b, raylib_artifact, wasm, .{ |
| 57 |
.optimize = optimize, |
| 58 |
.flags = emcc_flags, |
| 59 |
.settings = emcc_settings, |
| 60 |
.shell_file_path = emsdk.shell(raylib_dep), |
| 61 |
.install_dir = install_dir, |
| 62 |
}); |
| 63 |
b.getInstallStep().dependOn(emcc_step); |
| 64 |
|
| 65 |
const html_filename = try std.fmt.allocPrint(b.allocator, "{s}.html", .{wasm.name}); |
| 66 |
const emrun_step = emsdk.emrunStep( |
| 67 |
b, |
| 68 |
b.getInstallPath(install_dir, html_filename), |
| 69 |
&.{}, |
| 70 |
); |
| 71 |
|
| 72 |
emrun_step.dependOn(emcc_step); |
| 73 |
run_step.dependOn(emrun_step); |
| 74 |
} else { |
| 75 |
const exe = b.addExecutable(.{ |
| 76 |
.name = "core_basic_window", |
| 77 |
.root_module = exe_mod, |
| 78 |
.use_lld = target.result.os.tag == .windows, |
| 79 |
}); |
| 80 |
b.installArtifact(exe); |
| 81 |
|
| 82 |
const run_cmd = b.addRunArtifact(exe); |
| 83 |
run_cmd.step.dependOn(b.getInstallStep()); |
| 84 |
|
| 85 |
run_step.dependOn(&run_cmd.step); |
| 86 |
} |
| 87 |
} |