Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
zig-version: [master]
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
Copy link
Contributor

@MasonRemaley MasonRemaley Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I've set the YAML up here is a bit confusing. This list you've updated here is the list of operating systems the tests run on, however the actual tests also need to be updated.

Right now they look like this:

- name: Build for Windows
  run: zig build example -Dtarget=x86_64-windows-gnu --summary all

- name: Build for Linux
  run: zig build example -Dtarget=x86_64-linux-gnu --summary all

The first one attempts to cross compile to Windows from the host platform, the second attempts to cross compile to Linux from the host platform. If the macOS config is able to be used as a cross compile target, then all you need to do is add it to the above list as well and cross compilation to a macOS app will be tested on all three platforms.

That's the ideal scenario, I'd like to achieve it if possible. OTOH if this is impossible (e.g. maybe it requires sharing files that Apple forbids us from sharing) then the macOS test can just be made conditional to only run on macOS. I'm not an expert on GitHub's CI, but I'm guessing there's a way to wrap it in an if statement or something.

Copy link
Author

@garettbass garettbass Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, it is possible to cross compile to macOS from Linux or Windows. I was able to make a proof of concept of that on another branch by placing the necessary MacOSX.sdk in the repo's deps directory. I tested by cross compiling from my Steam Deck's linux desktop. It is more difficult for me to test on Windows right now, so I haven't tried there yet.

Based on the wording of the Mac SDK license, I'm not sure we're allowed to use the SDK on non-apple branded hardware, so it may be legally troublesome even though it is technically simple.

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -35,3 +35,7 @@ jobs:

- name: Build for Linux
run: zig build example -Dtarget=x86_64-linux-gnu --summary all

- name: Build for macOS
if: runner.os == 'macOS' # TODO: macOS frameworks on Windows/Linux?
run: zig build example -Dtarget=aarch64-macos --summary all
26 changes: 26 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const linux = @import("src/linux.zig");
const macos = @import("src/macos.zig");
const windows = @import("src/windows.zig");
const build_zon = @import("build.zig.zon");

Expand Down Expand Up @@ -106,6 +107,7 @@ pub fn build(b: *std.Build) !void {
// Configure the build for the target platform
switch (target.result.os.tag) {
.linux => linux.build(b, target.result, lib, build_config_h),
.macos => macos.build(b, target.result, lib, build_config_h),
.windows => windows.build(b, target.result, lib, build_config_h),
else => @panic("target has no default config"),
}
Expand All @@ -125,6 +127,30 @@ pub fn build(b: *std.Build) !void {
});
example.linkLibrary(lib);

// Inherit platform-specific include paths from lib.
// This is necessary on macOS because the example executable needs to
// include and link with these frameworks.
for (lib.root_module.include_dirs.items) |include_dir| {
switch (include_dir) {
.path => |path| {
example.addIncludePath(path);
},
.path_system => |path_system| {
example.addSystemIncludePath(path_system);
},
.path_after => |path_after| {
example.addAfterIncludePath(path_after);
},
.framework_path_system => |framework_path_system| {
example.addSystemFrameworkPath(framework_path_system);
},
.framework_path => |framework_path| {
example.addFrameworkPath(framework_path);
},
else => {},
}
}

const build_example_step = b.step("example", "Build the example app");
build_example_step.dependOn(&example.step);

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .sdl,
.fingerprint = 0xec638ccbd103848b,
.version = "0.0.0",
.minimum_zig_version = "0.15.0-dev.1218+bc8e1a74c",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is ok, my VSCode toolchain for zig couldn't locate the specific dev version

.minimum_zig_version = "0.15.1",
.dependencies = .{
.sdl = .{
.url = "https://github.com/libsdl-org/SDL/archive/refs/tags/release-3.2.22.tar.gz",
Expand Down
2 changes: 2 additions & 0 deletions src/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ pub fn build(
.HAVE_LIBDECOR_H = 1,
.HAVE_LIBURING_H = 1,

.HAVE_SIGTIMEDWAIT = 1,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to cross compile from macOS to linux, nor natively compile on Steam Deck without adding this. I got a compile error caused by SDL's static declaration of sigtimedwait() conflicting with the previous non-static declaration.


.USE_POSIX_SPAWN = 1,

// Enable various audio drivers
Expand Down
Loading