fengb / fengb/zig-wii

Update build.zig to support 0.11

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Zig
Stars
35
Forks
3
PR merge metrics
No merged PRs in 30d

Description

**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**

```zig
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);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.