mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Fixing linker error for raygui when building in shared mode. (#197)
This commit is contained in:
parent
1ef4995f82
commit
58724227e7
32
build.zig
32
build.zig
@ -49,8 +49,8 @@ fn link(
|
|||||||
target: std.Build.ResolvedTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
options: Options,
|
options: Options,
|
||||||
) void {
|
) !void {
|
||||||
const lib = getRaylib(b, target, optimize, options);
|
const lib = try getRaylib(b, target, optimize, options);
|
||||||
|
|
||||||
const target_os = exe.rootModuleTarget().os.tag;
|
const target_os = exe.rootModuleTarget().os.tag;
|
||||||
switch (target_os) {
|
switch (target_os) {
|
||||||
@ -95,7 +95,7 @@ fn link(
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.Step.Compile {
|
fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
|
||||||
if (_raylib_lib_cache) |lib| return lib else {
|
if (_raylib_lib_cache) |lib| return lib else {
|
||||||
const raylib = b.dependency("raylib", .{
|
const raylib = b.dependency("raylib", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -122,15 +122,29 @@ fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil
|
|||||||
lib.step.dependOn(&gen_step.step);
|
lib.step.dependOn(&gen_step.step);
|
||||||
|
|
||||||
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
|
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
|
||||||
lib.addCSourceFile(.{
|
|
||||||
.file = raygui_c_path,
|
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
|
||||||
.flags = &[_][]const u8{
|
defer raylib_flags_arr.deinit();
|
||||||
|
|
||||||
|
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
||||||
"-std=gnu99",
|
"-std=gnu99",
|
||||||
"-D_GNU_SOURCE",
|
"-D_GNU_SOURCE",
|
||||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.shared) {
|
||||||
|
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
||||||
|
"-fPIC",
|
||||||
|
"-DBUILD_LIBTYPE_SHARED",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
lib.addCSourceFile(.{
|
||||||
|
.file = raygui_c_path,
|
||||||
|
.flags = raylib_flags_arr.items,
|
||||||
|
});
|
||||||
|
|
||||||
lib.addIncludePath(raylib.path("src"));
|
lib.addIncludePath(raylib.path("src"));
|
||||||
lib.addIncludePath(raygui_dep.path("src"));
|
lib.addIncludePath(raygui_dep.path("src"));
|
||||||
|
|
||||||
@ -375,7 +389,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const exe_lib = try emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
|
const exe_lib = try emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
|
||||||
exe_lib.root_module.addImport("raylib", raylib);
|
exe_lib.root_module.addImport("raylib", raylib);
|
||||||
exe_lib.root_module.addImport("raygui", raygui);
|
exe_lib.root_module.addImport("raygui", raygui);
|
||||||
const raylib_lib = getRaylib(b, target, optimize, options);
|
const raylib_lib = try getRaylib(b, target, optimize, options);
|
||||||
|
|
||||||
// Note that raylib itself isn't actually added to the exe_lib
|
// Note that raylib itself isn't actually added to the exe_lib
|
||||||
// output file, so it also needs to be linked with emscripten.
|
// output file, so it also needs to be linked with emscripten.
|
||||||
@ -397,7 +411,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.target = target,
|
.target = target,
|
||||||
});
|
});
|
||||||
this.link(b, exe, target, optimize, options);
|
try this.link(b, exe, target, optimize, options);
|
||||||
exe.root_module.addImport("raylib", raylib);
|
exe.root_module.addImport("raylib", raylib);
|
||||||
exe.root_module.addImport("raygui", raygui);
|
exe.root_module.addImport("raygui", raygui);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user