Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build.zig to support 0.11 #4

Open
silbinarywolf opened this issue Jun 18, 2023 · 0 comments
Open

Update build.zig to support 0.11 #4

silbinarywolf opened this issue Jun 18, 2023 · 0 comments

Comments

@silbinarywolf
Copy link

The issue

From what I can tell there was seemingly nothing to set the build path for the obj file in 0.11. After digging around and trying to figure out how to get this working, I discovered this solution that works with 0.11.

Version

0.11.0-dev.3394+c842deea7

Code

const std = @import("std");
const Builder = std.build.Builder;

pub fn build(b: *Builder) void {
    const obj = b.addObject(.{
        .name = "wiimain",
        .root_source_file = .{
            .path = "src/main.zig",
        },
        .optimize = b.standardOptimizeOption(.{}),
        .target = .{
            .cpu_arch = .powerpc,
            .os_tag = .freestanding,
            .abi = .eabi,
            .cpu_model = .{ .explicit = &std.Target.powerpc.cpu.@"750" },
            .cpu_features_add = std.Target.powerpc.featureSet(&.{.hard_float}),
        },
        .link_libc = true,
    });
    obj.setLibCFile(std.build.FileSource{ .path = "libc.txt" });
    obj.addIncludePath("vendor/devkitpro/libogc/include");

    const devkitFolder = "C:/devkitPro"; // Change this to wherever you've installed devKitPro
    const elf = b.addSystemCommand(&[_][]const u8{devkitFolder ++ "/devkitPPC/bin/powerpc-eabi-gcc"});
    elf.addFileSourceArg(obj.getOutputSource()); // add argument to "wiimain.o" that'll be somewhere in zig-cache
    elf.addArgs(&[_][]const u8{ "-g", "-DGEKKO", "-mrvl", "-mcpu=750", "-meabi", "-mhard-float", "-Wl,-Map,zig-out/.map", "-L" ++ devkitFolder ++ "/libogc/lib/wii", "-lwiiuse", "-lbte", "-logc", "-lm", "-o", "zig-out/zig-wii.elf" });
    const dol = b.addSystemCommand(&[_][]const u8{ devkitFolder ++ "/tools/bin/elf2dol", "zig-out/zig-wii.elf", "zig-out/zig-wii.dol" });
    b.default_step.dependOn(&dol.step);
    dol.step.dependOn(&elf.step);
    elf.step.dependOn(&obj.step);
}
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

No branches or pull requests

1 participant