How to build zig for target mips-linux-musl with soft float?

I try to build a app for target mips-linux-musl with soft float by zig 0.11.0. The below build script can not work.

    var target = b.standardTargetOptions(.{});
    const Features = std.Target.mips.Feature;

    target.cpu_features_add.addFeature(@intFromEnum(Features.soft_float));

Hello @mythfish Welcome to the forum :slight_smile:

const target = b.resolveTargetQuery(.{
    .cpu_arch = .mips,
    .os_tag = .linux,
    .abi = .musl,
    .cpu_features_add = std.Target.mips.featureSet(&[_]std.target.mips.Feature{
        .mips32, // select CPU model from mips1-5, mips32, mips32r2-6, etc.
        .soft_float,
        // more mips features here
    }),
});

const exe = b.addExecutable(.{
    // ...
    .target = target,
    // ...
});

see also: mips features and all mips features names and descriptions

@dimdin thanks for you suggestion. But still not work, I don’t known if it is caused by the dynamic link.

    const target = b.resolveTargetQuery(.{
        .cpu_arch = .mips,
        .os_tag = .linux,
        .abi = .musl,
        .cpu_features_add = std.Target.mips.featureSet(&[_]std.Target.mips.Feature{
            .mips32, // select CPU model from mips1-5, mips32, mips32r2-6, etc.
            .soft_float,
            // more mips features here
        }),
    });

    const exe = b.addExecutable(.{
        .name = "zig_demo",
        // In this case the main source file is merely a path, however, in more
        // complicated build scripts, this could be a generated file.
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .linkage = .dynamic,
        .optimize = optimize,
    });

    exe.linkLibC();
zig-out/bin/zig_demo: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips.so.1, stripped

Yes, you need to static link with musl.