Zig: allow environment variables in `libc.txt`

Created on 27 Sep 2019  路  4Comments  路  Source: ziglang/zig

include_dir=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
sys_include_dir=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
static_crt_dir=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/
crt_dir=/opt/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21

msvc_lib_dir=
kernel32_lib_dir=

is particularly annoying for developers, would be nice if we could do:

include_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
sys_include_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
static_crt_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/
crt_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21

msvc_lib_dir=
kernel32_lib_dir=

so that ANDROID_NDK can be set during the zig build-exe ... --libc libc.txt process

proposal

Most helpful comment

I would love to solve this particular use case (android) in an even more satisfying way. What if zig could provide the android libc out of the box, like it already does for musl, glibc, and mingw-w64? Then you wouldn't have to provide a libc.txt file at all.

All 4 comments

This would indeed be quite helpful, and especially so for the Android NDK case.

I would love to solve this particular use case (android) in an even more satisfying way. What if zig could provide the android libc out of the box, like it already does for musl, glibc, and mingw-w64? Then you wouldn't have to provide a libc.txt file at all.

Bionic (Android's libc variant) is unfortunately VERY tied up with the rest of the Android build system. I am not familiar with how Zig builds glibc and musl, but we'd effectively need to pull out all the code and rewrite the entire build system. Still, I think this has a big benefit~ so perhaps we should split this off into another issue.

I would love to solve this particular use case (android) in an even more satisfying way. What if zig could provide the android libc out of the box, like it already does for musl, glibc, and mingw-w64? Then you wouldn't have to provide a libc.txt file at all.

FYI, here's my workaround for how I'm currently building native libraries for Android using Zig, even lacking environment variable expansion for libc.txt .

This following libc.txt configuration supports ARM on Android 4.1+ (API level 16+):

include_dir=3rdparty/android/sysroot/usr/include
sys_include_dir=3rdparty/android/sysroot/usr/include
crt_dir=3rdparty/android/sysroot/usr/lib/arm-linux-androideabi/16
msvc_lib_dir=
kernel32_lib_dir=

Then in the root of the Zig project, symlink 3rdparty/android/sysroot to the Android NDK's sysroot (note that the symlink target is system-specific, and I'm on a Mac):

mkdir -p 3rdparty/android
ln -s $HOME/Library/Android/sdk/ndk/21.2.6472646/toolchains/llvm/prebuilt/darwin-x86_64/sysroot 3rdparty/android/sysroot
Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewrk picture andrewrk  路  3Comments

andrewrk picture andrewrk  路  3Comments

jorangreef picture jorangreef  路  3Comments

bronze1man picture bronze1man  路  3Comments

andrewrk picture andrewrk  路  3Comments