@@ -11,36 +11,6 @@ comptime {
11
11
@compileError ("Raylib requires zig version " ++ min_ver );
12
12
}
13
13
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.13.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
-
44
14
fn setDesktopPlatform (raylib : * std.Build.Step.Compile , platform : PlatformBackend ) void {
45
15
raylib .defineCMacro ("PLATFORM_DESKTOP" , null );
46
16
@@ -107,21 +77,26 @@ const config_h_flags = outer: {
107
77
};
108
78
109
79
fn compileRaylib (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode , options : Options ) ! * std.Build.Step.Compile {
110
- raylib_flags_arr .clearRetainingCapacity ();
80
+ var raylib_flags_arr = std .ArrayList ([]const u8 ).init (b .allocator );
81
+ defer raylib_flags_arr .deinit ();
111
82
112
- const shared_flags = &[_ ][]const u8 {
113
- "-fPIC" ,
114
- "-DBUILD_LIBTYPE_SHARED" ,
115
- };
116
- try raylib_flags_arr .appendSlice (b .allocator , &[_ ][]const u8 {
83
+ try raylib_flags_arr .appendSlice (&[_ ][]const u8 {
117
84
"-std=gnu99" ,
118
85
"-D_GNU_SOURCE" ,
119
86
"-DGL_SILENCE_DEPRECATION=199309L" ,
120
87
"-fno-sanitize=undefined" , // https://github.com/raysan5/raylib/issues/3674
121
88
});
89
+
90
+ if (options .shared ) {
91
+ try raylib_flags_arr .appendSlice (&[_ ][]const u8 {
92
+ "-fPIC" ,
93
+ "-DBUILD_LIBTYPE_SHARED" ,
94
+ });
95
+ }
96
+
122
97
if (options .config .len > 0 ) {
123
98
// Sets a flag indiciating the use of a custom `config.h`
124
- try raylib_flags_arr .append (b . allocator , "-DEXTERNAL_CONFIG_FLAGS" );
99
+ try raylib_flags_arr .append ("-DEXTERNAL_CONFIG_FLAGS" );
125
100
126
101
// Splits a space-separated list of config flags into multiple flags
127
102
//
@@ -131,7 +106,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
131
106
132
107
// Apply config flags supplied by the user
133
108
while (config_iter .next ()) | config_flag |
134
- try raylib_flags_arr .append (b . allocator , config_flag );
109
+ try raylib_flags_arr .append (config_flag );
135
110
136
111
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
137
112
//
@@ -149,14 +124,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
149
124
}
150
125
151
126
// Otherwise, append default value from config.h to compile flags
152
- try raylib_flags_arr .append (b . allocator , flag );
127
+ try raylib_flags_arr .append (flag );
153
128
}
154
129
}
155
130
156
- if (options .shared ) {
157
- try raylib_flags_arr .appendSlice (b .allocator , shared_flags );
158
- }
159
-
160
131
const raylib = if (options .shared )
161
132
b .addSharedLibrary (.{
162
133
.name = "raylib" ,
@@ -288,7 +259,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
288
259
}
289
260
290
261
// On macos rglfw.c include Objective-C files.
291
- try raylib_flags_arr .append (b . allocator , "-ObjC" );
262
+ try raylib_flags_arr .append ("-ObjC" );
292
263
raylib .root_module .addCSourceFile (.{
293
264
.file = b .path ("src/rglfw.c" ),
294
265
.flags = raylib_flags_arr .items ,
@@ -327,25 +298,19 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
327
298
.flags = raylib_flags_arr .items ,
328
299
});
329
300
330
- return raylib ;
331
- }
332
-
333
- /// This function does not need to be called if you passed .raygui = true to addRaylib
334
- pub fn addRaygui (b : * std.Build , raylib : * std.Build.Step.Compile , raygui_dep : * std.Build.Dependency ) void {
335
- if (raylib_flags_arr .items .len == 0 ) {
336
- @panic (
337
- \\argument 2 `raylib` in `addRaygui` must come from b.dependency("raylib", ...).artifact("raylib")
338
- );
339
- }
301
+ if (options .raygui ) {
302
+ const raygui_dep = b .dependency (options .raygui_dependency_name , .{});
340
303
341
- var gen_step = b .addWriteFiles ();
342
- raylib .step .dependOn (& gen_step .step );
304
+ var gen_step = b .addWriteFiles ();
305
+ raylib .step .dependOn (& gen_step .step );
343
306
344
- const raygui_c_path = gen_step .add ("raygui.c" , "#define RAYGUI_IMPLEMENTATION\n #include \" raygui.h\" \n " );
345
- raylib .addCSourceFile (.{ .file = raygui_c_path , .flags = raylib_flags_arr .items });
346
- 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
+ }
347
312
348
- raylib . installHeader ( raygui_dep . path ( "src/raygui.h" ), "raygui.h" ) ;
313
+ return raylib ;
349
314
}
350
315
351
316
pub const Options = struct {
0 commit comments