build: linux: fix building tests & cleanup build.zig logic
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
dc5c1f69a6
commit
b94462a918
1 changed files with 109 additions and 98 deletions
207
build.zig
207
build.zig
|
|
@ -102,7 +102,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
if (want_examples) try buildExamples(b, optimize, target, module);
|
if (want_examples) try buildExamples(b, optimize, target, module);
|
||||||
}
|
}
|
||||||
if (want_core) {
|
if (want_core) {
|
||||||
if (Platform.fromTarget(target.result) == .linux) {
|
if (target.result.os.tag == .linux) {
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = "core-wayland",
|
.name = "core-wayland",
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -113,36 +113,9 @@ pub fn build(b: *std.Build) !void {
|
||||||
});
|
});
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
module.linkLibrary(lib);
|
module.linkLibrary(lib);
|
||||||
|
addCoreDependencies(b, &lib.root_module);
|
||||||
if (b.lazyDependency("wayland_headers", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
})) |dep| {
|
|
||||||
lib.linkLibrary(dep.artifact("wayland-headers"));
|
|
||||||
module.linkLibrary(dep.artifact("wayland-headers"));
|
|
||||||
}
|
|
||||||
if (b.lazyDependency("x11_headers", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
})) |dep| {
|
|
||||||
module.linkLibrary(dep.artifact("x11-headers"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (target.result.isDarwin()) {
|
|
||||||
// TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
|
|
||||||
if (b.lazyDependency("xcode_frameworks", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
})) |dep| {
|
|
||||||
module.addSystemFrameworkPath(dep.path("Frameworks"));
|
|
||||||
module.addSystemIncludePath(dep.path("include"));
|
|
||||||
module.addLibraryPath(dep.path("lib"));
|
|
||||||
}
|
|
||||||
if (b.lazyDependency("mach_objc", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
})) |dep| module.addImport("objc", dep.module("mach-objc"));
|
|
||||||
}
|
}
|
||||||
|
addCoreDependencies(b, module);
|
||||||
}
|
}
|
||||||
if (want_sysaudio) {
|
if (want_sysaudio) {
|
||||||
// Can build sysaudio examples if desired, then.
|
// Can build sysaudio examples if desired, then.
|
||||||
|
|
@ -173,46 +146,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addSysaudioDependencies(b, module);
|
||||||
if (target.result.isDarwin()) {
|
|
||||||
module.linkFramework("AudioToolbox", .{});
|
|
||||||
module.linkFramework("CoreFoundation", .{});
|
|
||||||
module.linkFramework("CoreAudio", .{});
|
|
||||||
}
|
|
||||||
if (target.result.os.tag == .linux) {
|
|
||||||
module.link_libc = true;
|
|
||||||
|
|
||||||
// TODO: for some reason this is not functional, a Zig bug (only when using this Zig package
|
|
||||||
// externally):
|
|
||||||
//
|
|
||||||
// module.addCSourceFile(.{
|
|
||||||
// .file = b.path("src/sysaudio/pipewire/sysaudio.c"),
|
|
||||||
// .flags = &.{"-std=gnu99"},
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// error: unable to check cache: stat file '/Volumes/data/hexops/mach-flac/zig-cache//Volumes/data/hexops/mach-flac/src/pipewire/sysaudio.c' failed: FileNotFound
|
|
||||||
//
|
|
||||||
// So instead we do this:
|
|
||||||
const lib = b.addStaticLibrary(.{
|
|
||||||
.name = "sysaudio-pipewire",
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
lib.linkLibC();
|
|
||||||
lib.addCSourceFile(.{
|
|
||||||
.file = b.path("src/sysaudio/pipewire/sysaudio.c"),
|
|
||||||
.flags = &.{"-std=gnu99"},
|
|
||||||
});
|
|
||||||
module.linkLibrary(lib);
|
|
||||||
|
|
||||||
if (b.lazyDependency("linux_audio_headers", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
})) |dep| {
|
|
||||||
module.linkLibrary(dep.artifact("linux-audio-headers"));
|
|
||||||
lib.linkLibrary(dep.artifact("linux-audio-headers"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (want_sysgpu) {
|
if (want_sysgpu) {
|
||||||
if (b.lazyDependency("vulkan_zig_generated", .{})) |dep| module.addImport("vulkan", dep.module("vulkan-zig-generated"));
|
if (b.lazyDependency("vulkan_zig_generated", .{})) |dep| module.addImport("vulkan", dep.module("vulkan-zig-generated"));
|
||||||
|
|
@ -232,7 +166,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
})) |dep| module.addImport("objc", dep.module("mach-objc"));
|
})) |dep| module.addImport("objc", dep.module("mach-objc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
linkSysgpu(b, module);
|
addSysgpuDependencies(b, module);
|
||||||
|
|
||||||
if (want_libs) {
|
if (want_libs) {
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
|
|
@ -245,7 +179,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
while (iter.next()) |e| {
|
while (iter.next()) |e| {
|
||||||
lib.root_module.addImport(e.key_ptr.*, e.value_ptr.*);
|
lib.root_module.addImport(e.key_ptr.*, e.value_ptr.*);
|
||||||
}
|
}
|
||||||
linkSysgpu(b, &lib.root_module);
|
addSysgpuDependencies(b, &lib.root_module);
|
||||||
b.installArtifact(lib);
|
b.installArtifact(lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +206,9 @@ pub fn build(b: *std.Build) !void {
|
||||||
const test_step = b.step("test", "Run unit tests");
|
const test_step = b.step("test", "Run unit tests");
|
||||||
test_step.dependOn(&run_unit_tests.step);
|
test_step.dependOn(&run_unit_tests.step);
|
||||||
|
|
||||||
if (want_sysgpu) linkSysgpu(b, &unit_tests.root_module);
|
if (want_sysgpu) addSysgpuDependencies(b, &unit_tests.root_module);
|
||||||
|
if (want_core) addCoreDependencies(b, &unit_tests.root_module);
|
||||||
|
if (want_sysaudio) addSysaudioDependencies(b, &unit_tests.root_module);
|
||||||
|
|
||||||
// Documentation
|
// Documentation
|
||||||
const docs_obj = b.addObject(.{
|
const docs_obj = b.addObject(.{
|
||||||
|
|
@ -309,21 +245,29 @@ pub const Platform = enum {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn linkSysgpu(b: *std.Build, module: *std.Build.Module) void {
|
fn addSysgpuDependencies(b: *std.Build, module: *std.Build.Module) void {
|
||||||
const resolved_target = module.resolved_target orelse b.host;
|
const target = module.resolved_target orelse @panic("module must have .target specified");
|
||||||
const target = resolved_target.result;
|
const optimize = module.optimize orelse @panic("module must have .optimize specified");
|
||||||
if (target.cpu.arch != .wasm32) module.link_libc = true;
|
|
||||||
if (target.isDarwin()) {
|
if (target.result.os.tag == .linux) {
|
||||||
// TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
|
module.link_libc = true;
|
||||||
|
} else if (target.result.isDarwin()) {
|
||||||
|
// TODO(build): some of these dependencies are mach.Core dependencies, but this section
|
||||||
|
// 'should' only be sysgpu dependencies. We should declare sysgpu and mach.Core are
|
||||||
|
// inherently tied together probably and merge these two build options?
|
||||||
|
|
||||||
if (b.lazyDependency("xcode_frameworks", .{
|
if (b.lazyDependency("xcode_frameworks", .{
|
||||||
.target = resolved_target,
|
.target = target,
|
||||||
.optimize = module.optimize.?,
|
.optimize = optimize,
|
||||||
})) |dep| {
|
})) |dep| {
|
||||||
module.addSystemFrameworkPath(dep.path("Frameworks"));
|
module.addSystemFrameworkPath(dep.path("Frameworks"));
|
||||||
module.addSystemIncludePath(dep.path("include"));
|
module.addSystemIncludePath(dep.path("include"));
|
||||||
module.addLibraryPath(dep.path("lib"));
|
module.addLibraryPath(dep.path("lib"));
|
||||||
}
|
}
|
||||||
if (target.os.tag == .macos) {
|
|
||||||
|
if (target.result.os
|
||||||
|
.tag == .macos)
|
||||||
|
{
|
||||||
module.linkFramework("AppKit", .{});
|
module.linkFramework("AppKit", .{});
|
||||||
} else {
|
} else {
|
||||||
module.linkFramework("UIKit", .{});
|
module.linkFramework("UIKit", .{});
|
||||||
|
|
@ -332,33 +276,100 @@ fn linkSysgpu(b: *std.Build, module: *std.Build.Module) void {
|
||||||
module.linkFramework("Foundation", .{});
|
module.linkFramework("Foundation", .{});
|
||||||
module.linkFramework("Metal", .{});
|
module.linkFramework("Metal", .{});
|
||||||
module.linkFramework("QuartzCore", .{});
|
module.linkFramework("QuartzCore", .{});
|
||||||
}
|
} else if (target.result.os.tag == .windows) {
|
||||||
if (target.os.tag == .windows) {
|
// TODO(build): Windows should never link OpenGL except in debug builds.
|
||||||
module.linkSystemLibrary("d3d12", .{});
|
module.linkSystemLibrary("d3d12", .{});
|
||||||
module.linkSystemLibrary("d3dcompiler_47", .{});
|
module.linkSystemLibrary("d3dcompiler_47", .{});
|
||||||
module.linkSystemLibrary("opengl32", .{});
|
module.linkSystemLibrary("opengl32", .{});
|
||||||
if (b.lazyDependency("direct3d_headers", .{
|
if (b.lazyDependency("direct3d_headers", .{
|
||||||
.target = resolved_target,
|
.target = target,
|
||||||
.optimize = module.optimize.?,
|
.optimize = optimize,
|
||||||
})) |dep| {
|
})) |dep| {
|
||||||
module.linkLibrary(dep.artifact("direct3d-headers"));
|
module.linkLibrary(dep.artifact("direct3d-headers"));
|
||||||
@import("direct3d_headers").addLibraryPathToModule(module);
|
@import("direct3d_headers").addLibraryPathToModule(module);
|
||||||
}
|
}
|
||||||
if (b.lazyDependency("opengl_headers", .{
|
if (b.lazyDependency("opengl_headers", .{
|
||||||
.target = resolved_target,
|
.target = target,
|
||||||
.optimize = module.optimize.?,
|
.optimize = optimize,
|
||||||
})) |dep| module.linkLibrary(dep.artifact("opengl-headers"));
|
})) |dep| module.linkLibrary(dep.artifact("opengl-headers"));
|
||||||
}
|
}
|
||||||
if (target.cpu.arch != .wasm32) {
|
}
|
||||||
// TODO: spirv-cross / spirv-tools support
|
|
||||||
// if (b.lazyDependency("spirv_cross", .{
|
fn addCoreDependencies(b: *std.Build, module: *std.Build.Module) void {
|
||||||
// .target = resolved_target,
|
const target = module.resolved_target orelse @panic("module must have .target specified");
|
||||||
// .optimize = module.optimize.?,
|
const optimize = module.optimize orelse @panic("module must have .optimize specified");
|
||||||
// })) |dep| module.linkLibrary(dep.artifact("spirv-cross"));
|
|
||||||
// if (b.lazyDependency("spirv_tools", .{
|
if (target.result.os.tag == .linux) {
|
||||||
// .target = resolved_target,
|
if (b.lazyDependency("wayland_headers", .{
|
||||||
// .optimize = module.optimize.?,
|
.target = target,
|
||||||
// })) |dep| module.linkLibrary(dep.artifact("spirv-opt"));
|
.optimize = optimize,
|
||||||
|
})) |dep| {
|
||||||
|
module.linkLibrary(dep.artifact("wayland-headers"));
|
||||||
|
}
|
||||||
|
if (b.lazyDependency("x11_headers", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
})) |dep| {
|
||||||
|
module.linkLibrary(dep.artifact("x11-headers"));
|
||||||
|
}
|
||||||
|
} else if (target.result.isDarwin()) {
|
||||||
|
// TODO(build): determine if we need this after https://github.com/ziglang/zig/issues/21598 is fixed
|
||||||
|
if (b.lazyDependency("xcode_frameworks", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
})) |dep| {
|
||||||
|
module.addSystemFrameworkPath(dep.path("Frameworks"));
|
||||||
|
module.addSystemIncludePath(dep.path("include"));
|
||||||
|
module.addLibraryPath(dep.path("lib"));
|
||||||
|
}
|
||||||
|
if (b.lazyDependency("mach_objc", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
})) |dep| module.addImport("objc", dep.module("mach-objc"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn addSysaudioDependencies(b: *std.Build, module: *std.Build.Module) void {
|
||||||
|
const target = module.resolved_target orelse @panic("module must have .target specified");
|
||||||
|
const optimize = module.optimize orelse @panic("module must have .optimize specified");
|
||||||
|
|
||||||
|
if (target.result.os.tag == .linux) {
|
||||||
|
module.link_libc = true;
|
||||||
|
|
||||||
|
// TODO: for some reason this is not functional, a Zig bug (only when using this Zig package
|
||||||
|
// externally):
|
||||||
|
//
|
||||||
|
// module.addCSourceFile(.{
|
||||||
|
// .file = b.path("src/sysaudio/pipewire/sysaudio.c"),
|
||||||
|
// .flags = &.{"-std=gnu99"},
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// error: unable to check cache: stat file '/Volumes/data/hexops/mach-flac/zig-cache//Volumes/data/hexops/mach-flac/src/pipewire/sysaudio.c' failed: FileNotFound
|
||||||
|
//
|
||||||
|
// So instead we do this:
|
||||||
|
const lib = b.addStaticLibrary(.{
|
||||||
|
.name = "sysaudio-pipewire",
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
lib.linkLibC();
|
||||||
|
lib.addCSourceFile(.{
|
||||||
|
.file = b.path("src/sysaudio/pipewire/sysaudio.c"),
|
||||||
|
.flags = &.{"-std=gnu99"},
|
||||||
|
});
|
||||||
|
module.linkLibrary(lib);
|
||||||
|
|
||||||
|
if (b.lazyDependency("linux_audio_headers", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
})) |dep| {
|
||||||
|
module.linkLibrary(dep.artifact("linux-audio-headers"));
|
||||||
|
lib.linkLibrary(dep.artifact("linux-audio-headers"));
|
||||||
|
}
|
||||||
|
} else if (target.result.isDarwin()) {
|
||||||
|
module.linkFramework("AudioToolbox", .{});
|
||||||
|
module.linkFramework("CoreFoundation", .{});
|
||||||
|
module.linkFramework("CoreAudio", .{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue