@@ -16,6 +16,7 @@ fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend
16
16
.glfw = > raylib .root_module .addCMacro ("PLATFORM_DESKTOP_GLFW" , "" ),
17
17
.rgfw = > raylib .root_module .addCMacro ("PLATFORM_DESKTOP_RGFW" , "" ),
18
18
.sdl = > raylib .root_module .addCMacro ("PLATFORM_DESKTOP_SDL" , "" ),
19
+ .android = > raylib .root_module .addCMacro ("PLATFORM_ANDROID" , "" ),
19
20
else = > {},
20
21
}
21
22
}
@@ -181,7 +182,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
181
182
.windows = > {
182
183
switch (options .platform ) {
183
184
.glfw = > try c_source_files .append ("src/rglfw.c" ),
184
- .rgfw , .sdl , .drm = > {},
185
+ .rgfw , .sdl , .drm , .android = > {},
185
186
}
186
187
187
188
raylib .linkSystemLibrary ("winmm" );
@@ -191,7 +192,71 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
191
192
setDesktopPlatform (raylib , options .platform );
192
193
},
193
194
.linux = > {
194
- if (options .platform != .drm ) {
195
+
196
+ if (options .platform == .drm ) {
197
+ if (options .opengl_version == .auto ) {
198
+ raylib .linkSystemLibrary ("GLESv2" );
199
+ raylib .root_module .addCMacro ("GRAPHICS_API_OPENGL_ES2" , "" );
200
+ }
201
+
202
+ raylib .linkSystemLibrary ("EGL" );
203
+ raylib .linkSystemLibrary ("gbm" );
204
+ raylib .linkSystemLibrary2 ("libdrm" , .{ .use_pkg_config = .force });
205
+
206
+ raylib .root_module .addCMacro ("PLATFORM_DRM" , "" );
207
+ raylib .root_module .addCMacro ("EGL_NO_X11" , "" );
208
+ raylib .root_module .addCMacro ("DEFAULT_BATCH_BUFFER_ELEMENT" , "" );
209
+ } else if (target .result .abi == .android ) {
210
+
211
+ //these are the only tag options per https://developer.android.com/ndk/guides/other_build_systems
212
+ const hostTuple = switch (builtin .target .os .tag ) {
213
+ .linux = > "linux-x86_64" ,
214
+ .windows = > "windows-x86_64" ,
215
+ .macos = > "darwin-x86_64" ,
216
+ else = > {
217
+ @panic ("unsupported host OS" );
218
+ }
219
+ };
220
+
221
+ const androidTriple = try target .result .linuxTriple (b .allocator );
222
+ const androidNdkPathString : []const u8 = options .android_ndk ;
223
+ if (androidNdkPathString .len < 1 ) @panic ("no ndk path provided and ANDROID_NDK_HOME is not set" );
224
+ const androidApiLevel : []const u8 = options .android_api_version ;
225
+
226
+ const androidSysroot = try std .fs .path .join (b .allocator , &.{androidNdkPathString , "/toolchains/llvm/prebuilt/" , hostTuple , "/sysroot" });
227
+ const androidLibPath = try std .fs .path .join (b .allocator , &.{androidSysroot , "/usr/lib/" , androidTriple });
228
+ const androidApiSpecificPath = try std .fs .path .join (b .allocator , &.{androidLibPath , androidApiLevel });
229
+ const androidIncludePath = try std .fs .path .join (b .allocator , &.{androidSysroot , "/usr/include" });
230
+ const androidArchIncludePath = try std .fs .path .join (b .allocator , &.{androidIncludePath , androidTriple });
231
+ const androidAsmPath = try std .fs .path .join (b .allocator , &.{androidIncludePath , "/asm-generic" });
232
+ const androidGluePath = try std .fs .path .join (b .allocator , &.{androidNdkPathString , "/sources/android/native_app_glue/" });
233
+
234
+ raylib .addLibraryPath (.{ .cwd_relative = androidLibPath });
235
+ raylib .root_module .addLibraryPath (.{ .cwd_relative = androidApiSpecificPath });
236
+ raylib .addSystemIncludePath (.{ .cwd_relative = androidIncludePath });
237
+ raylib .addSystemIncludePath (.{ .cwd_relative = androidArchIncludePath });
238
+ raylib .addSystemIncludePath ( .{ .cwd_relative = androidAsmPath });
239
+ raylib .addSystemIncludePath (.{ .cwd_relative = androidGluePath });
240
+
241
+ const libcFile = try std .fs .cwd ().createFile ("android-libc.txt" , .{});
242
+ const writer = libcFile .writer ();
243
+ const libc = std.zig.LibCInstallation {
244
+ .include_dir = androidIncludePath ,
245
+ .sys_include_dir = androidIncludePath ,
246
+ .crt_dir = androidApiSpecificPath ,
247
+ };
248
+ try libc .render (writer );
249
+ libcFile .close ();
250
+
251
+ raylib .setLibCFile (b .path ("android-libc.txt" ));
252
+
253
+ if (options .opengl_version == .auto ) {
254
+ raylib .root_module .linkSystemLibrary ("GLESv2" , .{});
255
+ raylib .root_module .addCMacro ("GRAPHICS_API_OPENGL_ES2" , "" );
256
+ }
257
+
258
+ setDesktopPlatform (raylib , .android );
259
+ } else {
195
260
try c_source_files .append ("src/rglfw.c" );
196
261
197
262
if (options .linux_display_backend == .X11 or options .linux_display_backend == .Both ) {
@@ -229,21 +294,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
229
294
waylandGenerate (b , raylib , "xdg-activation-v1.xml" , "xdg-activation-v1-client-protocol" );
230
295
waylandGenerate (b , raylib , "idle-inhibit-unstable-v1.xml" , "idle-inhibit-unstable-v1-client-protocol" );
231
296
}
232
-
233
297
setDesktopPlatform (raylib , options .platform );
234
- } else {
235
- if (options .opengl_version == .auto ) {
236
- raylib .linkSystemLibrary ("GLESv2" );
237
- raylib .root_module .addCMacro ("GRAPHICS_API_OPENGL_ES2" , "" );
238
- }
239
-
240
- raylib .linkSystemLibrary ("EGL" );
241
- raylib .linkSystemLibrary ("gbm" );
242
- raylib .linkSystemLibrary2 ("libdrm" , .{ .use_pkg_config = .force });
243
-
244
- raylib .root_module .addCMacro ("PLATFORM_DRM" , "" );
245
- raylib .root_module .addCMacro ("EGL_NO_X11" , "" );
246
- raylib .root_module .addCMacro ("DEFAULT_BATCH_BUFFER_ELEMENT" , "" );
247
298
}
248
299
},
249
300
.freebsd , .openbsd , .netbsd , .dragonfly = > {
@@ -335,6 +386,8 @@ pub const Options = struct {
335
386
shared : bool = false ,
336
387
linux_display_backend : LinuxDisplayBackend = .Both ,
337
388
opengl_version : OpenglVersion = .auto ,
389
+ android_ndk : []const u8 = "" ,
390
+ android_api_version : []const u8 = "35" ,
338
391
/// config should be a list of space-separated cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL"
339
392
config : []const u8 = &.{},
340
393
@@ -352,6 +405,8 @@ pub const Options = struct {
352
405
.linux_display_backend = b .option (LinuxDisplayBackend , "linux_display_backend" , "Linux display backend to use" ) orelse defaults .linux_display_backend ,
353
406
.opengl_version = b .option (OpenglVersion , "opengl_version" , "OpenGL version to use" ) orelse defaults .opengl_version ,
354
407
.config = b .option ([]const u8 , "config" , "Compile with custom define macros overriding config.h" ) orelse &.{},
408
+ .android_ndk = b .option ([]const u8 , "android_ndk" , "specify path to android ndk" ) orelse std .process .getEnvVarOwned (b .allocator , "ANDROID_NDK_HOME" ) catch "" ,
409
+ .android_api_version = b .option ([]const u8 , "android_api_version" , "specify target android API level" ) orelse defaults .android_api_version ,
355
410
};
356
411
}
357
412
};
@@ -389,6 +444,7 @@ pub const PlatformBackend = enum {
389
444
rgfw ,
390
445
sdl ,
391
446
drm ,
447
+ android
392
448
};
393
449
394
450
pub fn build (b : * std.Build ) ! void {
0 commit comments