diff --git a/libs/basisu/build.zig b/libs/basisu/build.zig index f2f9b2aa..3be7dbbc 100644 --- a/libs/basisu/build.zig +++ b/libs/basisu/build.zig @@ -24,27 +24,27 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget main_tests.setTarget(target); main_tests.main_pkg_path = thisDir(); link(b, main_tests, .{ - .encoder = true, - .transcoder = true, + .encoder = .{}, + .transcoder = .{}, }); main_tests.install(); return main_tests.run(); } pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - if (options.encoder) { - step.linkLibrary(buildEncoder(b)); + if (options.encoder) |encoder_options| { + step.linkLibrary(buildEncoder(b, encoder_options)); step.addCSourceFile(comptime thisDir() ++ "/src/encoder/wrapper.cpp", &.{}); step.addIncludePath(basisu_root ++ "/encoder"); } - if (options.transcoder) { - step.linkLibrary(buildTranscoder(b)); + if (options.transcoder) |transcoder_options| { + step.linkLibrary(buildTranscoder(b, transcoder_options)); step.addCSourceFile(comptime thisDir() ++ "/src/transcoder/wrapper.cpp", &.{}); step.addIncludePath(basisu_root ++ "/transcoder"); } } -pub fn buildEncoder(b: *Builder) *std.build.LibExeObjStep { +pub fn buildEncoder(b: *Builder, options: EncoderOptions) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; @@ -54,14 +54,15 @@ pub fn buildEncoder(b: *Builder) *std.build.LibExeObjStep { encoder_sources, &.{}, ); - encoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0"); encoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0"); - encoder.install(); + + if (options.install_libs) + encoder.install(); return encoder; } -pub fn buildTranscoder(b: *Builder) *std.build.LibExeObjStep { +pub fn buildTranscoder(b: *Builder, options: TranscoderOptions) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; @@ -71,16 +72,25 @@ pub fn buildTranscoder(b: *Builder) *std.build.LibExeObjStep { transcoder_sources, &.{}, ); - transcoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0"); transcoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0"); - transcoder.install(); + + if (options.install_libs) + transcoder.install(); return transcoder; } pub const Options = struct { - encoder: bool, - transcoder: bool, + encoder: ?EncoderOptions, + transcoder: ?TranscoderOptions, +}; + +pub const EncoderOptions = struct { + install_libs: bool = false, +}; + +pub const TranscoderOptions = struct { + install_libs: bool = false, }; fn thisDir() []const u8 { diff --git a/libs/freetype/build.zig b/libs/freetype/build.zig index a6eb1be3..59eb37f0 100644 --- a/libs/freetype/build.zig +++ b/libs/freetype/build.zig @@ -7,11 +7,6 @@ const hb_root = thisDir() ++ "/upstream/harfbuzz"; const hb_include_path = hb_root ++ "/src"; const brotli_root = thisDir() ++ "/upstream/brotli"; -const c_pkg = std.build.Pkg{ - .name = "c", - .source = .{ .path = thisDir() ++ "/src/c.zig" }, -}; - const utils_pkg = std.build.Pkg{ .name = "utils", .source = .{ .path = thisDir() ++ "/src/utils.zig" }, @@ -20,13 +15,13 @@ const utils_pkg = std.build.Pkg{ pub const pkg = std.build.Pkg{ .name = "freetype", .source = .{ .path = thisDir() ++ "/src/main.zig" }, - .dependencies = &.{ c_pkg, utils_pkg }, + .dependencies = &.{utils_pkg}, }; pub const harfbuzz_pkg = std.build.Pkg{ .name = "harfbuzz", .source = .{ .path = thisDir() ++ "/src/harfbuzz/main.zig" }, - .dependencies = &.{ c_pkg, utils_pkg, pkg }, + .dependencies = &.{ utils_pkg, pkg }, }; pub const Options = struct { @@ -37,22 +32,19 @@ pub const Options = struct { pub const FreetypeOptions = struct { /// the path you specify freetype options /// via `ftoptions.h` and `ftmodule.h` - ft_config_path: ?[]const u8 = null, + config_path: ?[]const u8 = null, + install_libs: bool = false, brotli: bool = false, }; -pub const HarfbuzzOptions = struct {}; +pub const HarfbuzzOptions = struct { + install_libs: bool = false, +}; pub fn build(b: *std.build.Builder) !void { const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{}); - const test_app = b.addStaticLibrary("test_app", null); - test_app.setBuildMode(mode); - test_app.setTarget(target); - link(b, test_app, .{ .freetype = .{ .brotli = true } }); - test_app.install(); - const test_step = b.step("test", "Run library tests"); test_step.dependOn(&testStep(b, mode, target).step); @@ -65,9 +57,6 @@ pub fn build(b: *std.build.Builder) !void { example_exe.setTarget(target); example_exe.addPackage(pkg); - // Remove once the stage2 compiler fixes pkg std not found - example_exe.addPackage(utils_pkg); - link(b, example_exe, .{}); const example_install = b.addInstallArtifact(example_exe); @@ -89,11 +78,6 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget const main_tests = b.addTestExe("freetype-tests", (comptime thisDir()) ++ "/src/main.zig"); main_tests.setBuildMode(mode); main_tests.setTarget(target); - main_tests.addPackage(c_pkg); - - // Remove once the stage2 compiler fixes pkg std not found - main_tests.addPackage(utils_pkg); - main_tests.addPackage(pkg); link(b, main_tests, .{ .freetype = .{ @@ -103,88 +87,111 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget }); main_tests.main_pkg_path = (comptime thisDir()); main_tests.install(); + + const harfbuzz_tests = b.addTestExe("harfbuzz-tests", (comptime thisDir()) ++ "/src/harfbuzz/main.zig"); + harfbuzz_tests.setBuildMode(mode); + harfbuzz_tests.setTarget(target); + harfbuzz_tests.addPackage(utils_pkg); + harfbuzz_tests.addPackage(pkg); + link(b, harfbuzz_tests, .{ + .freetype = .{ + .brotli = true, + }, + .harfbuzz = .{}, + }); + harfbuzz_tests.main_pkg_path = (comptime thisDir()); + harfbuzz_tests.install(); + + main_tests.step.dependOn(&harfbuzz_tests.run().step); return main_tests.run(); } pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - const ft_lib = buildFreetype(b, step, options.freetype); + linkFreetype(b, step, options.freetype); + if (options.harfbuzz) |harfbuzz_options| + linkHarfbuzz(b, step, harfbuzz_options); +} + +pub fn linkFreetype(b: *Builder, step: *std.build.LibExeObjStep, options: FreetypeOptions) void { + const ft_lib = buildFreetype(b, step.build_mode, step.target, options); step.linkLibrary(ft_lib); step.addIncludePath(ft_include_path); - step.addIncludePath(hb_include_path); - - if (options.harfbuzz) |hb_options| { - const hb_lib = buildHarfbuzz(b, step, hb_options); - step.linkLibrary(hb_lib); + if (options.brotli) { + const brotli_lib = buildBrotli(b, step.build_mode, step.target); + if (options.install_libs) + brotli_lib.install(); + step.linkLibrary(brotli_lib); } } -pub fn buildFreetype(b: *Builder, step: *std.build.LibExeObjStep, options: FreetypeOptions) *std.build.LibExeObjStep { +pub fn linkHarfbuzz(b: *Builder, step: *std.build.LibExeObjStep, options: HarfbuzzOptions) void { + const hb_lib = buildHarfbuzz(b, step.build_mode, step.target, options); + step.linkLibrary(hb_lib); + step.addIncludePath(hb_include_path); +} + +pub fn buildFreetype(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: FreetypeOptions) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; - const main_abs = ft_root ++ "/src/base/ftbase.c"; - const lib = b.addStaticLibrary("freetype", main_abs); + const lib = b.addStaticLibrary("freetype", null); lib.defineCMacro("FT2_BUILD_LIBRARY", "1"); - lib.setBuildMode(step.build_mode); - lib.setTarget(step.target); + lib.setBuildMode(mode); + lib.setTarget(target); lib.linkLibC(); lib.addIncludePath(ft_include_path); - if (options.ft_config_path) |path| + if (options.config_path) |path| lib.addIncludePath(path); - if (options.brotli) { - const brotli_lib = buildBrotli(b, step); - step.linkLibrary(brotli_lib); + if (options.brotli) lib.defineCMacro("FT_REQUIRE_BROTLI", "1"); - } - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; + const target_info = (std.zig.system.NativeTargetInfo.detect(b.allocator, target) catch unreachable).target; - if (target.os.tag == .windows) { + if (target_info.os.tag == .windows) { lib.addCSourceFile(ft_root ++ "/builds/windows/ftsystem.c", &.{}); lib.addCSourceFile(ft_root ++ "/builds/windows/ftdebug.c", &.{}); } else { lib.addCSourceFile(ft_root ++ "/src/base/ftsystem.c", &.{}); lib.addCSourceFile(ft_root ++ "/src/base/ftdebug.c", &.{}); } - if (target.os.tag.isBSD() or target.os.tag == .linux) { + if (target_info.os.tag.isBSD() or target_info.os.tag == .linux) { lib.defineCMacro("HAVE_UNISTD_H", "1"); lib.defineCMacro("HAVE_FCNTL_H", "1"); lib.addCSourceFile(ft_root ++ "/builds/unix/ftsystem.c", &.{}); - if (target.os.tag == .macos) { + if (target_info.os.tag == .macos) lib.addCSourceFile(ft_root ++ "/src/base/ftmac.c", &.{}); - } } - lib.addCSourceFiles(freetype_base_sources, &.{}); - lib.install(); + + if (options.install_libs) + lib.install(); return lib; } -pub fn buildHarfbuzz(b: *Builder, step: *std.build.LibExeObjStep, options: HarfbuzzOptions) *std.build.LibExeObjStep { - _ = options; +pub fn buildHarfbuzz(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: HarfbuzzOptions) *std.build.LibExeObjStep { const main_abs = hb_root ++ "/src/harfbuzz.cc"; const lib = b.addStaticLibrary("harfbuzz", main_abs); - lib.setBuildMode(step.build_mode); - lib.setTarget(step.target); + lib.setBuildMode(mode); + lib.setTarget(target); lib.linkLibCpp(); lib.addIncludePath(hb_include_path); lib.addIncludePath(ft_include_path); lib.defineCMacro("HAVE_FREETYPE", "1"); - lib.install(); + + if (options.install_libs) + lib.install(); return lib; } -pub fn buildBrotli(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep { - const main_abs = brotli_root ++ "/common/constants.c"; - const lib = b.addStaticLibrary("brotli", main_abs); - lib.setBuildMode(step.build_mode); - lib.setTarget(step.target); +fn buildBrotli(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.LibExeObjStep { + const lib = b.addStaticLibrary("brotli", null); + lib.setBuildMode(mode); + lib.setTarget(target); lib.linkLibC(); lib.addIncludePath(brotli_root ++ "/include"); lib.addCSourceFiles(brotli_base_sources, &.{}); - lib.install(); return lib; } @@ -207,6 +214,7 @@ fn ensureDependencySubmodule(allocator: std.mem.Allocator, path: []const u8) !vo const freetype_base_sources = &[_][]const u8{ ft_root ++ "/src/autofit/autofit.c", + ft_root ++ "/src/base/ftbase.c", ft_root ++ "/src/base/ftbbox.c", ft_root ++ "/src/base/ftbdf.c", ft_root ++ "/src/base/ftbitmap.c", @@ -272,6 +280,7 @@ const brotli_base_sources = &[_][]const u8{ brotli_root ++ "/dec/bit_reader.c", brotli_root ++ "/dec/huffman.c", brotli_root ++ "/dec/state.c", + brotli_root ++ "/common/constants.c", brotli_root ++ "/common/context.c", brotli_root ++ "/common/dictionary.c", brotli_root ++ "/common/transform.c", diff --git a/libs/glfw/build.zig b/libs/glfw/build.zig index b2a89653..b56b720f 100644 --- a/libs/glfw/build.zig +++ b/libs/glfw/build.zig @@ -59,6 +59,8 @@ pub const Options = struct { /// Build and link GLFW as a shared library. shared: bool = false, + + install_libs: bool = false, }; pub const pkg = std.build.Pkg{ @@ -67,29 +69,39 @@ pub const pkg = std.build.Pkg{ }; pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - const lib = buildLibrary(b, step, options); + const lib = buildLibrary(b, step.build_mode, step.target, options); step.linkLibrary(lib); addGLFWIncludes(step); - if (!options.shared) linkGLFWDependencies(b, step, options); - if (options.shared) step.defineCMacro("GLFW_DLL", null); + if (options.shared) { + step.defineCMacro("GLFW_DLL", null); + // TODO(build-system): pass system SDK options through + system_sdk.include(b, step, .{}); + } else { + linkGLFWDependencies(b, step, options); + } } -fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *std.build.LibExeObjStep { +fn buildLibrary(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; - const main_abs = thisDir() ++ "/src/main.zig"; - const lib = if (options.shared) b.addSharedLibrary("glfw", main_abs, .unversioned) else b.addStaticLibrary("glfw", main_abs); - lib.setBuildMode(step.build_mode); - lib.setTarget(step.target); - addGLFWIncludes(lib); + const lib = if (options.shared) + b.addSharedLibrary("glfw", null, .unversioned) + else + b.addStaticLibrary("glfw", null); + lib.setBuildMode(mode); + lib.setTarget(target); - if (options.shared) { + if (options.shared) lib.defineCMacro("_GLFW_BUILD_DLL", null); - lib.install(); - } - addGLFWSources(b, step, lib, options); + + addGLFWIncludes(lib); + addGLFWSources(b, lib, options); linkGLFWDependencies(b, lib, options); + + if (options.install_libs) + lib.install(); + return lib; } @@ -98,10 +110,9 @@ fn addGLFWIncludes(step: *std.build.LibExeObjStep) void { step.addIncludePath(thisDir() ++ "/upstream/vulkan_headers/include"); } -fn addGLFWSources(b: *Builder, step: *std.build.LibExeObjStep, lib: *std.build.LibExeObjStep, options: Options) void { - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; +fn addGLFWSources(b: *Builder, lib: *std.build.LibExeObjStep, options: Options) void { const include_glfw_src = "-I" ++ thisDir() ++ "/upstream/glfw/src"; - switch (target.os.tag) { + switch (lib.target_info.target.os.tag) { .windows => lib.addCSourceFiles(&.{ thisDir() ++ "/src/sources_all.c", thisDir() ++ "/src/sources_windows.c", @@ -112,15 +123,12 @@ fn addGLFWSources(b: *Builder, step: *std.build.LibExeObjStep, lib: *std.build.L thisDir() ++ "/src/sources_macos.c", }, &.{ "-D_GLFW_COCOA", include_glfw_src }), else => { - // TODO(future): for now, Linux must be built with glibc, not musl: + // TODO(future): for now, Linux can't be built with musl: // // ``` // ld.lld: error: cannot create a copy relocation for symbol stderr // thread 2004762 panic: attempt to unwrap error: LLDReportedFailure // ``` - step.target.abi = .gnu; - lib.setTarget(step.target); - var sources = std.ArrayList([]const u8).init(b.allocator); var flags = std.ArrayList([]const u8).init(b.allocator); sources.append(thisDir() ++ "/src/sources_all.c") catch unreachable; @@ -161,8 +169,7 @@ fn linkGLFWDependencies(b: *Builder, step: *std.build.LibExeObjStep, options: Op step.linkLibC(); // TODO(build-system): pass system SDK options through system_sdk.include(b, step, .{}); - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - switch (target.os.tag) { + switch (step.target_info.target.os.tag) { .windows => { step.linkSystemLibraryName("gdi32"); step.linkSystemLibraryName("user32"); diff --git a/libs/gpu-dawn/build.zig b/libs/gpu-dawn/build.zig index 3e258334..d8c6ea21 100644 --- a/libs/gpu-dawn/build.zig +++ b/libs/gpu-dawn/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *Builder) void { }); const options = gpu_dawn.Options{ + .install_libs = true, .from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false, }; diff --git a/libs/gpu-dawn/sdk.zig b/libs/gpu-dawn/sdk.zig index 1150c3ec..ccf7d4f0 100644 --- a/libs/gpu-dawn/sdk.zig +++ b/libs/gpu-dawn/sdk.zig @@ -43,6 +43,9 @@ pub fn Sdk(deps: anytype) type { /// Whether to build Dawn from source or not. from_source: bool = false, + /// Produce static libraries at zig-out/lib + install_libs: bool = false, + /// The binary release version to use from https://github.com/hexops/mach-gpu-dawn/releases binary_version: []const u8 = "release-777728f", @@ -74,8 +77,7 @@ pub fn Sdk(deps: anytype) type { }; pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - const opt = options.detectDefaults(target); + const opt = options.detectDefaults(step.target_info.target); if (options.from_source) linkFromSource(b, step, opt) else linkFromBinary(b, step, opt); } @@ -124,10 +126,11 @@ pub fn Sdk(deps: anytype) type { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const lib_dawn = b.addStaticLibrary("dawn", main_abs); - lib_dawn.install(); lib_dawn.setBuildMode(step.build_mode); lib_dawn.setTarget(step.target); lib_dawn.linkLibCpp(); + if (options.install_libs) + lib_dawn.install(); step.linkLibrary(lib_dawn); _ = buildLibMachDawnNative(b, lib_dawn, options); @@ -155,7 +158,7 @@ pub fn Sdk(deps: anytype) type { } pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; + const target = step.target_info.target; const binaries_available = switch (target.os.tag) { .windows => target.abi.isGnu(), .linux => target.cpu.arch.isX86() and (target.abi.isGnu() or target.abi.isMusl()), @@ -478,10 +481,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-native-mach", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -498,8 +502,7 @@ pub fn Sdk(deps: anytype) type { include("libs/dawn/include"), include("libs/dawn/src"), }) catch unreachable; - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - if (target.os.tag == .windows) { + if (step.target_info.target.os.tag == .windows) { cpp_flags.appendSlice(&.{ "-D_DEBUG", "-D_MT", @@ -514,10 +517,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-common", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -542,15 +546,14 @@ pub fn Sdk(deps: anytype) type { }) catch unreachable; var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - if (target.os.tag == .macos) { + if (step.target_info.target.os.tag == .macos) { // TODO(build-system): pass system SDK options through deps.system_sdk.include(b, lib, .{}); lib.linkFramework("Foundation"); const abs_path = comptime thisDir() ++ "/libs/dawn/src/dawn/common/SystemUtils_mac.mm"; cpp_sources.append(abs_path) catch unreachable; } - if (target.os.tag == .windows) { + if (step.target_info.target.os.tag == .windows) { const abs_path = comptime thisDir() ++ "/libs/dawn/src/dawn/common/WindowsUtils.cpp"; cpp_sources.append(abs_path) catch unreachable; } @@ -567,10 +570,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-platform", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -638,10 +642,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-native", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; deps.system_sdk.include(b, lib, .{}); @@ -780,7 +785,6 @@ pub fn Sdk(deps: anytype) type { }) catch unreachable; } - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; if (options.vulkan.?) { appendLangScannedSources(b, lib, options, .{ .rel_dirs = &.{ @@ -790,7 +794,7 @@ pub fn Sdk(deps: anytype) type { .excluding_contains = &.{ "test", "benchmark", "mock" }, }) catch unreachable; - if (isLinuxDesktopLike(target)) { + if (isLinuxDesktopLike(step.target_info.target)) { inline for ([_][]const u8{ "src/dawn/native/vulkan/external_memory/MemoryServiceOpaqueFD.cpp", "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceFD.cpp", @@ -798,7 +802,7 @@ pub fn Sdk(deps: anytype) type { const abs_path = comptime thisDir() ++ "/libs/dawn/" ++ path; cpp_sources.append(abs_path) catch unreachable; } - } else if (target.os.tag == .fuchsia) { + } else if (step.target_info.target.os.tag == .fuchsia) { inline for ([_][]const u8{ "src/dawn/native/vulkan/external_memory/MemoryServiceZirconHandle.cpp", "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp", @@ -909,10 +913,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("tint", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -961,8 +966,7 @@ pub fn Sdk(deps: anytype) type { }) catch unreachable; var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - switch (target.os.tag) { + switch (step.target_info.target.os.tag) { .windows => cpp_sources.append(comptime thisDir() ++ "/libs/dawn/src/tint/diagnostic/printer_windows.cc") catch unreachable, .linux => cpp_sources.append(comptime thisDir() ++ "/libs/dawn/src/tint/diagnostic/printer_linux.cc") catch unreachable, else => cpp_sources.append(comptime thisDir() ++ "/libs/dawn/src/tint/diagnostic/printer_other.cc") catch unreachable, @@ -1057,10 +1061,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("spirv-tools", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -1124,15 +1129,16 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("abseil-cpp-common", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; deps.system_sdk.include(b, lib, .{}); - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; + const target = step.target_info.target; if (target.os.tag == .macos) lib.linkFramework("CoreFoundation"); if (target.os.tag == .windows) lib.linkSystemLibraryName("bcrypt"); @@ -1185,10 +1191,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-wire", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; @@ -1221,10 +1228,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dawn-utils", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; deps.glfw.link(b, lib, .{ .system_sdk = .{ .set_sysroot = false } }); @@ -1295,10 +1303,11 @@ pub fn Sdk(deps: anytype) type { const lib = if (!options.separate_libs) step else blk: { const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig"; const separate_lib = b.addStaticLibrary("dxcompiler", main_abs); - separate_lib.install(); separate_lib.setBuildMode(step.build_mode); separate_lib.setTarget(step.target); separate_lib.linkLibCpp(); + if (options.install_libs) + separate_lib.install(); break :blk separate_lib; }; deps.system_sdk.include(b, lib, .{}); diff --git a/libs/sysaudio/build.zig b/libs/sysaudio/build.zig index f12c8f8a..c91b4add 100644 --- a/libs/sysaudio/build.zig +++ b/libs/sysaudio/build.zig @@ -15,7 +15,9 @@ const soundio_pkg = std.build.Pkg{ .source = .{ .path = thisDir() ++ "/soundio/main.zig" }, }; -pub const Options = struct {}; +pub const Options = struct { + install_libs: bool = false, +}; pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); @@ -68,15 +70,14 @@ pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.C } pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { - _ = options; if (step.target.toTarget().cpu.arch != .wasm32) { - const soundio_lib = buildSoundIo(b, step); + const soundio_lib = buildSoundIo(b, step.build_mode, step.target, options); step.linkLibrary(soundio_lib); step.addIncludePath(soundio_path); } } -fn buildSoundIo(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep { +fn buildSoundIo(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; @@ -95,31 +96,32 @@ fn buildSoundIo(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeOb config_file.writeAll(config_base) catch unreachable; const lib = b.addStaticLibrary("soundio", null); - lib.setTarget(step.target); - lib.setBuildMode(step.build_mode); + lib.setBuildMode(mode); + lib.setTarget(target); lib.linkLibC(); lib.addIncludePath(soundio_path); lib.addCSourceFiles(soundio_sources, &.{}); - const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - if (target.isDarwin()) { + const target_info = (std.zig.system.NativeTargetInfo.detect(b.allocator, target) catch unreachable).target; + if (target_info.isDarwin()) { lib.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{}); lib.linkFramework("AudioToolbox"); lib.linkFramework("CoreFoundation"); lib.linkFramework("CoreAudio"); config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable; - } else if (target.os.tag == .linux) { + } else if (target_info.os.tag == .linux) { lib.addCSourceFile(soundio_path ++ "/src/alsa.c", &.{}); lib.linkSystemLibrary("asound"); config_file.writeAll("#define SOUNDIO_HAVE_ALSA\n") catch unreachable; - } else if (target.os.tag == .windows) { + } else if (target_info.os.tag == .windows) { lib.addCSourceFile(soundio_path ++ "/src/wasapi.c", &.{}); config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable; } config_file.writeAll("#endif\n") catch unreachable; - lib.install(); + if (options.install_libs) + lib.install(); return lib; }