@@ -118,7 +118,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
118118 }
119119
120120 if (options .linkage == .dynamic ) {
121- try raylib_flags_arr . append ( "-fPIC" ) ;
121+ raylib_mod . pic = true ;
122122 raylib_mod .addCMacro ("BUILD_LIBTYPE_SHARED" , "" );
123123 }
124124
@@ -160,6 +160,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
160160 switch (options .platform ) {
161161 .glfw = > {
162162 var opengl_version : OpenglVersion = options .opengl_version ;
163+ if (opengl_version == .gl_soft ) {
164+ @panic ("The opengl version is not supported by this platform" );
165+ }
166+
163167 raylib_mod .addIncludePath (b .path ("src/external/glfw/include" ));
164168
165169 if (target .result .os .tag != .emscripten ) {
@@ -181,17 +185,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
181185 @panic ("Target is not supported with this platform" );
182186 }
183187
188+ raylib_mod .linkSystemLibrary ("GL" , .{});
189+
184190 if (options .linux_display_backend == .X11 or options .linux_display_backend == .Both ) {
185191 raylib_mod .addCMacro ("_GLFW_X11" , "" );
186- raylib_mod .linkSystemLibrary ("GLX" , .{});
187192 raylib_mod .linkSystemLibrary ("X11" , .{});
188- raylib_mod .linkSystemLibrary ("Xcursor" , .{});
189- raylib_mod .linkSystemLibrary ("Xext" , .{});
190- raylib_mod .linkSystemLibrary ("Xfixes" , .{});
191- raylib_mod .linkSystemLibrary ("Xi" , .{});
192- raylib_mod .linkSystemLibrary ("Xinerama" , .{});
193- raylib_mod .linkSystemLibrary ("Xrandr" , .{});
194- raylib_mod .linkSystemLibrary ("Xrender" , .{});
195193 }
196194
197195 if (options .linux_display_backend == .Wayland or options .linux_display_backend == .Both ) {
@@ -212,15 +210,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
212210 },
213211 .freebsd , .openbsd , .netbsd , .dragonfly = > {
214212 raylib_mod .linkSystemLibrary ("GL" , .{});
215- raylib_mod .linkSystemLibrary ("rt" , .{});
216- raylib_mod .linkSystemLibrary ("dl" , .{});
217- raylib_mod .linkSystemLibrary ("m" , .{});
218- raylib_mod .linkSystemLibrary ("X11" , .{});
219- raylib_mod .linkSystemLibrary ("Xrandr" , .{});
220- raylib_mod .linkSystemLibrary ("Xinerama" , .{});
221- raylib_mod .linkSystemLibrary ("Xi" , .{});
222- raylib_mod .linkSystemLibrary ("Xxf86vm" , .{});
223- raylib_mod .linkSystemLibrary ("Xcursor" , .{});
213+
214+ raylib_mod .addSystemIncludePath (b .path ("/usr/local/include/" ));
215+ raylib_mod .addSystemIncludePath (b .path ("/usr/pkg/include" ));
216+ raylib_mod .addSystemIncludePath (b .path ("/usr/X11R7/include" ));
217+ raylib_mod .addRPath (b .path ("/usr/pkg/lib" ));
224218 },
225219 .macos = > {
226220 // On macos rglfw.c include Objective-C files.
@@ -278,18 +272,21 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
278272 raylib_mod .linkSystemLibrary ("opengl32" , .{});
279273 },
280274 .linux = > {
275+ if (target .result .abi .isAndroid ()) {
276+ @panic ("Target is not supported with this platform" );
277+ }
278+
279+ raylib_mod .linkSystemLibrary ("GL" , .{});
280+
281281 if (options .linux_display_backend == .X11 or options .linux_display_backend == .Both ) {
282282 raylib_mod .addCMacro ("RGFW_X11" , "" );
283283 raylib_mod .addCMacro ("RGFW_UNIX" , "" );
284284
285- raylib_mod .linkSystemLibrary ("GL" , .{});
286285 raylib_mod .linkSystemLibrary ("X11" , .{});
287286 raylib_mod .linkSystemLibrary ("Xrandr" , .{});
287+ raylib_mod .linkSystemLibrary ("Xinerama" , .{});
288288 raylib_mod .linkSystemLibrary ("Xi" , .{});
289289 raylib_mod .linkSystemLibrary ("Xcursor" , .{});
290- raylib_mod .linkSystemLibrary ("pthread" , .{});
291- raylib_mod .linkSystemLibrary ("dl" , .{});
292- raylib_mod .linkSystemLibrary ("rt" , .{});
293290 }
294291
295292 if (options .linux_display_backend == .Wayland or options .linux_display_backend == .Both ) {
@@ -313,6 +310,14 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
313310 try waylandGenerate (b , raylib , "src/external/RGFW/deps/wayland/" , true );
314311 }
315312 },
313+ .freebsd , .openbsd , .netbsd , .dragonfly = > {
314+ raylib_mod .linkSystemLibrary ("GL" , .{});
315+
316+ raylib_mod .addSystemIncludePath (b .path ("/usr/local/include/" ));
317+ raylib_mod .addSystemIncludePath (b .path ("/usr/pkg/include" ));
318+ raylib_mod .addSystemIncludePath (b .path ("/usr/X11R7/include" ));
319+ raylib_mod .addRPath (b .path ("/usr/pkg/lib" ));
320+ },
316321 .macos = > {
317322 // Include xcode_frameworks for cross compilation
318323 if (b .lazyDependency ("xcode_frameworks" , .{})) | dep | {
@@ -350,18 +355,18 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
350355 raylib_mod .addCMacro (options .opengl_version .toCMacroStr (), "" );
351356 }
352357
358+ raylib_mod .addCMacro ("PLATFORM_DESKTOP_SDL" , "" );
359+
353360 if (options .platform == .sdl2 ) {
354361 raylib_mod .addCMacro ("USING_SDL2_PACKAGE" , "" );
355362 }
356363 if (options .platform == .sdl3 ) {
357364 raylib_mod .addCMacro ("USING_SDL3_PACKAGE" , "" );
358365 }
359-
360- raylib_mod .addCMacro ("PLATFORM_DESKTOP_SDL" , "" );
361366 },
362367 .memory = > {
363368 if (options .opengl_version != .auto and options .opengl_version != .gl_soft ) {
364- @panic ("opengl version not supported" );
369+ @panic ("The opengl version is not supported by this platform " );
365370 }
366371 raylib_mod .addCMacro (OpenglVersion .gl_soft .toCMacroStr (), "" );
367372 raylib_mod .addCMacro ("PLATFORM_MEMORY" , "" );
@@ -397,12 +402,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
397402
398403 try raylib_flags_arr .append ("-Werror=implicit-function-declaration" );
399404
405+ raylib_mod .addSystemIncludePath (b .path ("/usr/include/libdrm" ));
406+
400407 raylib_mod .linkSystemLibrary ("libdrm" , .{ .use_pkg_config = .force });
401408 raylib_mod .linkSystemLibrary ("drm" , .{});
402409 raylib_mod .linkSystemLibrary ("gbm" , .{});
403- raylib_mod .linkSystemLibrary ("pthread" , .{});
404- raylib_mod .linkSystemLibrary ("rt" , .{});
405- raylib_mod .linkSystemLibrary ("dl" , .{});
406410
407411 switch (options .opengl_version ) {
408412 .auto , .gles_2 = > {
@@ -411,7 +415,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
411415 raylib_mod .linkSystemLibrary ("EGL" , .{});
412416 },
413417 .gl_soft = > {},
414- else = > @panic ("opengl version not supported" ),
418+ else = > @panic ("The opengl version is not supported by this platform " ),
415419 }
416420 },
417421 .android = > {
@@ -422,9 +426,12 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
422426 raylib_mod .addCMacro ("PLATFORM_ANDROID" , "" );
423427
424428 raylib_mod .linkSystemLibrary ("EGL" , .{});
425- if (options .opengl_version == .auto or options .opengl_version == .gles_2 ) {
426- raylib_mod .addCMacro (OpenglVersion .gles_2 .toCMacroStr (), "" );
427- raylib_mod .linkSystemLibrary ("GLESv2" , .{});
429+ switch (options .opengl_version ) {
430+ .auto , .gles_2 = > {
431+ raylib_mod .addCMacro (OpenglVersion .gles_2 .toCMacroStr (), "" );
432+ raylib_mod .linkSystemLibrary ("GLESv2" , .{});
433+ },
434+ else = > @panic ("The opengl version is not supported by this platform" ),
428435 }
429436
430437 //these are the only tag options per https://developer.android.com/ndk/guides/other_build_systems
@@ -637,14 +644,14 @@ pub fn build(b: *std.Build) !void {
637644 }
638645
639646 const examples = b .step ("examples" , "build/install all examples" );
640- examples .dependOn (try addExamples ("core" , b , target , optimize , lib ));
641- examples .dependOn (try addExamples ("audio" , b , target , optimize , lib ));
642- examples .dependOn (try addExamples ("models" , b , target , optimize , lib ));
643- examples .dependOn (try addExamples ("others " , b , target , optimize , lib ));
644- examples .dependOn (try addExamples ("shaders " , b , target , optimize , lib ));
645- examples .dependOn (try addExamples ("shapes " , b , target , optimize , lib ));
646- examples .dependOn (try addExamples ("text " , b , target , optimize , lib ));
647- examples .dependOn (try addExamples ("textures " , b , target , optimize , lib ));
647+ examples .dependOn (try addExamples ("core" , b , target , optimize , lib , options . platform ));
648+ examples .dependOn (try addExamples ("audio" , b , target , optimize , lib , options . platform ));
649+ examples .dependOn (try addExamples ("models" , b , target , optimize , lib , options . platform ));
650+ examples .dependOn (try addExamples ("shaders " , b , target , optimize , lib , options . platform ));
651+ examples .dependOn (try addExamples ("shapes " , b , target , optimize , lib , options . platform ));
652+ examples .dependOn (try addExamples ("text " , b , target , optimize , lib , options . platform ));
653+ examples .dependOn (try addExamples ("textures " , b , target , optimize , lib , options . platform ));
654+ examples .dependOn (try addExamples ("others " , b , target , optimize , lib , options . platform ));
648655}
649656
650657fn addExamples (
@@ -653,13 +660,25 @@ fn addExamples(
653660 target : std.Build.ResolvedTarget ,
654661 optimize : std.builtin.OptimizeMode ,
655662 raylib : * std.Build.Step.Compile ,
663+ platform : PlatformBackend ,
656664) ! * std.Build.Step {
657665 const all = b .step (module , "All " ++ module ++ " examples" );
658666 const module_subpath = b .pathJoin (&.{ "examples" , module });
659667
660668 var dir = try b .build_root .handle .openDir (b .graph .io , module_subpath , .{ .iterate = true });
661669 defer dir .close (b .graph .io );
662670
671+ if (platform == .sdl ) {
672+ raylib .root_module .linkSystemLibrary ("SDL2" , .{});
673+ raylib .root_module .linkSystemLibrary ("SDL3" , .{});
674+ }
675+ if (platform == .sdl2 ) {
676+ raylib .root_module .linkSystemLibrary ("SDL2" , .{});
677+ }
678+ if (platform == .sdl3 ) {
679+ raylib .root_module .linkSystemLibrary ("SDL3" , .{});
680+ }
681+
663682 var iter = dir .iterate ();
664683 while (try iter .next (b .graph .io )) | entry | {
665684 if (entry .kind != .file ) continue ;
@@ -668,114 +687,68 @@ fn addExamples(
668687 if (! std .mem .eql (u8 , filetype , ".c" )) continue ;
669688
670689 const filename = std .fs .path .stem (entry .name );
671-
672690 const path = b .pathJoin (&.{ module_subpath , entry .name });
673691
674- // zig's mingw headers do not include pthread.h
675- if (std .mem .eql (u8 , "core_loading_thread" , filename ) and target .result .os .tag == .windows ) continue ;
676-
677692 const exe_mod = b .createModule (.{
678693 .target = target ,
679694 .optimize = optimize ,
695+ .link_libc = true ,
680696 });
681- exe_mod .addCSourceFile (.{ .file = b .path (path ), . flags = &.{} });
697+ exe_mod .addCSourceFile (.{ .file = b .path (path ) });
682698 exe_mod .linkLibrary (raylib );
683699
700+ if (std .mem .eql (u8 , filename , "rlgl_standalone" )) {
701+ if (platform != .glfw ) continue ;
702+ exe_mod .addIncludePath (b .path ("src" ));
703+ exe_mod .addIncludePath (b .path ("src/external/glfw/include" ));
704+ }
705+ if (std .mem .eql (u8 , filename , "raylib_opengl_interop" )) {
706+ exe_mod .addIncludePath (b .path ("src/external" ));
707+ }
708+
684709 const run_step = b .step (filename , filename );
685710
686- if (target .result .os .tag == .emscripten ) {
711+ // web exports are completely separate
712+ if (target .query .os_tag == .emscripten ) {
713+ exe_mod .addCMacro ("PLATFORM_WEB" , "" );
714+
687715 const wasm = b .addLibrary (.{
688716 .name = filename ,
689- .linkage = .static ,
690717 .root_module = exe_mod ,
691718 });
692719
693- if (std .mem .eql (u8 , filename , "rlgl_standalone" )) {
694- exe_mod .addIncludePath (b .path ("src" ));
695- exe_mod .addIncludePath (b .path ("src/external/glfw/include" ));
696- }
697- if (std .mem .eql (u8 , filename , "raylib_opengl_interop" )) {
698- exe_mod .addIncludePath (b .path ("src/external" ));
699- }
700-
720+ const install_dir : std.Build.InstallDir = .{ .custom = "web" };
701721 const emcc_flags = emsdk .emccDefaultFlags (b .allocator , .{ .optimize = optimize });
702722 const emcc_settings = emsdk .emccDefaultSettings (b .allocator , .{ .optimize = optimize });
703723
704- const install_dir : std.Build.InstallDir = .{ .custom = "htmlout" };
705724 const emcc_step = emsdk .emccStep (b , raylib , wasm , .{
706725 .optimize = optimize ,
707726 .flags = emcc_flags ,
708727 .settings = emcc_settings ,
709728 .shell_file_path = b .path ("src/shell.html" ),
710- .embed_paths = &.{
711- .{
712- .src_path = b .pathJoin (&.{ module_subpath , "resources" }),
713- .virtual_path = "resources" ,
714- },
715- },
716729 .install_dir = install_dir ,
717730 });
731+ b .getInstallStep ().dependOn (emcc_step );
718732
719733 const html_filename = try std .fmt .allocPrint (b .allocator , "{s}.html" , .{wasm .name });
720734 const emrun_step = emsdk .emrunStep (
721735 b ,
722736 b .getInstallPath (install_dir , html_filename ),
723- &.{"--no_browser" },
737+ &.{},
724738 );
725- emrun_step .dependOn (emcc_step );
726739
740+ emrun_step .dependOn (emcc_step );
727741 run_step .dependOn (emrun_step );
728742 all .dependOn (emcc_step );
729743 } else {
730- // special examples that test using these external dependencies directly
731- // alongside raylib
732- if (std .mem .eql (u8 , filename , "rlgl_standalone" )) {
733- exe_mod .addIncludePath (b .path ("src" ));
734- exe_mod .addIncludePath (b .path ("src/external/glfw/include" ));
735- if (! hasCSource (raylib .root_module , "rglfw.c" )) {
736- exe_mod .addCSourceFile (.{ .file = b .path ("src/rglfw.c" ), .flags = &.{} });
737- }
738- }
739- if (std .mem .eql (u8 , filename , "raylib_opengl_interop" )) {
740- exe_mod .addIncludePath (b .path ("src/external" ));
741- }
742-
743- switch (target .result .os .tag ) {
744- .windows = > {
745- exe_mod .linkSystemLibrary ("winmm" , .{});
746- exe_mod .linkSystemLibrary ("gdi32" , .{});
747- exe_mod .linkSystemLibrary ("opengl32" , .{});
748-
749- exe_mod .addCMacro ("PLATFORM_DESKTOP" , "" );
750- },
751- .linux = > {
752- exe_mod .linkSystemLibrary ("GL" , .{});
753- exe_mod .linkSystemLibrary ("rt" , .{});
754- exe_mod .linkSystemLibrary ("dl" , .{});
755- exe_mod .linkSystemLibrary ("m" , .{});
756- exe_mod .linkSystemLibrary ("X11" , .{});
757-
758- exe_mod .addCMacro ("PLATFORM_DESKTOP" , "" );
759- },
760- .macos = > {
761- exe_mod .linkFramework ("Foundation" , .{});
762- exe_mod .linkFramework ("Cocoa" , .{});
763- exe_mod .linkFramework ("OpenGL" , .{});
764- exe_mod .linkFramework ("CoreAudio" , .{});
765- exe_mod .linkFramework ("CoreVideo" , .{});
766- exe_mod .linkFramework ("IOKit" , .{});
767-
768- exe_mod .addCMacro ("PLATFORM_DESKTOP" , "" );
769- },
770- else = > {
771- @panic ("Unsupported OS" );
772- },
773- }
744+ exe_mod .addCMacro ("PLATFORM_DESKTOP" , "" );
774745
775746 const exe = b .addExecutable (.{
776747 .name = filename ,
777748 .root_module = exe_mod ,
749+ .use_lld = target .result .os .tag == .windows ,
778750 });
751+ b .installArtifact (exe );
779752
780753 const install_cmd = b .addInstallArtifact (exe , .{});
781754
@@ -787,7 +760,6 @@ fn addExamples(
787760 all .dependOn (& install_cmd .step );
788761 }
789762 }
790-
791763 return all ;
792764}
793765
0 commit comments