Skip to content

fixup --sysroot for cross-compile - #4

Merged
bandithedoge merged 2 commits into
bandithedoge:mainfrom
nat3Github:main
Sep 7, 2026
Merged

bandithedoge merged 2 commits into
bandithedoge:mainfrom
nat3Github:main

Conversation

@nat3Github

@nat3Github nat3Github commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

follow up to #2

you could verify setting up ci for cross compiling i.e. ubuntu machine to mac or mac machine to linux with --sysroot. just tell me if you need help with that!

forks: without explicit -F/-I paths derived from --sysroot, framework
headers like Cocoa/CoreVideo can't be found when cross-compiling from
a non-macOS host.

lean-deps: Linux sysroot cross-compile options for X11/GL

fixup cross compiling with --sysroot
@nat3Github nat3Github changed the title wire up --sysroot for cross-compile (frameworks + include) fixup --sysroot for cross-compile Sep 6, 2026
@bandithedoge

Copy link
Copy Markdown
Owner

Thanks! I'm able to cross-compile for macOS locally by pointing --sysroot at https://github.com/ypsvlq/wio-macos-sdk. Not sure if that's the best way to do it in CI. I might need help with testing the other way round, though.

Comment thread build.zig Outdated
Comment on lines +80 to +89
if (cross_linux) {
const include_path = b.option(std.Build.LazyPath, "system_include_path", "Linux sysroot include path (for cross-compiling to Linux)");
const library_path = b.option(std.Build.LazyPath, "library_path", "Linux sysroot library path (for cross-compiling to Linux)");
if (include_path) |p| pugl.addSystemIncludePath(p);
if (library_path) |p| pugl.addLibraryPath(p);
if (include_path == null or library_path == null) {
std.debug.print("error: cross-compiling to Linux requires -Dsystem_include_path and -Dlibrary_path pointing at a Linux sysroot's usr/include and usr/lib (X11/GL headers+libs)\n", .{});
std.process.exit(1);
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not sure about making the user supply two separate paths for both headers and libs. Why not just rely on --sysroot like in the macOS case?

Comment thread build.zig Outdated
pugl.linkSystemLibrary("X11", .{});
pugl.linkSystemLibrary("Xrender", .{});
const cross_linux = builtin.os.tag != .linux;
const use_pkg_config: std.Build.Module.SystemLib.UsePkgConfig = if (cross_linux) .no else .yes;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Zig honors the PKG_CONFIG environment variable, so with a cross pkg-config binary the build system should find the right libraries for the cross target. Seems better to rely on that instead of disabling pkg-config everywhere when cross-compiling (or at least make this behavior overridable, although I'm skeptical about adding yet another build option/system integration).

@bandithedoge
bandithedoge merged commit 12e1bec into bandithedoge:main Sep 7, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants