Skip to content

Commit 09570a0

Browse files
committed
Merge branch 'master' of https://github.com/raysan5/raylib
2 parents 85de743 + ce3b121 commit 09570a0

17 files changed

Lines changed: 1544 additions & 723 deletions

build.zig

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22
const builtin = @import("builtin");
33

44
/// Minimum supported version of Zig
5-
const min_ver = "0.12.0";
5+
const min_ver = "0.13.0";
66

77
comptime {
88
const order = std.SemanticVersion.order;
@@ -11,36 +11,6 @@ comptime {
1111
@compileError("Raylib requires zig version " ++ min_ver);
1212
}
1313

14-
// NOTE(freakmangd): I don't like using a global here, but it prevents having to
15-
// get the flags a second time when adding raygui
16-
var raylib_flags_arr: std.ArrayListUnmanaged([]const u8) = .{};
17-
18-
// This has been tested with zig version 0.12.0
19-
pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
20-
const raylib_dep = b.dependencyFromBuildZig(@This(), .{
21-
.target = target,
22-
.optimize = optimize,
23-
.raudio = options.raudio,
24-
.rmodels = options.rmodels,
25-
.rshapes = options.rshapes,
26-
.rtext = options.rtext,
27-
.rtextures = options.rtextures,
28-
.platform = options.platform,
29-
.shared = options.shared,
30-
.linux_display_backend = options.linux_display_backend,
31-
.opengl_version = options.opengl_version,
32-
.config = options.config,
33-
});
34-
const raylib = raylib_dep.artifact("raylib");
35-
36-
if (options.raygui) {
37-
const raygui_dep = b.dependency(options.raygui_dependency_name, .{});
38-
addRaygui(b, raylib, raygui_dep);
39-
}
40-
41-
return raylib;
42-
}
43-
4414
fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend) void {
4515
raylib.defineCMacro("PLATFORM_DESKTOP", null);
4616

@@ -52,6 +22,30 @@ fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend
5222
}
5323
}
5424

25+
fn createEmsdkStep(b: *std.Build, emsdk: *std.Build.Dependency) *std.Build.Step.Run {
26+
if (builtin.os.tag == .windows) {
27+
return b.addSystemCommand(&.{emsdk.path("emsdk.bat").getPath(b)});
28+
} else {
29+
return b.addSystemCommand(&.{emsdk.path("emsdk").getPath(b)});
30+
}
31+
}
32+
33+
fn emSdkSetupStep(b: *std.Build, emsdk: *std.Build.Dependency) !?*std.Build.Step.Run {
34+
const dot_emsc_path = emsdk.path(".emscripten").getPath(b);
35+
const dot_emsc_exists = !std.meta.isError(std.fs.accessAbsolute(dot_emsc_path, .{}));
36+
37+
if (!dot_emsc_exists) {
38+
const emsdk_install = createEmsdkStep(b, emsdk);
39+
emsdk_install.addArgs(&.{ "install", "latest" });
40+
const emsdk_activate = createEmsdkStep(b, emsdk);
41+
emsdk_activate.addArgs(&.{ "activate", "latest" });
42+
emsdk_activate.step.dependOn(&emsdk_install.step);
43+
return emsdk_activate;
44+
} else {
45+
return null;
46+
}
47+
}
48+
5549
/// A list of all flags from `src/config.h` that one may override
5650
const config_h_flags = outer: {
5751
// Set this value higher if compile errors happen as `src/config.h` gets larger
@@ -83,21 +77,26 @@ const config_h_flags = outer: {
8377
};
8478

8579
fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
86-
raylib_flags_arr.clearRetainingCapacity();
80+
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
81+
defer raylib_flags_arr.deinit();
8782

88-
const shared_flags = &[_][]const u8{
89-
"-fPIC",
90-
"-DBUILD_LIBTYPE_SHARED",
91-
};
92-
try raylib_flags_arr.appendSlice(b.allocator, &[_][]const u8{
83+
try raylib_flags_arr.appendSlice(&[_][]const u8{
9384
"-std=gnu99",
9485
"-D_GNU_SOURCE",
9586
"-DGL_SILENCE_DEPRECATION=199309L",
9687
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
9788
});
89+
90+
if (options.shared) {
91+
try raylib_flags_arr.appendSlice(&[_][]const u8{
92+
"-fPIC",
93+
"-DBUILD_LIBTYPE_SHARED",
94+
});
95+
}
96+
9897
if (options.config.len > 0) {
9998
// Sets a flag indiciating the use of a custom `config.h`
100-
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
99+
try raylib_flags_arr.append("-DEXTERNAL_CONFIG_FLAGS");
101100

102101
// Splits a space-separated list of config flags into multiple flags
103102
//
@@ -107,7 +106,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
107106

108107
// Apply config flags supplied by the user
109108
while (config_iter.next()) |config_flag|
110-
try raylib_flags_arr.append(b.allocator, config_flag);
109+
try raylib_flags_arr.append(config_flag);
111110

112111
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
113112
//
@@ -125,14 +124,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
125124
}
126125

127126
// Otherwise, append default value from config.h to compile flags
128-
try raylib_flags_arr.append(b.allocator, flag);
127+
try raylib_flags_arr.append(flag);
129128
}
130129
}
131130

132-
if (options.shared) {
133-
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
134-
}
135-
136131
const raylib = if (options.shared)
137132
b.addSharedLibrary(.{
138133
.name = "raylib",
@@ -223,6 +218,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
223218
waylandGenerate(b, raylib, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol");
224219
waylandGenerate(b, raylib, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol");
225220
}
221+
226222
setDesktopPlatform(raylib, options.platform);
227223
} else {
228224
if (options.opengl_version == .auto) {
@@ -255,8 +251,15 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
255251
setDesktopPlatform(raylib, options.platform);
256252
},
257253
.macos => {
254+
// Include xcode_frameworks for cross compilation
255+
if (b.lazyDependency("xcode_frameworks", .{})) |dep| {
256+
raylib.addSystemFrameworkPath(dep.path("Frameworks"));
257+
raylib.addSystemIncludePath(dep.path("include"));
258+
raylib.addLibraryPath(dep.path("lib"));
259+
}
260+
258261
// On macos rglfw.c include Objective-C files.
259-
try raylib_flags_arr.append(b.allocator, "-ObjC");
262+
try raylib_flags_arr.append("-ObjC");
260263
raylib.root_module.addCSourceFile(.{
261264
.file = b.path("src/rglfw.c"),
262265
.flags = raylib_flags_arr.items,
@@ -271,20 +274,19 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
271274
setDesktopPlatform(raylib, options.platform);
272275
},
273276
.emscripten => {
277+
// Include emscripten for cross compilation
278+
if (b.lazyDependency("emsdk", .{})) |dep| {
279+
if (try emSdkSetupStep(b, dep)) |emSdkStep| {
280+
raylib.step.dependOn(&emSdkStep.step);
281+
}
282+
283+
raylib.addIncludePath(dep.path("upstream/emscripten/cache/sysroot/include"));
284+
}
285+
274286
raylib.defineCMacro("PLATFORM_WEB", null);
275287
if (options.opengl_version == .auto) {
276288
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
277289
}
278-
279-
if (b.sysroot == null) {
280-
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
281-
}
282-
283-
const cache_include = b.pathJoin(&.{ b.sysroot.?, "cache", "sysroot", "include" });
284-
285-
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
286-
dir.close();
287-
raylib.addIncludePath(.{ .cwd_relative = cache_include });
288290
},
289291
else => {
290292
@panic("Unsupported OS");
@@ -296,25 +298,19 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
296298
.flags = raylib_flags_arr.items,
297299
});
298300

299-
return raylib;
300-
}
301-
302-
/// This function does not need to be called if you passed .raygui = true to addRaylib
303-
pub fn addRaygui(b: *std.Build, raylib: *std.Build.Step.Compile, raygui_dep: *std.Build.Dependency) void {
304-
if (raylib_flags_arr.items.len == 0) {
305-
@panic(
306-
\\argument 2 `raylib` in `addRaygui` must come from b.dependency("raylib", ...).artifact("raylib")
307-
);
308-
}
301+
if (options.raygui) {
302+
const raygui_dep = b.dependency(options.raygui_dependency_name, .{});
309303

310-
var gen_step = b.addWriteFiles();
311-
raylib.step.dependOn(&gen_step.step);
304+
var gen_step = b.addWriteFiles();
305+
raylib.step.dependOn(&gen_step.step);
312306

313-
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
314-
raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items });
315-
raylib.addIncludePath(raygui_dep.path("src"));
307+
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
308+
raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items });
309+
raylib.addIncludePath(raygui_dep.path("src"));
310+
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
311+
}
316312

317-
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
313+
return raylib;
318314
}
319315

320316
pub const Options = struct {

build.zig.zon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.{
2+
.name = "raylib",
3+
.version = "5.5.0",
4+
.minimum_zig_version = "0.13.0",
5+
6+
.dependencies = .{
7+
.xcode_frameworks = .{
8+
.url = "git+https://github.com/hexops/xcode-frameworks#a6bf82e032d4d9923ad5c222d466710fcc05f249",
9+
.hash = "12208da4dfcd9b53fb367375fb612ec73f38e53015f1ce6ae6d6e8437a637078e170",
10+
.lazy = true,
11+
},
12+
.emsdk = .{
13+
.url = "git+https://github.com/emscripten-core/emsdk#3.1.50",
14+
.hash = "1220e8fe9509f0843e5e22326300ca415c27afbfbba3992f3c3184d71613540b5564",
15+
.lazy = true,
16+
},
17+
},
18+
19+
.paths = .{
20+
"build.zig",
21+
"build.zig.zon",
22+
"src",
23+
},
24+
}

examples/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ USE_EXTERNAL_GLFW ?= FALSE
8787
# WARNING: Library is not included in raylib, it MUST be configured by users
8888
SDL_INCLUDE_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2/include
8989
SDL_LIBRARY_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2/lib
90+
SDL_LIBRARIES ?= -lSDL2 -lSDL2main
91+
9092

9193
# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system)
9294
# NOTE: This variable is only used for PLATFORM_OS: LINUX
@@ -263,9 +265,9 @@ endif
263265
# Define include paths for required headers: INCLUDE_PATHS
264266
# NOTE: Some external/extras libraries could be required (stb, easings...)
265267
#------------------------------------------------------------------------------------------------
266-
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
267-
268+
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external $(EXTRA_INCLUDE_PATHS)
268269
# Define additional directories containing required header files
270+
269271
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
270272
ifeq ($(PLATFORM_OS),BSD)
271273
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH) -I/usr/pkg/include -I/usr/X11R7/include
@@ -415,12 +417,12 @@ endif
415417
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
416418
ifeq ($(PLATFORM_OS),WINDOWS)
417419
# Libraries for Windows desktop compilation
418-
LDLIBS = -lraylib -lSDL2 -lSDL2main -lopengl32 -lgdi32
420+
LDLIBS = -lraylib $(SDL_LIBRARIES) -lopengl32 -lgdi32
419421
endif
420422
ifeq ($(PLATFORM_OS),LINUX)
421423
# Libraries for Debian GNU/Linux desktop compiling
422424
# NOTE: Required packages: libegl1-mesa-dev
423-
LDLIBS = -lraylib -lSDL2 -lSDL2main -lGL -lm -lpthread -ldl -lrt
425+
LDLIBS = -lraylib $(SDL_LIBRARIES) -lGL -lm -lpthread -ldl -lrt
424426

425427
# On X11 requires also below libraries
426428
LDLIBS += -lX11
@@ -646,8 +648,12 @@ OTHERS = \
646648
others/embedded_files_loading \
647649
others/raylib_opengl_interop \
648650
others/raymath_vector_angle \
649-
others/rlgl_compute_shader \
650-
others/rlgl_standalone
651+
others/rlgl_compute_shader
652+
653+
ifeq ($(TARGET_PLATFORM), PLATFORM_DESKTOP_GFLW)
654+
OTHERS += others/rlgl_standalone
655+
endif
656+
651657

652658
CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
653659

parser/output/raylib_api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,6 +3520,11 @@
35203520
"description": "Get clipboard text content",
35213521
"returnType": "const char *"
35223522
},
3523+
{
3524+
"name": "GetClipboardImage",
3525+
"description": "Get clipboard image",
3526+
"returnType": "Image"
3527+
},
35233528
{
35243529
"name": "EnableEventWaiting",
35253530
"description": "Enable waiting for events on EndDrawing(), no automatic event polling",

parser/output/raylib_api.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,6 +3397,11 @@ return {
33973397
description = "Get clipboard text content",
33983398
returnType = "const char *"
33993399
},
3400+
{
3401+
name = "GetClipboardImage",
3402+
description = "Get clipboard image",
3403+
returnType = "Image"
3404+
},
34003405
{
34013406
name = "EnableEventWaiting",
34023407
description = "Enable waiting for events on EndDrawing(), no automatic event polling",

0 commit comments

Comments
 (0)