Skip to content

add android prebuilt binary support - #4729

Open
thunder-coding wants to merge 2 commits into
microsoft:mainfrom
thunder-coding:android
Open

add android prebuilt binary support#4729
thunder-coding wants to merge 2 commits into
microsoft:mainfrom
thunder-coding:android

Conversation

@thunder-coding

Copy link
Copy Markdown

Fixes #4715

This currently requires the Android NDK bin to be present in $PATH. Tested using NDK r29. Had to modify the const nativePreviewReleaseVersion = /** @type {string | undefined} */ (undefined); line in Herebyfile.mjs and hardcode it to a string in order to build for all targets at once, else it was only building for vsix targets.

I believe upstream might be interested in explicitly using a certain version of NDK adding the toolchain bin in $PATH, open to suggestions on that.

Requesting explicit review from @jakebailey as they had assigned them the issue

Android targets do need CGO_ENABLED=1 as it requires building some
native C code. See upstream issue: golang/go#42725 (comment)

Also move environment variable setting to getPlatforms(), as we need to
set more architecture specific and os-specific environment variables
now. Makes it much more cleaner to do it here. Also this means we are no
longer setting GOARM=6 for architectures that don't need it, the
variable should be accessed only for arm and arm64 targets, so setting
it specifically only for them makes sense. Similarly set CC environment
variable for cross-compiling for Android, and set CGO_ENABLED=1 when CC
is set.
fanotify syscall requires CAP_SYS_ADMIN which is not granted without
root on Android. Android terminates the process when the syscall is used
instead of gracefully rejecting the syscall, so don't try to use it at
all on Android
Copilot AI review requested due to automatic review settings July 24, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jakebailey

Copy link
Copy Markdown
Member

We're not going to have any of this NDK stuff on the build machine. I'm a bit confused why any of this is required, but maybe esbuild has been dealing with this too.

@thunder-coding

Copy link
Copy Markdown
Author

We're not going to have any of this NDK stuff on the build machine. I'm a bit confused why any of this is required, but maybe esbuild has been dealing with this too.

For some weird unknown reasons cgo is not needed for android arm64 builds, and esbuild only does provide prebuilt binaries for android arm64. So they get away without using cgo entirely and having no dependency on Android NDK. I enabled cgo for arm64 Android as well in this PR for consistency across all the architectures. Also there is another issue without cgo where name resolution might fail due to Go trying to read /etc/resolv.conf on Android which doesn't exist: https://dave.engineer/blog/2025/11/cross-compiling-go-android/. Android uses a different method for name resolution which actually depends on the java side of things: termux/termux-packages#10277 (comment), so cgo is needed to use getaddrinfo() provided by libc on Android

@jakebailey

Copy link
Copy Markdown
Member

If we want to do this, then I'm going to have to get NDK and so on on the builder, and I don't really want to do that until we move repos and get the pipeline in the same repo where it's easy to touch, so I don't think we'd want this PR at this point.

@thunder-coding

Copy link
Copy Markdown
Author

If we want to do this, then I'm going to have to get NDK and so on on the builder, and I don't really want to do that until we move repos and get the pipeline in the same repo where it's easy to touch, so I don't think we'd want this PR at this point.

Thanks that makes sense! Btw, I just did go through the codebase, and seems like tsgo isn't making any dns resolutions or any http requests that might trigger dns resolution (thanks to Gemini for the thorough search). I believe we can add support for Android arm64 now without cgo, and then once you move the pipelines over to here, I'll add support for other architectures. arm64 is most of active users according to deb download data I have for Termux.

Would you be fine with it?

@jakebailey

Copy link
Copy Markdown
Member

Btw, I just did go through the codebase, and seems like tsgo isn't making any dns resolutions or any http requests that might trigger dns resolution (thanks to Gemini for the thorough search).

Yes, this is super intentional 😄

I believe we can add support for Android arm64 now without cgo

After #4566, at least

@thunder-coding

Copy link
Copy Markdown
Author

This might be slightly off-topic for this PR, but I was surprised to see that you guys are raw handling syscalls for fanotify and inotify on linux and darwin. Seemed quite contradicting considering you guys choose Golang for it being just native enough for being portable and you guys broke portability here. I guess that's cause Go doesn't provide any native way to do that. I used to follow TS dev blogs quite religiously back when Go experimental rewrite was first announced

@jakebailey

Copy link
Copy Markdown
Member

"portable" to us meant "we can port our code to it", because our TS was structurally similar to Go. Has nothing to do with platform specific code.

@robertkirkman

robertkirkman commented Jul 24, 2026

Copy link
Copy Markdown

We're not going to have any of this NDK stuff on the build machine. I'm a bit confused why any of this is required, but maybe esbuild has been dealing with this too.

I'm not highly experienced with Go, but I believe that as long as you end up building it in any way that causes the command file on the resulting binary to resemble this (log from a different Go binary built for Android)

ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, for Android 24, built by NDK r29 (14206865), Go BuildID=TWSv5VruhiBWLdj8giMF/5htH7A3MAiAttg80FyFj/AV6eW2jc-yHczcI_ysGY/1-xRNyCAHRwFZDQ9lOzw, BuildID[sha1]=544ff1db9053fbf1c37993aaebe2c6d06840e3b2, stripped

then it will work properly.

@jakebailey

Copy link
Copy Markdown
Member

I don't think it's required; I am putting up another PR that's the simplified version of this which perhaps you all could check. But, it'll only work for arm64.

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.

Request for support for Android

4 participants