@@ -90,41 +90,7 @@ fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend
9090 }
9191}
9292
93- /// A list of all flags from `src/config.h` that one may override
94- const config_h_flags = outer : {
95- // Set this value higher if compile errors happen as `src/config.h` gets larger
96- @setEvalBranchQuota (1 << 20 );
97-
98- const config_h = @embedFile ("src/config.h" );
99- var flags : [std .mem .count (u8 , config_h , "\n " ) + 1 ][]const u8 = undefined ;
100-
101- var i = 0 ;
102- var lines = std .mem .tokenizeScalar (u8 , config_h , '\n ' );
103- while (lines .next ()) | line | {
104- if (! std .mem .containsAtLeast (u8 , line , 1 , "SUPPORT" )) continue ;
105- if (std .mem .containsAtLeast (u8 , line , 1 , "MODULE" )) continue ;
106- if (std .mem .startsWith (u8 , line , "//" )) continue ;
107- if (std .mem .startsWith (u8 , line , "#if" )) continue ;
108-
109- var flag = std .mem .trimStart (u8 , line , " \t " ); // Trim whitespace
110- flag = flag ["#define " .len - 1 .. ]; // Remove #define
111- flag = std .mem .trimStart (u8 , flag , " \t " ); // Trim whitespace
112- flag = flag [0 .. std .mem .indexOf (u8 , flag , " " ) orelse continue ]; // Flag is only one word, so capture till space
113- flag = "-D" ++ flag ; // Prepend with -D
114-
115- flags [i ] = flag ;
116- i += 1 ;
117- }
118-
119- // Uncomment this to check what flags normally get passed
120- //@compileLog(flags[0..i].*);
121- break :outer flags [0.. i ].* ;
122- };
123-
12493fn compileRaylib (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode , options : Options ) ! * std.Build.Step.Compile {
125- var raylib_flags_arr : std .ArrayList ([]const u8 ) = .empty ;
126- defer raylib_flags_arr .deinit (b .allocator );
127-
12894 const raylib = b .addLibrary (.{
12995 .name = "raylib" ,
13096 .linkage = options .linkage ,
@@ -135,60 +101,37 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
135101 }),
136102 });
137103
138- try raylib_flags_arr .appendSlice (
104+ raylib .root_module .addCMacro ("_GNU_SOURCE" , "" );
105+ raylib .root_module .addCMacro ("GL_SILENCE_DEPRECATION" , "199309L" );
106+
107+ var raylib_flags_arr : std .ArrayList ([]const u8 ) = .empty ;
108+ defer raylib_flags_arr .deinit (b .allocator );
109+
110+ try raylib_flags_arr .append (
139111 b .allocator ,
140- &[_ ][]const u8 {
141- "-std=gnu99" ,
142- "-D_GNU_SOURCE" ,
143- "-DGL_SILENCE_DEPRECATION=199309L" ,
144- "-fno-sanitize=undefined" , // https://github.com/raysan5/raylib/issues/3674
145- },
112+ "-std=gnu99" ,
146113 );
147114
148115 if (options .linkage == .dynamic ) {
149- try raylib_flags_arr .appendSlice (
116+ try raylib_flags_arr .append (
150117 b .allocator ,
151- &[_ ][]const u8 {
152- "-fPIC" ,
153- "-DBUILD_LIBTYPE_SHARED" ,
154- },
118+ "-fPIC" ,
155119 );
120+
121+ raylib .root_module .addCMacro ("BUILD_LIBTYPE_SHARED" , "" );
156122 }
157123
158124 if (options .config .len > 0 ) {
159- // Sets a flag indicating the use of a custom `config.h`
160- try raylib_flags_arr .append (b .allocator , "-DEXTERNAL_CONFIG_FLAGS" );
161125 // Splits a space-separated list of config flags into multiple flags
162126 //
163127 // Note: This means certain flags like `-x c++` won't be processed properly.
164128 // `-xc++` or similar should be used when possible
165129 var config_iter = std .mem .tokenizeScalar (u8 , options .config , ' ' );
166130
167131 // Apply config flags supplied by the user
168- while (config_iter .next ()) | config_flag |
132+ while (config_iter .next ()) | config_flag | {
169133 try raylib_flags_arr .append (b .allocator , config_flag );
170-
171- // Apply all relevant configs from `src/config.h` *except* the user-specified ones
172- //
173- // Note: Currently using a suboptimal `O(m*n)` time algorithm where:
174- // `m` corresponds roughly to the number of lines in `src/config.h`
175- // `n` corresponds to the number of user-specified flags
176- outer : for (config_h_flags ) | flag | {
177- // If a user already specified the flag, skip it
178- config_iter .reset ();
179- while (config_iter .next ()) | config_flag | {
180- // For a user-specified flag to match, it must share the same prefix and have the
181- // same length or be followed by an equals sign
182- if (! std .mem .startsWith (u8 , config_flag , flag )) continue ;
183- if (config_flag .len == flag .len or config_flag [flag .len ] == '=' ) continue :outer ;
184- }
185-
186- // Otherwise, append default value from config.h to compile flags
187- try raylib_flags_arr .append (b .allocator , flag );
188134 }
189- } else {
190- // Set default config if no custom config got set
191- try raylib_flags_arr .appendSlice (b .allocator , & config_h_flags );
192135 }
193136
194137 // No GLFW required on PLATFORM_DRM
@@ -200,24 +143,38 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
200143 c_source_files .appendSliceAssumeCapacity (&.{"src/rcore.c" });
201144
202145 if (options .rshapes ) {
146+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RSHAPES" , "1" );
203147 try c_source_files .append (b .allocator , "src/rshapes.c" );
204- try raylib_flags_arr .append (b .allocator , "-DSUPPORT_MODULE_RSHAPES" );
148+ } else {
149+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RSHAPES" , "0" );
205150 }
151+
206152 if (options .rtextures ) {
153+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RTEXTURES" , "1" );
207154 try c_source_files .append (b .allocator , "src/rtextures.c" );
208- try raylib_flags_arr .append (b .allocator , "-DSUPPORT_MODULE_RTEXTURES" );
155+ } else {
156+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RTEXTURES" , "0" );
209157 }
158+
210159 if (options .rtext ) {
160+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RTEXT" , "1" );
211161 try c_source_files .append (b .allocator , "src/rtext.c" );
212- try raylib_flags_arr .append (b .allocator , "-DSUPPORT_MODULE_RTEXT" );
162+ } else {
163+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RTEXT" , "0" );
213164 }
165+
214166 if (options .rmodels ) {
167+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RMODELS" , "1" );
215168 try c_source_files .append (b .allocator , "src/rmodels.c" );
216- try raylib_flags_arr .append (b .allocator , "-DSUPPORT_MODULE_RMODELS" );
169+ } else {
170+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RMODELS" , "0" );
217171 }
172+
218173 if (options .raudio ) {
174+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RAUDIO" , "1" );
219175 try c_source_files .append (b .allocator , "src/raudio.c" );
220- try raylib_flags_arr .append (b .allocator , "-DSUPPORT_MODULE_RAUDIO" );
176+ } else {
177+ raylib .root_module .addCMacro ("SUPPORT_MODULE_RAUDIO" , "0" );
221178 }
222179
223180 if (options .opengl_version != .auto ) {
0 commit comments