Update to Zig 0.12.0 and raylib 5.1-dev

This commit is contained in:
Not-Nik 2024-04-25 23:50:35 +02:00
parent 6eeb304ff3
commit 19f054bec5
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
5 changed files with 38 additions and 38 deletions

View File

@ -92,9 +92,9 @@ Now add the modules and artifact to your target as you would normally:
```zig
exe.linkLibrary(raylib_artifact);
exe.addModule("raylib", raylib);
exe.addModule("raylib-math", raylib_math);
exe.addModule("rlgl", rlgl);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raylib-math", raylib_math);
exe.root_module.addImport("rlgl", rlgl);
```
If you additionally want to support Web as a platform with emscripten, you will need `emcc.zig`. Refer to raylib-zig's project template on how to use it

View File

@ -13,12 +13,12 @@ const Program = struct {
fn link(
b: *std.Build,
exe: *std.Build.Step.Compile,
target: std.zig.CrossTarget,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
) void {
const lib = getRaylib(b, target, optimize);
const lib = getRaylib(b, target.query, optimize);
const target_os = exe.target.toTarget().os.tag;
const target_os = exe.rootModuleTarget().os.tag;
switch (target_os) {
.windows => {
exe.linkSystemLibrary("winmm");
@ -60,7 +60,7 @@ fn link(
exe.linkLibrary(lib);
}
var _raylib_lib_cache: ?*std.build.Step.Compile = null;
var _raylib_lib_cache: ?*std.Build.Step.Compile = null;
fn getRaylib(
b: *std.Build,
target: std.zig.CrossTarget,
@ -83,15 +83,15 @@ fn getModule(b: *std.Build) *std.Build.Module {
if (b.modules.contains("raylib")) {
return b.modules.get("raylib").?;
}
return b.addModule("raylib", .{ .source_file = .{ .path = "lib/raylib.zig" } });
return b.addModule("raylib", .{ .root_source_file = b.path("lib/raylib.zig")});
}
const math = struct {
fn getModule(b: *std.Build) *std.Build.Module {
const raylib = rl.getModule(b);
return b.addModule("raylib-math", .{
.source_file = .{ .path = "lib/raymath.zig" },
.dependencies = &.{.{ .name = "raylib-zig", .module = raylib }},
.root_source_file = b.path("lib/raymath.zig"),
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
});
}
};
@ -100,13 +100,13 @@ const gl = struct {
fn getModule(b: *std.Build) *std.Build.Module {
const raylib = rl.getModule(b);
return b.addModule("rlgl", .{
.source_file = .{ .path = "lib/rlgl.zig" },
.dependencies = &.{.{ .name = "raylib-zig", .module = raylib }},
.root_source_file = b.path("lib/rlgl.zig"),
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
});
}
};
fn build(b: *std.Build) !void {
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@ -190,24 +190,24 @@ fn build(b: *std.Build) !void {
const rlgl = rl.gl.getModule(b);
const raylib_test = b.addTest(.{
.root_source_file = .{ .path = "lib/raylib.zig" },
.root_source_file = b.path("lib/raylib.zig"),
.target = target,
.optimize = optimize,
});
const raylib_math_test = b.addTest(.{
.root_source_file = .{ .path = "lib/raymath.zig" },
.root_source_file = b.path("lib/raymath.zig"),
.target = target,
.optimize = optimize,
});
raylib_math_test.addModule("raylib-zig", raylib);
raylib_math_test.root_module.addImport("raylib-zig", raylib);
const rlgl_test = b.addTest(.{
.root_source_file = .{ .path = "lib/rlgl.zig" },
.root_source_file = b.path("lib/rlgl.zig"),
.target = target,
.optimize = optimize,
});
rlgl_test.addModule("raylib-zig", raylib);
rlgl_test.root_module.addImport("raylib-zig", raylib);
const test_step = b.step("test", "Check for library compilation errors");
test_step.dependOn(&raylib_test.step);
@ -215,12 +215,12 @@ fn build(b: *std.Build) !void {
test_step.dependOn(&rlgl_test.step);
for (examples) |ex| {
if (target.getOsTag() == .emscripten) {
if (target.query.os_tag == .emscripten) {
const exe_lib = emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
exe_lib.addModule("raylib", raylib);
exe_lib.addModule("raylib-math", raylib_math);
exe_lib.addModule("rlgl", rlgl);
const raylib_lib = getRaylib(b, target, optimize);
exe_lib.root_module.addImport("raylib", raylib);
exe_lib.root_module.addImport("raylib-math", raylib_math);
exe_lib.root_module.addImport("rlgl", rlgl);
const raylib_lib = getRaylib(b, target.query, optimize);
// Note that raylib itself isn't actually added to the exe_lib
// output file, so it also needs to be linked with emscripten.
@ -241,9 +241,9 @@ fn build(b: *std.Build) !void {
.target = target,
});
rl.link(b, exe, target, optimize);
exe.addModule("raylib", raylib);
exe.addModule("raylib-math", raylib_math);
exe.addModule("rlgl", rlgl);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raylib-math", raylib_math);
exe.root_module.addImport("rlgl", rlgl);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step(ex.name, ex.desc);
run_step.dependOn(&run_cmd.step);

View File

@ -1,12 +1,12 @@
.{
.name = "raylib-zig",
.version = "5.0.0",
.version = "5.1.0",
.dependencies = .{
.raylib = .{
.url = "https://github.com/raysan5/raylib/archive/5.0.tar.gz",
.hash = "1220c28847ca8e8756734ae84355802b764c9d9cf4de057dbc6fc2b15c56e726f27b",
.url = "https://github.com/raysan5/raylib/archive/e47ebec66134800e734710038ea4e5f070f3ef06.tar.gz",
.hash = "12208edb6d35c0aa5f57262014b02392c6ccfd0685a8eff1d961b42a612d3418fa89",
},
},
.minimum_zig_version = "0.11.0",
.minimum_zig_version = "0.12.0",
.paths = .{ "lib/raylib.zig", "lib/raylib-ext.zig", "lib/raymath.zig", "lib/raymath-ext.zig", "lib/rlgl.zig", "lib/rlgl-ext.zig" },
}

View File

@ -29,7 +29,7 @@ pub fn compileForEmscripten(
b: *std.Build,
name: []const u8,
root_source_file: []const u8,
target: std.zig.CrossTarget,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
) *std.Build.Step.Compile {
// TODO: It might be a good idea to create a custom compile step, that does
@ -37,13 +37,13 @@ pub fn compileForEmscripten(
// the make function of the step. However it might also be a bad idea since
// it messes with the build system itself.
const new_target = updateTargetForWeb(target);
//const new_target = updateTargetForWeb(target);
// The project is built as a library and linked later.
const exe_lib = b.addStaticLibrary(.{
.name = name,
.root_source_file = .{ .path = root_source_file },
.target = new_target,
.target = target,
.optimize = optimize,
});

View File

@ -26,12 +26,12 @@ pub fn build(b: *std.Build) !void {
const raylib_artifact = raylib_dep.artifact("raylib");
//web exports are completely separate
if (target.getOsTag() == .emscripten) {
if (target.query.os_tag == .emscripten) {
const exe_lib = emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize);
exe_lib.linkLibrary(raylib_artifact);
exe_lib.addModule("raylib", raylib);
exe_lib.addModule("raylib-math", raylib_math);
exe_lib.root_module.addImport("raylib", raylib);
exe_lib.root_module.addImport("raylib-math", raylib_math);
// Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten.
const link_step = try emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact });
@ -47,8 +47,8 @@ pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{ .name = "'$PROJECT_NAME'", .root_source_file = .{ .path = "src/main.zig" }, .optimize = optimize, .target = target });
exe.linkLibrary(raylib_artifact);
exe.addModule("raylib", raylib);
exe.addModule("raylib-math", raylib_math);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raylib-math", raylib_math);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run '$PROJECT_NAME'");