mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	fix build paths (#3835)
This commit is contained in:
		| @@ -1,12 +1,16 @@ | |||||||
| const std = @import("std"); | const std = @import("std"); | ||||||
| const builtin = @import("builtin"); | const builtin = @import("builtin"); | ||||||
|  |  | ||||||
| // This has been tested to work with zig 0.11.0 and zig 0.12.0-dev.2075+f5978181e | // This has been tested to work with zig 0.11.0, zig 0.12.0-dev.2075+f5978181e and 0.12.0-dev.2990+31763d28c | ||||||
| // | // | ||||||
| // anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type | // anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type | ||||||
| // was reworked into std.Target.Query and std.Build.ResolvedTarget. Using anytype allows | // was reworked into std.Target.Query and std.Build.ResolvedTarget. Using anytype allows | ||||||
| // us to accept both CrossTarget and ResolvedTarget and act accordingly in getOsTagVersioned. | // us to accept both CrossTarget and ResolvedTarget and act accordingly in getOsTagVersioned. | ||||||
| pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile { | pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile { | ||||||
|  |     var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; | ||||||
|  |     const gpa = general_purpose_allocator.allocator(); | ||||||
|  |     // get the relative source path, because it is needed for addCSourceFilesVersioned | ||||||
|  |     const relative = srcdir[b.build_root.path.?.len..]; | ||||||
|     if (comptime builtin.zig_version.minor >= 12 and @TypeOf(target) != std.Build.ResolvedTarget) { |     if (comptime builtin.zig_version.minor >= 12 and @TypeOf(target) != std.Build.ResolvedTarget) { | ||||||
|         @compileError("Expected 'std.Build.ResolvedTarget' for argument 2 'target' in 'addRaylib', found '" ++ @typeName(@TypeOf(target)) ++ "'"); |         @compileError("Expected 'std.Build.ResolvedTarget' for argument 2 'target' in 'addRaylib', found '" ++ @typeName(@TypeOf(target)) ++ "'"); | ||||||
|     } else if (comptime builtin.zig_version.minor == 11 and @TypeOf(target) != std.zig.CrossTarget) { |     } else if (comptime builtin.zig_version.minor == 11 and @TypeOf(target) != std.zig.CrossTarget) { | ||||||
| @@ -45,37 +49,37 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM | |||||||
|  |  | ||||||
|     // No GLFW required on PLATFORM_DRM |     // No GLFW required on PLATFORM_DRM | ||||||
|     if (!options.platform_drm) { |     if (!options.platform_drm) { | ||||||
|         raylib.addIncludePath(.{ .path = srcdir ++ "/external/glfw/include" }); |         raylib.addIncludePath(.{ .cwd_relative = srcdir ++ "/external/glfw/include" }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     addCSourceFilesVersioned(raylib, &.{ |     addCSourceFilesVersioned(raylib, &.{ | ||||||
|         srcdir ++ "/rcore.c", |         try join2(gpa, relative, "rcore.c"), | ||||||
|         srcdir ++ "/utils.c", |         try join2(gpa, relative, "utils.c"), | ||||||
|     }, raylib_flags_arr.items); |     }, raylib_flags_arr.items); | ||||||
|  |  | ||||||
|     if (options.raudio) { |     if (options.raudio) { | ||||||
|         addCSourceFilesVersioned(raylib, &.{ |         addCSourceFilesVersioned(raylib, &.{ | ||||||
|             srcdir ++ "/raudio.c", |             try join2(gpa, relative, "raudio.c"), | ||||||
|         }, raylib_flags_arr.items); |         }, raylib_flags_arr.items); | ||||||
|     } |     } | ||||||
|     if (options.rmodels) { |     if (options.rmodels) { | ||||||
|         addCSourceFilesVersioned(raylib, &.{ |         addCSourceFilesVersioned(raylib, &.{ | ||||||
|             srcdir ++ "/rmodels.c", |             try join2(gpa, relative, "rmodels.c"), | ||||||
|         }, raylib_flags_arr.items); |         }, raylib_flags_arr.items); | ||||||
|     } |     } | ||||||
|     if (options.rshapes) { |     if (options.rshapes) { | ||||||
|         addCSourceFilesVersioned(raylib, &.{ |         addCSourceFilesVersioned(raylib, &.{ | ||||||
|             srcdir ++ "/rshapes.c", |             try join2(gpa, relative, "rshapes.c"), | ||||||
|         }, raylib_flags_arr.items); |         }, raylib_flags_arr.items); | ||||||
|     } |     } | ||||||
|     if (options.rtext) { |     if (options.rtext) { | ||||||
|         addCSourceFilesVersioned(raylib, &.{ |         addCSourceFilesVersioned(raylib, &.{ | ||||||
|             srcdir ++ "/rtext.c", |             try join2(gpa, relative, "rtext.c"), | ||||||
|         }, raylib_flags_arr.items); |         }, raylib_flags_arr.items); | ||||||
|     } |     } | ||||||
|     if (options.rtextures) { |     if (options.rtextures) { | ||||||
|         addCSourceFilesVersioned(raylib, &.{ |         addCSourceFilesVersioned(raylib, &.{ | ||||||
|             srcdir ++ "/rtextures.c", |             try join2(gpa, relative, "rtextures.c"), | ||||||
|         }, raylib_flags_arr.items); |         }, raylib_flags_arr.items); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -85,14 +89,14 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM | |||||||
|     if (options.raygui) { |     if (options.raygui) { | ||||||
|         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"); | ||||||
|         raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items }); |         raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items }); | ||||||
|         raylib.addIncludePath(.{ .path = srcdir }); |         raylib.addIncludePath(.{ .cwd_relative = srcdir }); | ||||||
|         raylib.addIncludePath(.{ .path = srcdir ++ "/../../raygui/src" }); |         raylib.addIncludePath(.{ .cwd_relative = srcdir ++ "/../../raygui/src" }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     switch (getOsTagVersioned(target)) { |     switch (getOsTagVersioned(target)) { | ||||||
|         .windows => { |         .windows => { | ||||||
|             addCSourceFilesVersioned(raylib, &.{ |             addCSourceFilesVersioned(raylib, &.{ | ||||||
|                 srcdir ++ "/rglfw.c", |                 try join2(gpa, relative, "rglfw.c"), | ||||||
|             }, raylib_flags_arr.items); |             }, raylib_flags_arr.items); | ||||||
|             raylib.linkSystemLibrary("winmm"); |             raylib.linkSystemLibrary("winmm"); | ||||||
|             raylib.linkSystemLibrary("gdi32"); |             raylib.linkSystemLibrary("gdi32"); | ||||||
| @@ -103,7 +107,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM | |||||||
|         .linux => { |         .linux => { | ||||||
|             if (!options.platform_drm) { |             if (!options.platform_drm) { | ||||||
|                 addCSourceFilesVersioned(raylib, &.{ |                 addCSourceFilesVersioned(raylib, &.{ | ||||||
|                     srcdir ++ "/rglfw.c", |                     try join2(gpa, relative, "rglfw.c"), | ||||||
|                 }, raylib_flags_arr.items); |                 }, raylib_flags_arr.items); | ||||||
|                 raylib.linkSystemLibrary("GL"); |                 raylib.linkSystemLibrary("GL"); | ||||||
|                 raylib.linkSystemLibrary("rt"); |                 raylib.linkSystemLibrary("rt"); | ||||||
| @@ -133,7 +137,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM | |||||||
|         }, |         }, | ||||||
|         .freebsd, .openbsd, .netbsd, .dragonfly => { |         .freebsd, .openbsd, .netbsd, .dragonfly => { | ||||||
|             addCSourceFilesVersioned(raylib, &.{ |             addCSourceFilesVersioned(raylib, &.{ | ||||||
|                 srcdir ++ "/rglfw.c", |                 try join2(gpa, relative, "rglfw.c"), | ||||||
|             }, raylib_flags_arr.items); |             }, raylib_flags_arr.items); | ||||||
|             raylib.linkSystemLibrary("GL"); |             raylib.linkSystemLibrary("GL"); | ||||||
|             raylib.linkSystemLibrary("rt"); |             raylib.linkSystemLibrary("rt"); | ||||||
| @@ -152,7 +156,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM | |||||||
|             // On macos rglfw.c include Objective-C files. |             // On macos rglfw.c include Objective-C files. | ||||||
|             try raylib_flags_arr.append("-ObjC"); |             try raylib_flags_arr.append("-ObjC"); | ||||||
|             addCSourceFilesVersioned(raylib, &.{ |             addCSourceFilesVersioned(raylib, &.{ | ||||||
|                 srcdir ++ "/rglfw.c", |                 try join2(gpa, relative, "rglfw.c"), | ||||||
|             }, raylib_flags_arr.items); |             }, raylib_flags_arr.items); | ||||||
|             raylib.linkFramework("Foundation"); |             raylib.linkFramework("Foundation"); | ||||||
|             raylib.linkFramework("CoreServices"); |             raylib.linkFramework("CoreServices"); | ||||||
| @@ -257,3 +261,8 @@ fn addCSourceFilesVersioned(exe: *std.Build.Step.Compile, files: []const []const | |||||||
|         exe.addCSourceFiles(files, flags); |         exe.addCSourceFiles(files, flags); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | fn join2(allocator: std.mem.Allocator, path1: []const u8, path2: []const u8) ![]u8 { | ||||||
|  |     const joinedPath = try std.fs.path.join(allocator, &[_][]const u8{ path1, path2 }); | ||||||
|  |     return joinedPath; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Steve Biedermann
					Steve Biedermann