Skip to content

Commit

Permalink
updated to zig v0.13.0/v0.14.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Aug 25, 2024
1 parent bd8a0be commit 6f59071
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ jobs:
target: [x86_64, x86, aarch64]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
- uses: baptiste0928/cargo-install@v2
with:
crate: xwin
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Cargo.lock
*.pdb

# Zig build
zig-cache/
zig-out/
*zig-*/

# Xwin Unpack
.xwin/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This experiment is for testing purposes only. Possibly to make it easier to buil
## Requirements

- [xwin](https://github.com/Jake-Shadle/xwin)
- [zig 0.11 or higher](https://ziglang.org/download)
- [zig 0.13.x or higher](https://ziglang.org/download)

## Testing

Expand Down
53 changes: 29 additions & 24 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,35 @@ fn buildExe(b: *std.Build, info: BuildInfo) void {
// zig w/ msvc no has libcxx support
// https://github.com/ziglang/zig/issues/5312
.cpp => {
exe.addCSourceFile(.{ .file = .{ .path = info.filepath }, .flags = &.{
"-Wall",
"-Wextra",
} });
exe.addCSourceFile(.{
.file = b.path(info.filepath),
.flags = &.{
"-Wall",
"-Wextra",
},
});
exe.want_lto = false;
if (exe.target.getAbi() == .msvc) {
if (exe.rootModuleTarget().abi == .msvc) {
xWin(b, exe);
exe.linkLibC();
} else {
exe.linkLibCpp();
}
},
.c => {
exe.addCSourceFile(.{ .file = .{ .path = info.filepath }, .flags = &.{
"-Wall",
"-Wextra",
} });
if (exe.target.getAbi() == .msvc) {
exe.addCSourceFile(.{
.file = b.path(info.filepath),
.flags = &.{
"-Wall",
"-Wextra",
},
});
if (exe.rootModuleTarget().abi == .msvc) {
xWin(b, exe);
}
exe.linkLibC();
},
.zig => exe.root_src = .{ .path = info.filepath },
.zig => exe.root_module.root_source_file = b.path(info.filepath),
}
b.installArtifact(exe);

Expand All @@ -81,7 +87,7 @@ const BuildInfo = struct {
cpp,
zig,
},
target: std.zig.CrossTarget,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,

fn filename(self: BuildInfo) []const u8 {
Expand All @@ -90,25 +96,24 @@ const BuildInfo = struct {
}
};
fn xWin(b: *std.Build, exe: *std.Build.Step.Compile) void {
const target = (std.zig.system.NativeTargetInfo.detect(exe.target) catch unreachable).target;
const arch: []const u8 = switch (target.cpu.arch) {
const arch: []const u8 = switch (exe.rootModuleTarget().cpu.arch) {
.x86_64 => "x64",
.x86 => "x86",
.arm, .armeb => "arm",
.aarch64 => "arm64",
else => @panic("Unsupported Architecture"),
};

exe.setLibCFile(.{ .path = sdkPath("/libc.txt") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/crt/include") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/sdk/include") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/sdk/include/10.0.22000/cppwinrt") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/sdk/include/10.0.22000/ucrt") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/sdk/include/10.0.22000/um") });
exe.addSystemIncludePath(.{ .path = sdkPath("/.xwin/sdk/include/10.0.22000/shared") });
exe.addLibraryPath(.{ .path = b.fmt(sdkPath("/.xwin/crt/lib/{s}"), .{arch}) });
exe.addLibraryPath(.{ .path = b.fmt(sdkPath("/.xwin/sdk/lib/ucrt/{s}"), .{arch}) });
exe.addLibraryPath(.{ .path = b.fmt(sdkPath("/.xwin/sdk/lib/um/{s}"), .{arch}) });
exe.setLibCFile(.{ .cwd_relative = sdkPath("/libc.txt") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/crt/include") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/sdk/include") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/sdk/include/10.0.26100/cppwinrt") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/sdk/include/10.0.26100/ucrt") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/sdk/include/10.0.26100/um") });
exe.addSystemIncludePath(.{ .cwd_relative = sdkPath("/.xwin/sdk/include/10.0.26100/shared") });
exe.addLibraryPath(.{ .cwd_relative = b.fmt(sdkPath("/.xwin/crt/lib/{s}"), .{arch}) });
exe.addLibraryPath(.{ .cwd_relative = b.fmt(sdkPath("/.xwin/sdk/lib/ucrt/{s}"), .{arch}) });
exe.addLibraryPath(.{ .cwd_relative = b.fmt(sdkPath("/.xwin/sdk/lib/um/{s}"), .{arch}) });
}
fn sdkPath(comptime suffix: []const u8) []const u8 {
if (suffix[0] != '/') @compileError("relToPath requires an absolute path!");
Expand Down

0 comments on commit 6f59071

Please sign in to comment.