-
Notifications
You must be signed in to change notification settings - Fork 10
added minimal example for raylib #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
silbinarywolf
merged 7 commits into
silbinarywolf:main
from
lumenkeyes:add-raylib-example
May 24, 2025
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10628d1
added minimal example for raylib
lumenkeyes f6f1723
Changes as requested
lumenkeyes af49aed
Fix null value usage
lumenkeyes 9cbe2be
add run step
lumenkeyes 243ab6a
changes as requested
lumenkeyes 9af0b37
Remove old comment
lumenkeyes 1840751
Fix missing entry point
lumenkeyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| A minimal example of using [zig-android-sdk](https://github.com/silbinarywolf/zig-android-sdk) to build raylib for android. | ||
|
|
||
| Build for a single target with, e.g. `zig build -Dtarget=aarch64-linux-android`, or for all android targets with `zig build -Dandroid=true`. | ||
|
|
||
| **Note**: | ||
| Due to [an upstream bug](https://github.com/ziglang/zig/issues/20476), you will probably receive a warning (or multiple warnings if building for multiple targets) like this: | ||
| ``` | ||
| error: warning(link): unexpected LLD stderr: | ||
| ld.lld: warning: <path-to-project>/.zig-cache/o/4227869d730f094811a7cdaaab535797/libraylib.a: archive member '<path-to-ndk>/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/35/libGLESv2.so' is neither ET_REL nor LLVM bitcode | ||
| ``` | ||
| You can ignore this error for now. | ||
|
|
||
| You should probably source the `android_native_app_glue.c/.h` files from the version of the SDK you download, rather than using the included ones, to ensure you are using the most up-to-date versions. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| package="com.zig.minimal"> | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <uses-feature android:glEsVersion="0x00020000" android:required="true"/> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <uses-sdk android:minSdkVersion="9" /> | ||
|
|
||
| <application | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:hasCode="false" | ||
| android:theme="@android:style/Theme.NoTitleBar.Fullscreen" | ||
| tools:targetApi="29" | ||
| android:alwaysRetainTaskState="true" | ||
| android:launchMode="singleInstance" | ||
| android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation" | ||
| > | ||
| <activity | ||
| android:name="android.app.NativeActivity" | ||
| android:exported="true" | ||
| android:label="@string/app_name"> | ||
| <meta-data android:name="android.app.lib_name" android:value="main"/> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <!-- Pretty name of your app --> | ||
| <string name="app_name">Zig Minimal</string> | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <!-- | ||
| This is required for the APK name. This identifies your app, Android will associate | ||
| your signing key with this identifier and will prevent updates if the key changes. | ||
| --> | ||
| <string name="package_name">com.zig.minimal</string> | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </resources> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| const android = @import("android"); | ||
| const std = @import("std"); | ||
|
|
||
| //this is targeting android API level 29. | ||
| //You may have to change the values here and in android/AndroidManifest.xml to target your desired API level | ||
| const android_api = "29"; | ||
| const android_version = .android10; | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| pub fn build(b: *std.Build) void { | ||
| const root_target = b.standardTargetOptions(.{}); | ||
| const optimize = b.standardOptimizeOption(.{}); | ||
| const android_targets = android.standardTargets(b, root_target); | ||
|
|
||
| var root_target_single = [_]std.Build.ResolvedTarget{root_target}; | ||
| const targets: []std.Build.ResolvedTarget = if (android_targets.len == 0) | ||
| root_target_single[0..] | ||
| else | ||
| android_targets; | ||
|
|
||
| const android_apk: ?*android.APK = blk: { | ||
| if (android_targets.len == 0) { | ||
| break :blk null; | ||
| } | ||
| const android_tools = android.Tools.create(b, .{ | ||
| .api_level = android_version, | ||
| .build_tools_version = "35.0.0", | ||
| .ndk_version = "27.2.12479018", | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| const apk = android.APK.create(b, android_tools); | ||
|
|
||
| const key_store_file = android_tools.createKeyStore(android.CreateKey.example()); | ||
| apk.setKeyStore(key_store_file); | ||
| apk.setAndroidManifest(b.path("android/AndroidManifest.xml")); | ||
| apk.addResourceDirectory(b.path("android/res")); | ||
|
|
||
| break :blk apk; | ||
| }; | ||
|
|
||
| for(targets) |target| { | ||
| if (target.result.abi.isAndroid()) { | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const lib_mod = b.createModule(.{ | ||
| .root_source_file = b.path("src/main.zig"), | ||
| .target = target, | ||
| .optimize = optimize, | ||
| }); | ||
|
|
||
| const lib = b.addLibrary(.{ | ||
| .linkage = .dynamic, | ||
| .name = "minimal_android_raylib", | ||
| .root_module = lib_mod, | ||
| }); | ||
|
|
||
| b.installArtifact(lib); | ||
| lib.linkLibC(); | ||
| const raylib_dep = b.dependency("raylib_zig", .{ | ||
| .target = target, | ||
| .optimize = optimize, | ||
| .android_api_version = @as([]const u8, android_api) | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| const raylib_artifact = raylib_dep.artifact("raylib"); | ||
| lib.linkLibrary(raylib_artifact); | ||
|
|
||
| const raylib_mod = raylib_dep.module("raylib"); | ||
| lib.root_module.addImport("raylib", raylib_mod); | ||
| const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized"); | ||
|
|
||
| const android_dep = b.dependency("android", .{ | ||
| .optimize = optimize, | ||
| .target = target, | ||
| }); | ||
| lib.root_module.addImport("android", android_dep.module("android")); | ||
| lib.root_module.linkSystemLibrary("android", .{.preferred_link_mode = .dynamic}); | ||
| lib.root_module.linkSystemLibrary("EGL", .{.preferred_link_mode = .dynamic}); | ||
| lib.root_module.linkSystemLibrary("GLESv2", .{.preferred_link_mode = .dynamic}); | ||
| lib.root_module.linkSystemLibrary("log", .{ .preferred_link_mode = .dynamic }); | ||
| lib.root_module.addCSourceFile(.{ .file = b.path("src/android_native_app_glue.c")}); | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| apk.addArtifact(lib); | ||
| } else { | ||
| //non-android build logic... | ||
| } | ||
| } | ||
| if (android_apk) |apk| { | ||
| apk.installApk(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| .{ | ||
| // This is the default name used by packages depending on this one. For | ||
| // example, when a user runs `zig fetch --save <url>`, this field is used | ||
| // as the key in the `dependencies` table. Although the user can choose a | ||
| // different name, most users will stick with this provided value. | ||
| // | ||
| // It is redundant to include "zig" in this name because it is already | ||
| // within the Zig package namespace. | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .name = .minimal_android_raylib, | ||
lumenkeyes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // This is a [Semantic Version](https://semver.org/). | ||
| // In a future version of Zig it will be used for package deduplication. | ||
| .version = "0.0.0", | ||
|
|
||
| // Together with name, this represents a globally unique package | ||
| // identifier. This field is generated by the Zig toolchain when the | ||
| // package is first created, and then *never changes*. This allows | ||
| // unambiguous detection of one package being an updated version of | ||
| // another. | ||
| // | ||
| // When forking a Zig project, this id should be regenerated (delete the | ||
| // field and run `zig build`) if the upstream project is still maintained. | ||
| // Otherwise, the fork is *hostile*, attempting to take control over the | ||
| // original project's identity. Thus it is recommended to leave the comment | ||
| // on the following line intact, so that it shows up in code reviews that | ||
| // modify the field. | ||
| .fingerprint = 0x7d5dc97ee62a8428, // Changing this has security and trust implications. | ||
|
|
||
| // Tracks the earliest Zig version that the package considers to be a | ||
| // supported use case. | ||
| .minimum_zig_version = "0.14.0", | ||
|
|
||
| // This field is optional. | ||
| // Each dependency must either provide a `url` and `hash`, or a `path`. | ||
| // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. | ||
| // Once all dependencies are fetched, `zig build` no longer requires | ||
| // internet connectivity. | ||
| .dependencies = .{ | ||
| .raylib_zig = .{ | ||
| .url = "git+https://github.com/lumenkeyes/raylib-zig#e421e2a16c7f965b8ff70c7db7a13bf9fe2d321c", | ||
| .hash = "raylib_zig-5.6.0-dev-KE8REAgyBQB4QKuE8SJZHBOw_KGcoLCybyyAIXRLCXKQ", | ||
| }, | ||
| .android = .{ .path = "../.." }, | ||
| }, | ||
| .paths = .{ | ||
| "build.zig", | ||
| "build.zig.zon", | ||
| "src", | ||
| // For example... | ||
| //"LICENSE", | ||
| //"README.md", | ||
| }, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.