#How do i configure `build.zig` to tell it to output shared libraries ?

1 messages · Page 1 of 1 (latest)

minor jolt
#

i'm here at the moment

const std = @import("std");

const targets: []const std.Target.Query = &.{
    .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .android },
    .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .android },
    .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .android },
};

pub fn build(b: *std.Build) !void {
    for (targets) |t| {
        
    }
}

i would like to eventually add ios and simulator but not sure how to do anything more here any help ?

minor jolt
#

i have this rn, i'm trying to compile it but i don;t think it will work:

const std = @import("std");

const targets: []const std.Target.Query = &.{
    .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .android },
    .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .android },
    .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .android },
};

pub fn build(b: *std.Build) !void {
    for (targets) |t| {
        const lib = b.addLibrary(.{
            .name = "hello",
            .linkage = .dynamic,
            .root_module = b.createModule(.{
                .root_source_file = b.path("hello.zig"),
                .target = b.resolveTargetQuery(t),
                .optimize = .ReleaseSafe,
            }),
        });

        b.installArtifact(lib);

        const target_output = b.addInstallArtifact(lib, .{
            .dest_dir = .{
                .override = .{
                    .custom = greet(t.cpu_arch.?),
                },
            },
        });

        b.getInstallStep().dependOn(&target_output.step);
    }
}

fn greet(arch: std.Target.Cpu.Arch) []const u8 {
    return switch (arch) {
        .x86_64 => "x86_64",
        .aarch64 => "arm64-v8a",
        .arm => "armeabi-v7a",
        else => "",
    };
}

test "greetTests" {
    try std.testing.expectEqual(greet(std.Target.Cpu.Arch.x86_64), "x86_64");
    try std.testing.expectEqual(greet(std.Target.Cpu.Arch.aarch64), "arm64-v8a");
    try std.testing.expectEqual(greet(std.Target.Cpu.Arch.arm), "armeabi-v7a");
}

#

it works 🥳