Repository navigation
Build the default library for Android - #22
Merged
Merged
Conversation
scripts/build_android.bat builds it on a Windows host with the Android NDK for API 29 (arm64-v8a and x86_64; release and debug; gc, rc and none), the Android counterpart of scripts/build.sh. It stages one complete tree per ABI into __build/android/<abi>/defaultlib, for --default-lib-path. libcurl is not part of Android, so HTTP is src/wrappers/http_stub.cpp: the same http_* functions, with every request failing, so fetch() throws and nothing links curl. Everything is position independent (Android executables are PIE), and the .so links libc++_shared.so. Verified by linking a program (class, assert, number to string, Date, async/await, fetch) with the NDK for both ABIs under gc, rc and none: it links against Bionic only (libc, libm, libdl). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
scripts/build_android.bat [abi] [release|debug] [gc|rc|none]builds the default library for Android API 29 on a Windows host with the Android NDK. It's the Android counterpart ofscripts/build.sh; with no arguments it builds every combination:arm64-v8aandx86_64, release and debug, gc/rc/none. For each ABI it stages one complete tree:A program for that ABI passes
--default-lib-path=__build/android/<abi>. The C++ wrappers are compiled with NDKclang++,lib.tsandlib.linux.tswithtslang -mtriple=<arch>-linux-android29, and both are archived with NDKllvm-ar.Differences from
build.sh:src/wrappers/http_stub.cpp: the samehttp_*functions ashttp_linux.cpp, with every request failing (errorCode -1), sofetch()throws. There's therefore no linker script pulling in-lcurl; the archive is the library itself..solinkslibc++_shared.so, which the app ships (Android allows one C++ runtime per app). Under gc,GC_*stay undefined in it on purpose, as inbuild.sh.API 29 is the floor:
lib.linux.tscallstimespec_get, which Android's libc has from 29 on. The README gets an Android section with a full compile-and-link example.Needs ASDAlexander77/TypeScriptCompiler#507 for the Android collector and async runtime (it fixes the standalone runtime project, which lacked
GC_enable_threads). It also needs atslangwith ASDAlexander77/TypeScriptCompiler#506 (TOOL_PATH, default: the compiler's release build tree). Tested with NDK r30.Verification
assert, number to string,Date,async/await,fetch) was linked with NDKclang++ -pie -static-libstdc++against these archives. That ran for both ABIs, under gc, rc and none (release), and gc (debug):libc,libmandlibdlonly;http_requestis linked in;GC_*..so's undefined symbols all resolve against the API 29 Bionic stubs, except two kinds:GC_*under gc, which is intended.memfd_create(API 30) on arm64. It comes from the NDK's ownlibclang_rt.builtins(aarch64.c.o), not from this library. Because it's weak, it resolves to null on 29.Noticed, not changed
lib.linux.tsdeclaresstruct tmas ninei32s (36 bytes), but it's 56 bytes on 64-bit Linux and Android (tm_gmtoff,tm_zone). Sogmtime_randlocaltime_rwrite past the tuple, on Linux too.fetcherror message says "WinHTTP" on every platform.🤖 Generated with Claude Code