fixup --sysroot for cross-compile - #4
Conversation
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
|
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. |
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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?
| 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; |
There was a problem hiding this comment.
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).
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!