Skip to content
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

Get it working with 0.12.0-dev / latest nightly Zig #37

Closed
wants to merge 7 commits into from

Conversation

slimsag
Copy link

@slimsag slimsag commented Sep 16, 2023

This PR gets ZigAndroidTemplate working again with the latest Zig version.

This requires > current nightly Zig, and will not work with Zig 0.11, as std.c actually needs to be patched to support Android bionic libc: ziglang/zig#17176

Context: I did this work as I am using this as a reference for Mach's own Android support. At this point, I will probably diverge from this repository and may not update this PR. So if anything here is not useful to you feel free to discard it - this achieved what I wanted to achieve, so I am just sharing the results with you. Feel free to integrate (or not integrate) any parts of this, I don't mind what you do with it.

I was able to confirm on an Apple Silicon host machine (any host OS should work) that:

zig build -Dexample=egl install push && sleep 1 && zig build run

works as expected, displays a Zig logo and when volume is turned all the way up, tapping the screen plays a quiet 'beeeep' sound with AAudio.

see individual commit messages for details, I explained the changes in there.

Helps hexops/mach#17

image

Signed-off-by: Stephen Gutekanst <[email protected]>
Signed-off-by: Stephen Gutekanst <[email protected]>
25.1.8937393 does not provide Apple Silicon toolchain binaries, only x86 ones. It also
does not correctly invoke Rosetta emulation in the build scripts, BUT 24.0.8215888 actually
does. [details](https://stackoverflow.com/questions/69541831/unknown-host-cpu-architecture-arm64-android-ndk-siliconm1-apple-macbook-pro)
so it seems prudent to downgrade the version.

Additionally, when building from an Apple Silicon host, adjust the `toolchainHostTag()` appropriately for Rosetta emulation.

Signed-off-by: Stephen Gutekanst <[email protected]>
Signed-off-by: Stephen Gutekanst <[email protected]>
On macOS, `adb devices` ALWAYS has an 'offline' emulator device:

```
List of devices attached
emulator-5562  offline
```

As a result, all the `adb` commands in build.zig only work if you are
using the emulator. The second that you connect an actual Android device,
you have two devices in the list - and it all the adb commands error out
with a 'ambiguous device' error.

Adding the `-d` flag everywhere tells adb to prefer physical devices,
which results in build.zig only working with physical devices in
practice.

Long-term, I imagine you would want to make `-d` a CLI flag that can be
passed to `zig build` - or perhaps even let the user select a device
somehow. But this was good enough for my purposes.

Signed-off-by: Stephen Gutekanst <[email protected]>
@ikskuh
Copy link
Owner

ikskuh commented Sep 20, 2023

Not sure if i can merge it like that, especially as you unnecessarily changed several versions of SDK/NDK/Android version where it wouldn't be necessary (you can just declare those in the build setup instead of changing the defaults)

@ikskuh
Copy link
Owner

ikskuh commented Sep 20, 2023

At this point, I will probably diverge from this repository and may not update this PR.

Can you explain that? I really don't like to see that we have two implementations of the Android stuff, as it means we both have to make either the same mistake twice or constantly monitor the other repository to backport things. What exactly would you change, and why? And can we make those changes as optional features of this repository?

@slimsag
Copy link
Author

slimsag commented Sep 21, 2023

Not sure if i can merge it like that, especially as you unnecessarily changed several versions of SDK/NDK/Android version

No worries, as I mentioned this was less of a 'please merge this' but rather more of a 'here's what I did, just sharing the results, hope any of this is useful to you' PR. Not asking for this to be merged as-is :) I'll close the PR, I just wanted you to be aware the code is here if you want to cherry-pick anything from it.

Changing the NDK version was for good reason, see the commit message for details.

Can you explain that? I really don't like to see that we have two implementations of the Android stuff

Yeah, I get that.. happy to explain:

  1. I'm comfortable requiring AAudio and Vulkan, and dropping older APIs like OpenSL ES, GLES, etc. entirely
  2. Mach is already on Zig 0.12.0-dev, and will continue following (pinned, specific) nightly Zig versions. I understand you intend to stick with older Zig 0.11 (fair!) but I can't/won't do that so it introduces a divergence between our projects.
  3. I will possibly use native_app_glue instead of the main ZigAndroidTemplate provides, not sure yet though.
  4. ZigAndroidTemplate feels a bit like a kitchen sink with Sdk.zig, AAudio, OpenSL, JNI, and various other Android APIs wrapped all in the same project. I think this is by design, but it doesn't mesh well with Mach which tries to solve each of these as independent projects:
    • sysaudio would have an AAudio backend
    • I feel uneasy about Sdk.zig and how many levers it necessarily has to pull here, if Zig does in fact lose custom build steps the approach taken in this project would be very very hard to adapt to that I suspect. There are other ways to structure this to avoid this potential outcome, application packaging in general is a more broad topic than just Android, but I suspect you wouldn't be happy with the way I might approach this.
  5. Like you, I also don't have a ton of time. Hopefully one day, but for today my bandwidth is very very limited so I have to be very careful where I spend my time to have productive outcomes.

I am grateful for ZigAndroidTemplate/you pioneering the way here, and giving me something I can reference/look at. In short I think that Mach has different constraints/goals than you w.r.t. Android support and that's not straightforward to unify with little time.

@slimsag slimsag closed this Sep 21, 2023
@ikskuh
Copy link
Owner

ikskuh commented Sep 21, 2023

Thanks for the clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants