Skip to content

Build the default library for Android - #22

Merged
ASDAlexander77 merged 2 commits into
mainfrom
android-build
Oct 5, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
android-build

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

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 of scripts/build.sh; with no arguments it builds every combination: arm64-v8a and x86_64, release and debug, gc/rc/none. For each ABI it stages one complete tree:

__build/android/<abi>/defaultlib/lib/<mode>/<model>/libTypeScriptDefaultLib.a
__build/android/<abi>/defaultlib/dll/<mode>/<model>/libTypeScriptDefaultLib.so
__build/android/<abi>/defaultlib/*.d.ts ...

A program for that ABI passes --default-lib-path=__build/android/<abi>. The C++ wrappers are compiled with NDK clang++, lib.ts and lib.linux.ts with tslang -mtriple=<arch>-linux-android29, and both are archived with NDK llvm-ar.

Differences from build.sh:

  • No curl. Android has no libcurl, so HTTP is the new src/wrappers/http_stub.cpp: the same http_* functions as http_linux.cpp, with every request failing (errorCode -1), so fetch() throws. There's therefore no linker script pulling in -lcurl; the archive is the library itself.
  • Everything is PIC, the archive too: Android executables must be PIE.
  • The .so links libc++_shared.so, which the app ships (Android allows one C++ runtime per app). Under gc, GC_* stay undefined in it on purpose, as in build.sh.

API 29 is the floor: lib.linux.ts calls timespec_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 a tslang with ASDAlexander77/TypeScriptCompiler#506 (TOOL_PATH, default: the compiler's release build tree). Tested with NDK r30.

Verification

  • All 12 configurations build.
  • A test program (class, assert, number to string, Date, async/await, fetch) was linked with NDK clang++ -pie -static-libstdc++ against these archives. That ran for both ABIs, under gc, rc and none (release), and gc (debug):
    • all 8 link;
    • the dynamic dependencies are libc, libm and libdl only;
    • the stub http_request is linked in;
    • rc and none contain no GC_*.
  • The .so's undefined symbols all resolve against the API 29 Bionic stubs, except two kinds:
    • GC_* under gc, which is intended.
    • A weak memfd_create (API 30) on arm64. It comes from the NDK's own libclang_rt.builtins (aarch64.c.o), not from this library. Because it's weak, it resolves to null on 29.
  • Link-only: no Android device or emulator was available, so nothing has been run.

Noticed, not changed

  • lib.linux.ts declares struct tm as nine i32s (36 bytes), but it's 56 bytes on 64-bit Linux and Android (tm_gmtoff, tm_zone). So gmtime_r and localtime_r write past the tuple, on Linux too.
  • The fetch error message says "WinHTTP" on every platform.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 5, 2026 13:35
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>
@ASDAlexander77
ASDAlexander77 merged commit 7536799 into main Oct 5, 2026
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.

1 participant