mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
prepare build to run on zig 15 (#264)
* prepare build to run on zig 15 * set raylib as static for web
This commit is contained in:
parent
e8167c2e56
commit
ac0b07c4bd
16
build.zig
16
build.zig
@ -51,7 +51,7 @@ fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil
|
|||||||
if (b.modules.contains("raylib")) {
|
if (b.modules.contains("raylib")) {
|
||||||
return b.modules.get("raylib").?;
|
return b.modules.get("raylib").?;
|
||||||
}
|
}
|
||||||
return b.addModule("raylib", .{
|
return b.createModule(.{
|
||||||
.root_source_file = b.path("lib/raylib.zig"),
|
.root_source_file = b.path("lib/raylib.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
@ -61,7 +61,7 @@ fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil
|
|||||||
const gui = struct {
|
const gui = struct {
|
||||||
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
|
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
|
||||||
const raylib = this.getModule(b, target, optimize);
|
const raylib = this.getModule(b, target, optimize);
|
||||||
return b.addModule("raygui", .{
|
return b.createModule(.{
|
||||||
.root_source_file = b.path("lib/raygui.zig"),
|
.root_source_file = b.path("lib/raygui.zig"),
|
||||||
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
|
.imports = &.{.{ .name = "raylib-zig", .module = raylib }},
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -293,16 +293,12 @@ pub fn build(b: *std.Build) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const raylib_test = b.addTest(.{
|
const raylib_test = b.addTest(.{
|
||||||
.root_source_file = b.path("lib/raylib.zig"),
|
.root_module = raylib,
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
});
|
||||||
raylib_test.linkLibC();
|
raylib_test.linkLibC();
|
||||||
|
|
||||||
const raygui_test = b.addTest(.{
|
const raygui_test = b.addTest(.{
|
||||||
.root_source_file = b.path("lib/raygui.zig"),
|
.root_module = raygui,
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
});
|
||||||
raygui_test.root_module.addImport("raylib-zig", raylib);
|
raygui_test.root_module.addImport("raylib-zig", raylib);
|
||||||
raygui_test.linkLibC();
|
raygui_test.linkLibC();
|
||||||
@ -336,9 +332,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
} else {
|
} else {
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = ex.name,
|
.name = ex.name,
|
||||||
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path(ex.path),
|
.root_source_file = b.path(ex.path),
|
||||||
.optimize = optimize,
|
|
||||||
.target = target,
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
exe.linkLibrary(raylib_artifact);
|
exe.linkLibrary(raylib_artifact);
|
||||||
exe.root_module.addImport("raylib", raylib);
|
exe.root_module.addImport("raylib", raylib);
|
||||||
|
25
emcc.zig
25
emcc.zig
@ -15,17 +15,9 @@ pub fn emscriptenRunStep(b: *std.Build) !*std.Build.Step.Run {
|
|||||||
defer b.allocator.free(emrun_run_arg);
|
defer b.allocator.free(emrun_run_arg);
|
||||||
|
|
||||||
if (b.sysroot == null) {
|
if (b.sysroot == null) {
|
||||||
emrun_run_arg = try std.fmt.bufPrint(
|
emrun_run_arg = try std.fmt.bufPrint(emrun_run_arg, "{s}", .{emrunExe});
|
||||||
emrun_run_arg,
|
|
||||||
"{s}",
|
|
||||||
.{ emrunExe }
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
emrun_run_arg = try std.fmt.bufPrint(
|
emrun_run_arg = try std.fmt.bufPrint(emrun_run_arg, "{s}" ++ std.fs.path.sep_str ++ "{s}", .{ b.sysroot.?, emrunExe });
|
||||||
emrun_run_arg,
|
|
||||||
"{s}" ++ std.fs.path.sep_str ++ "{s}",
|
|
||||||
.{ b.sysroot.?, emrunExe }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const run_cmd = b.addSystemCommand(&[_][]const u8{ emrun_run_arg, emccOutputDir ++ emccOutputFile });
|
const run_cmd = b.addSystemCommand(&[_][]const u8{ emrun_run_arg, emccOutputDir ++ emccOutputFile });
|
||||||
@ -38,7 +30,7 @@ pub fn compileForEmscripten(
|
|||||||
name: []const u8,
|
name: []const u8,
|
||||||
root_source_file: []const u8,
|
root_source_file: []const u8,
|
||||||
target: std.Build.ResolvedTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.Mode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
) !*std.Build.Step.Compile {
|
) !*std.Build.Step.Compile {
|
||||||
// TODO: It might be a good idea to create a custom compile step, that does
|
// TODO: It might be a good idea to create a custom compile step, that does
|
||||||
// both the compile to static library and the link with emcc by overidding
|
// both the compile to static library and the link with emcc by overidding
|
||||||
@ -46,11 +38,14 @@ pub fn compileForEmscripten(
|
|||||||
// it messes with the build system itself.
|
// it messes with the build system itself.
|
||||||
|
|
||||||
// The project is built as a library and linked later.
|
// The project is built as a library and linked later.
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addLibrary(.{
|
||||||
.name = name,
|
.name = name,
|
||||||
|
.linkage = .static,
|
||||||
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path(root_source_file),
|
.root_source_file = b.path(root_source_file),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const emscripten_headers = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" });
|
const emscripten_headers = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" });
|
||||||
@ -83,11 +78,7 @@ pub fn linkWithEmscripten(
|
|||||||
defer b.allocator.free(emcc_run_arg);
|
defer b.allocator.free(emcc_run_arg);
|
||||||
|
|
||||||
if (b.sysroot == null) {
|
if (b.sysroot == null) {
|
||||||
emcc_run_arg = try std.fmt.bufPrint(
|
emcc_run_arg = try std.fmt.bufPrint(emcc_run_arg, "{s}", .{emccExe});
|
||||||
emcc_run_arg,
|
|
||||||
"{s}",
|
|
||||||
.{ emccExe }
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
emcc_run_arg = try std.fmt.bufPrint(
|
emcc_run_arg = try std.fmt.bufPrint(
|
||||||
emcc_run_arg,
|
emcc_run_arg,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user