No longer able to build using android abi

I have this build.zig (created with zig init)

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const mod = b.addModule("afac", .{
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = optimize,
    });

    const lib = b.addLibrary(.{
        .name = "root",
        .linkage = .dynamic,
        .root_module = mod,
    });
    // this doesn't do anything
    // lib.root_module.link_libc = true;
    b.installArtifact(lib);
}

This builds fine (I get a working library for Android):

zig version # 0.15.0-dev.1408+9b509dad3
zig build -Dtarget=aarch64-linux-android

However, from zig 0.15.0-dev.1427+3de8bbd3d onwards, I get this error:

install
└─ install root
   └─ compile lib root Debug aarch64-linux-android failure
error: error: unable to find or provide libc for target 'aarch64-linux.5.10...6.16-android.24'
info: zig can provide libc for related target aarch64-linux.3.7.0-gnu.2.17
info: zig can provide libc for related target aarch64-linux.3.7.0-musl

error: the following command exited with error code 1:
/usr/lib/zig/zig build-lib -ODebug -target aarch64-linux-android -mcpu baseline -Mroot=/tmp/afac/src/root.zig --cache-dir .zig-cache --global-cache-dir /home/adria/.cache/zig --name root -dynamic --zig-lib-dir /usr/lib/zig/lib/ --listen=-

Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install root transitive failure
   └─ compile lib root Debug aarch64-linux-android failure

error: the following build command failed with exit code 1:
.zig-cache/o/3fe6be82f61c12241edbe536d62ba78b/build /usr/lib/zig/zig /usr/lib/zig/lib /tmp/afac .zig-cache /home/adria/.cache/zig --seed 0x5b9b4642 -Z9538a903bb6a75ff -Dtarget=aarch64-linux-android

Should I specify a libc manually now?

Actually, using the target triple aarch64-linux-musl makes it work on Android, too. But I am confused, what happened?

You’ll need to either specify an Android API level >= 29, i.e. aarch64-linux-android.29, or provide a libc.txt pointing to Bionic libc binaries from the NDK for older versions. (You’ll have to do the latter in any case if you want to link libc for any reason, as Zig does not currently provide Bionic when cross-compiling.)

2 Likes
1 Like

Thank you! I was reading the latest commits, I didn’t think you’d reply so fast.

My android app targets api 29 anyways, so this works:

b.resolveTargetQuery(.{
    .os_tag = .linux,
    .cpu_arch = .aarch64,
    .abi = .android,
    .android_api_level = 29,
})

I don’t require linking to libc, so, in my cases, both approaches work. I wonder which one should I use.

If you don’t need libc, then this seems reasonable to me.

1 Like

Thank you!