build: don't install libs, fix glfw shared lib compilation,
standardilize `buildXXX` funcs
This commit is contained in:
parent
16d4e374a9
commit
47bdb5ea03
6 changed files with 167 additions and 129 deletions
|
|
@ -24,27 +24,27 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget
|
||||||
main_tests.setTarget(target);
|
main_tests.setTarget(target);
|
||||||
main_tests.main_pkg_path = thisDir();
|
main_tests.main_pkg_path = thisDir();
|
||||||
link(b, main_tests, .{
|
link(b, main_tests, .{
|
||||||
.encoder = true,
|
.encoder = .{},
|
||||||
.transcoder = true,
|
.transcoder = .{},
|
||||||
});
|
});
|
||||||
main_tests.install();
|
main_tests.install();
|
||||||
return main_tests.run();
|
return main_tests.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
||||||
if (options.encoder) {
|
if (options.encoder) |encoder_options| {
|
||||||
step.linkLibrary(buildEncoder(b));
|
step.linkLibrary(buildEncoder(b, encoder_options));
|
||||||
step.addCSourceFile(comptime thisDir() ++ "/src/encoder/wrapper.cpp", &.{});
|
step.addCSourceFile(comptime thisDir() ++ "/src/encoder/wrapper.cpp", &.{});
|
||||||
step.addIncludePath(basisu_root ++ "/encoder");
|
step.addIncludePath(basisu_root ++ "/encoder");
|
||||||
}
|
}
|
||||||
if (options.transcoder) {
|
if (options.transcoder) |transcoder_options| {
|
||||||
step.linkLibrary(buildTranscoder(b));
|
step.linkLibrary(buildTranscoder(b, transcoder_options));
|
||||||
step.addCSourceFile(comptime thisDir() ++ "/src/transcoder/wrapper.cpp", &.{});
|
step.addCSourceFile(comptime thisDir() ++ "/src/transcoder/wrapper.cpp", &.{});
|
||||||
step.addIncludePath(basisu_root ++ "/transcoder");
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
||||||
|
|
||||||
|
|
@ -54,14 +54,15 @@ pub fn buildEncoder(b: *Builder) *std.build.LibExeObjStep {
|
||||||
encoder_sources,
|
encoder_sources,
|
||||||
&.{},
|
&.{},
|
||||||
);
|
);
|
||||||
|
|
||||||
encoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
|
encoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
|
||||||
encoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
|
encoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
|
||||||
encoder.install();
|
|
||||||
|
if (options.install_libs)
|
||||||
|
encoder.install();
|
||||||
return encoder;
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
||||||
|
|
||||||
|
|
@ -71,16 +72,25 @@ pub fn buildTranscoder(b: *Builder) *std.build.LibExeObjStep {
|
||||||
transcoder_sources,
|
transcoder_sources,
|
||||||
&.{},
|
&.{},
|
||||||
);
|
);
|
||||||
|
|
||||||
transcoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
|
transcoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
|
||||||
transcoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
|
transcoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
|
||||||
transcoder.install();
|
|
||||||
|
if (options.install_libs)
|
||||||
|
transcoder.install();
|
||||||
return transcoder;
|
return transcoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
encoder: bool,
|
encoder: ?EncoderOptions,
|
||||||
transcoder: bool,
|
transcoder: ?TranscoderOptions,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const EncoderOptions = struct {
|
||||||
|
install_libs: bool = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const TranscoderOptions = struct {
|
||||||
|
install_libs: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn thisDir() []const u8 {
|
fn thisDir() []const u8 {
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,6 @@ const hb_root = thisDir() ++ "/upstream/harfbuzz";
|
||||||
const hb_include_path = hb_root ++ "/src";
|
const hb_include_path = hb_root ++ "/src";
|
||||||
const brotli_root = thisDir() ++ "/upstream/brotli";
|
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{
|
const utils_pkg = std.build.Pkg{
|
||||||
.name = "utils",
|
.name = "utils",
|
||||||
.source = .{ .path = thisDir() ++ "/src/utils.zig" },
|
.source = .{ .path = thisDir() ++ "/src/utils.zig" },
|
||||||
|
|
@ -20,13 +15,13 @@ const utils_pkg = std.build.Pkg{
|
||||||
pub const pkg = std.build.Pkg{
|
pub const pkg = std.build.Pkg{
|
||||||
.name = "freetype",
|
.name = "freetype",
|
||||||
.source = .{ .path = thisDir() ++ "/src/main.zig" },
|
.source = .{ .path = thisDir() ++ "/src/main.zig" },
|
||||||
.dependencies = &.{ c_pkg, utils_pkg },
|
.dependencies = &.{utils_pkg},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const harfbuzz_pkg = std.build.Pkg{
|
pub const harfbuzz_pkg = std.build.Pkg{
|
||||||
.name = "harfbuzz",
|
.name = "harfbuzz",
|
||||||
.source = .{ .path = thisDir() ++ "/src/harfbuzz/main.zig" },
|
.source = .{ .path = thisDir() ++ "/src/harfbuzz/main.zig" },
|
||||||
.dependencies = &.{ c_pkg, utils_pkg, pkg },
|
.dependencies = &.{ utils_pkg, pkg },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
|
|
@ -37,22 +32,19 @@ pub const Options = struct {
|
||||||
pub const FreetypeOptions = struct {
|
pub const FreetypeOptions = struct {
|
||||||
/// the path you specify freetype options
|
/// the path you specify freetype options
|
||||||
/// via `ftoptions.h` and `ftmodule.h`
|
/// via `ftoptions.h` and `ftmodule.h`
|
||||||
ft_config_path: ?[]const u8 = null,
|
config_path: ?[]const u8 = null,
|
||||||
|
install_libs: bool = false,
|
||||||
brotli: 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 {
|
pub fn build(b: *std.build.Builder) !void {
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
const target = b.standardTargetOptions(.{});
|
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");
|
const test_step = b.step("test", "Run library tests");
|
||||||
test_step.dependOn(&testStep(b, mode, target).step);
|
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.setTarget(target);
|
||||||
example_exe.addPackage(pkg);
|
example_exe.addPackage(pkg);
|
||||||
|
|
||||||
// Remove once the stage2 compiler fixes pkg std not found
|
|
||||||
example_exe.addPackage(utils_pkg);
|
|
||||||
|
|
||||||
link(b, example_exe, .{});
|
link(b, example_exe, .{});
|
||||||
|
|
||||||
const example_install = b.addInstallArtifact(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");
|
const main_tests = b.addTestExe("freetype-tests", (comptime thisDir()) ++ "/src/main.zig");
|
||||||
main_tests.setBuildMode(mode);
|
main_tests.setBuildMode(mode);
|
||||||
main_tests.setTarget(target);
|
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);
|
main_tests.addPackage(pkg);
|
||||||
link(b, main_tests, .{
|
link(b, main_tests, .{
|
||||||
.freetype = .{
|
.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.main_pkg_path = (comptime thisDir());
|
||||||
main_tests.install();
|
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();
|
return main_tests.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
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.linkLibrary(ft_lib);
|
||||||
step.addIncludePath(ft_include_path);
|
step.addIncludePath(ft_include_path);
|
||||||
step.addIncludePath(hb_include_path);
|
if (options.brotli) {
|
||||||
|
const brotli_lib = buildBrotli(b, step.build_mode, step.target);
|
||||||
if (options.harfbuzz) |hb_options| {
|
if (options.install_libs)
|
||||||
const hb_lib = buildHarfbuzz(b, step, hb_options);
|
brotli_lib.install();
|
||||||
step.linkLibrary(hb_lib);
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
||||||
|
|
||||||
const main_abs = ft_root ++ "/src/base/ftbase.c";
|
const lib = b.addStaticLibrary("freetype", null);
|
||||||
const lib = b.addStaticLibrary("freetype", main_abs);
|
|
||||||
lib.defineCMacro("FT2_BUILD_LIBRARY", "1");
|
lib.defineCMacro("FT2_BUILD_LIBRARY", "1");
|
||||||
lib.setBuildMode(step.build_mode);
|
lib.setBuildMode(mode);
|
||||||
lib.setTarget(step.target);
|
lib.setTarget(target);
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
lib.addIncludePath(ft_include_path);
|
lib.addIncludePath(ft_include_path);
|
||||||
|
|
||||||
if (options.ft_config_path) |path|
|
if (options.config_path) |path|
|
||||||
lib.addIncludePath(path);
|
lib.addIncludePath(path);
|
||||||
|
|
||||||
if (options.brotli) {
|
if (options.brotli)
|
||||||
const brotli_lib = buildBrotli(b, step);
|
|
||||||
step.linkLibrary(brotli_lib);
|
|
||||||
lib.defineCMacro("FT_REQUIRE_BROTLI", "1");
|
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/ftsystem.c", &.{});
|
||||||
lib.addCSourceFile(ft_root ++ "/builds/windows/ftdebug.c", &.{});
|
lib.addCSourceFile(ft_root ++ "/builds/windows/ftdebug.c", &.{});
|
||||||
} else {
|
} else {
|
||||||
lib.addCSourceFile(ft_root ++ "/src/base/ftsystem.c", &.{});
|
lib.addCSourceFile(ft_root ++ "/src/base/ftsystem.c", &.{});
|
||||||
lib.addCSourceFile(ft_root ++ "/src/base/ftdebug.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_UNISTD_H", "1");
|
||||||
lib.defineCMacro("HAVE_FCNTL_H", "1");
|
lib.defineCMacro("HAVE_FCNTL_H", "1");
|
||||||
lib.addCSourceFile(ft_root ++ "/builds/unix/ftsystem.c", &.{});
|
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.addCSourceFile(ft_root ++ "/src/base/ftmac.c", &.{});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.addCSourceFiles(freetype_base_sources, &.{});
|
lib.addCSourceFiles(freetype_base_sources, &.{});
|
||||||
lib.install();
|
|
||||||
|
if (options.install_libs)
|
||||||
|
lib.install();
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buildHarfbuzz(b: *Builder, step: *std.build.LibExeObjStep, options: HarfbuzzOptions) *std.build.LibExeObjStep {
|
pub fn buildHarfbuzz(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: HarfbuzzOptions) *std.build.LibExeObjStep {
|
||||||
_ = options;
|
|
||||||
const main_abs = hb_root ++ "/src/harfbuzz.cc";
|
const main_abs = hb_root ++ "/src/harfbuzz.cc";
|
||||||
const lib = b.addStaticLibrary("harfbuzz", main_abs);
|
const lib = b.addStaticLibrary("harfbuzz", main_abs);
|
||||||
lib.setBuildMode(step.build_mode);
|
lib.setBuildMode(mode);
|
||||||
lib.setTarget(step.target);
|
lib.setTarget(target);
|
||||||
lib.linkLibCpp();
|
lib.linkLibCpp();
|
||||||
lib.addIncludePath(hb_include_path);
|
lib.addIncludePath(hb_include_path);
|
||||||
lib.addIncludePath(ft_include_path);
|
lib.addIncludePath(ft_include_path);
|
||||||
lib.defineCMacro("HAVE_FREETYPE", "1");
|
lib.defineCMacro("HAVE_FREETYPE", "1");
|
||||||
lib.install();
|
|
||||||
|
if (options.install_libs)
|
||||||
|
lib.install();
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buildBrotli(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
|
fn buildBrotli(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||||
const main_abs = brotli_root ++ "/common/constants.c";
|
const lib = b.addStaticLibrary("brotli", null);
|
||||||
const lib = b.addStaticLibrary("brotli", main_abs);
|
lib.setBuildMode(mode);
|
||||||
lib.setBuildMode(step.build_mode);
|
lib.setTarget(target);
|
||||||
lib.setTarget(step.target);
|
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
lib.addIncludePath(brotli_root ++ "/include");
|
lib.addIncludePath(brotli_root ++ "/include");
|
||||||
lib.addCSourceFiles(brotli_base_sources, &.{});
|
lib.addCSourceFiles(brotli_base_sources, &.{});
|
||||||
lib.install();
|
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,6 +214,7 @@ fn ensureDependencySubmodule(allocator: std.mem.Allocator, path: []const u8) !vo
|
||||||
|
|
||||||
const freetype_base_sources = &[_][]const u8{
|
const freetype_base_sources = &[_][]const u8{
|
||||||
ft_root ++ "/src/autofit/autofit.c",
|
ft_root ++ "/src/autofit/autofit.c",
|
||||||
|
ft_root ++ "/src/base/ftbase.c",
|
||||||
ft_root ++ "/src/base/ftbbox.c",
|
ft_root ++ "/src/base/ftbbox.c",
|
||||||
ft_root ++ "/src/base/ftbdf.c",
|
ft_root ++ "/src/base/ftbdf.c",
|
||||||
ft_root ++ "/src/base/ftbitmap.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/bit_reader.c",
|
||||||
brotli_root ++ "/dec/huffman.c",
|
brotli_root ++ "/dec/huffman.c",
|
||||||
brotli_root ++ "/dec/state.c",
|
brotli_root ++ "/dec/state.c",
|
||||||
|
brotli_root ++ "/common/constants.c",
|
||||||
brotli_root ++ "/common/context.c",
|
brotli_root ++ "/common/context.c",
|
||||||
brotli_root ++ "/common/dictionary.c",
|
brotli_root ++ "/common/dictionary.c",
|
||||||
brotli_root ++ "/common/transform.c",
|
brotli_root ++ "/common/transform.c",
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ pub const Options = struct {
|
||||||
|
|
||||||
/// Build and link GLFW as a shared library.
|
/// Build and link GLFW as a shared library.
|
||||||
shared: bool = false,
|
shared: bool = false,
|
||||||
|
|
||||||
|
install_libs: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const pkg = std.build.Pkg{
|
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 {
|
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);
|
step.linkLibrary(lib);
|
||||||
addGLFWIncludes(step);
|
addGLFWIncludes(step);
|
||||||
if (!options.shared) linkGLFWDependencies(b, step, options);
|
if (options.shared) {
|
||||||
if (options.shared) step.defineCMacro("GLFW_DLL", null);
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
||||||
|
|
||||||
const main_abs = thisDir() ++ "/src/main.zig";
|
const lib = if (options.shared)
|
||||||
const lib = if (options.shared) b.addSharedLibrary("glfw", main_abs, .unversioned) else b.addStaticLibrary("glfw", main_abs);
|
b.addSharedLibrary("glfw", null, .unversioned)
|
||||||
lib.setBuildMode(step.build_mode);
|
else
|
||||||
lib.setTarget(step.target);
|
b.addStaticLibrary("glfw", null);
|
||||||
addGLFWIncludes(lib);
|
lib.setBuildMode(mode);
|
||||||
|
lib.setTarget(target);
|
||||||
|
|
||||||
if (options.shared) {
|
if (options.shared)
|
||||||
lib.defineCMacro("_GLFW_BUILD_DLL", null);
|
lib.defineCMacro("_GLFW_BUILD_DLL", null);
|
||||||
lib.install();
|
|
||||||
}
|
addGLFWIncludes(lib);
|
||||||
addGLFWSources(b, step, lib, options);
|
addGLFWSources(b, lib, options);
|
||||||
linkGLFWDependencies(b, lib, options);
|
linkGLFWDependencies(b, lib, options);
|
||||||
|
|
||||||
|
if (options.install_libs)
|
||||||
|
lib.install();
|
||||||
|
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,10 +110,9 @@ fn addGLFWIncludes(step: *std.build.LibExeObjStep) void {
|
||||||
step.addIncludePath(thisDir() ++ "/upstream/vulkan_headers/include");
|
step.addIncludePath(thisDir() ++ "/upstream/vulkan_headers/include");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addGLFWSources(b: *Builder, step: *std.build.LibExeObjStep, lib: *std.build.LibExeObjStep, options: Options) void {
|
fn addGLFWSources(b: *Builder, lib: *std.build.LibExeObjStep, options: Options) void {
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
|
||||||
const include_glfw_src = "-I" ++ thisDir() ++ "/upstream/glfw/src";
|
const include_glfw_src = "-I" ++ thisDir() ++ "/upstream/glfw/src";
|
||||||
switch (target.os.tag) {
|
switch (lib.target_info.target.os.tag) {
|
||||||
.windows => lib.addCSourceFiles(&.{
|
.windows => lib.addCSourceFiles(&.{
|
||||||
thisDir() ++ "/src/sources_all.c",
|
thisDir() ++ "/src/sources_all.c",
|
||||||
thisDir() ++ "/src/sources_windows.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",
|
thisDir() ++ "/src/sources_macos.c",
|
||||||
}, &.{ "-D_GLFW_COCOA", include_glfw_src }),
|
}, &.{ "-D_GLFW_COCOA", include_glfw_src }),
|
||||||
else => {
|
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
|
// ld.lld: error: cannot create a copy relocation for symbol stderr
|
||||||
// thread 2004762 panic: attempt to unwrap error: LLDReportedFailure
|
// 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 sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
var flags = 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;
|
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();
|
step.linkLibC();
|
||||||
// TODO(build-system): pass system SDK options through
|
// TODO(build-system): pass system SDK options through
|
||||||
system_sdk.include(b, step, .{});
|
system_sdk.include(b, step, .{});
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
switch (step.target_info.target.os.tag) {
|
||||||
switch (target.os.tag) {
|
|
||||||
.windows => {
|
.windows => {
|
||||||
step.linkSystemLibraryName("gdi32");
|
step.linkSystemLibraryName("gdi32");
|
||||||
step.linkSystemLibraryName("user32");
|
step.linkSystemLibraryName("user32");
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ pub fn build(b: *Builder) void {
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = gpu_dawn.Options{
|
const options = gpu_dawn.Options{
|
||||||
|
.install_libs = true,
|
||||||
.from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false,
|
.from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ pub fn Sdk(deps: anytype) type {
|
||||||
/// Whether to build Dawn from source or not.
|
/// Whether to build Dawn from source or not.
|
||||||
from_source: bool = false,
|
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
|
/// The binary release version to use from https://github.com/hexops/mach-gpu-dawn/releases
|
||||||
binary_version: []const u8 = "release-777728f",
|
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 {
|
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(step.target_info.target);
|
||||||
const opt = options.detectDefaults(target);
|
|
||||||
|
|
||||||
if (options.from_source) linkFromSource(b, step, opt) else linkFromBinary(b, step, opt);
|
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 main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const lib_dawn = b.addStaticLibrary("dawn", main_abs);
|
const lib_dawn = b.addStaticLibrary("dawn", main_abs);
|
||||||
lib_dawn.install();
|
|
||||||
lib_dawn.setBuildMode(step.build_mode);
|
lib_dawn.setBuildMode(step.build_mode);
|
||||||
lib_dawn.setTarget(step.target);
|
lib_dawn.setTarget(step.target);
|
||||||
lib_dawn.linkLibCpp();
|
lib_dawn.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
lib_dawn.install();
|
||||||
step.linkLibrary(lib_dawn);
|
step.linkLibrary(lib_dawn);
|
||||||
|
|
||||||
_ = buildLibMachDawnNative(b, lib_dawn, options);
|
_ = 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 {
|
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) {
|
const binaries_available = switch (target.os.tag) {
|
||||||
.windows => target.abi.isGnu(),
|
.windows => target.abi.isGnu(),
|
||||||
.linux => target.cpu.arch.isX86() and (target.abi.isGnu() or target.abi.isMusl()),
|
.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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-native-mach", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-native-mach", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -498,8 +502,7 @@ pub fn Sdk(deps: anytype) type {
|
||||||
include("libs/dawn/include"),
|
include("libs/dawn/include"),
|
||||||
include("libs/dawn/src"),
|
include("libs/dawn/src"),
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
if (step.target_info.target.os.tag == .windows) {
|
||||||
if (target.os.tag == .windows) {
|
|
||||||
cpp_flags.appendSlice(&.{
|
cpp_flags.appendSlice(&.{
|
||||||
"-D_DEBUG",
|
"-D_DEBUG",
|
||||||
"-D_MT",
|
"-D_MT",
|
||||||
|
|
@ -514,10 +517,11 @@ pub fn Sdk(deps: anytype) type {
|
||||||
const lib = if (!options.separate_libs) step else blk: {
|
const lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-common", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-common", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -542,15 +546,14 @@ pub fn Sdk(deps: anytype) type {
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
|
|
||||||
var cpp_sources = std.ArrayList([]const u8).init(b.allocator);
|
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 (step.target_info.target.os.tag == .macos) {
|
||||||
if (target.os.tag == .macos) {
|
|
||||||
// TODO(build-system): pass system SDK options through
|
// TODO(build-system): pass system SDK options through
|
||||||
deps.system_sdk.include(b, lib, .{});
|
deps.system_sdk.include(b, lib, .{});
|
||||||
lib.linkFramework("Foundation");
|
lib.linkFramework("Foundation");
|
||||||
const abs_path = comptime thisDir() ++ "/libs/dawn/src/dawn/common/SystemUtils_mac.mm";
|
const abs_path = comptime thisDir() ++ "/libs/dawn/src/dawn/common/SystemUtils_mac.mm";
|
||||||
cpp_sources.append(abs_path) catch unreachable;
|
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";
|
const abs_path = comptime thisDir() ++ "/libs/dawn/src/dawn/common/WindowsUtils.cpp";
|
||||||
cpp_sources.append(abs_path) catch unreachable;
|
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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-platform", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-platform", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -638,10 +642,11 @@ pub fn Sdk(deps: anytype) type {
|
||||||
const lib = if (!options.separate_libs) step else blk: {
|
const lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-native", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-native", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
deps.system_sdk.include(b, lib, .{});
|
deps.system_sdk.include(b, lib, .{});
|
||||||
|
|
@ -780,7 +785,6 @@ pub fn Sdk(deps: anytype) type {
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
|
||||||
if (options.vulkan.?) {
|
if (options.vulkan.?) {
|
||||||
appendLangScannedSources(b, lib, options, .{
|
appendLangScannedSources(b, lib, options, .{
|
||||||
.rel_dirs = &.{
|
.rel_dirs = &.{
|
||||||
|
|
@ -790,7 +794,7 @@ pub fn Sdk(deps: anytype) type {
|
||||||
.excluding_contains = &.{ "test", "benchmark", "mock" },
|
.excluding_contains = &.{ "test", "benchmark", "mock" },
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
|
|
||||||
if (isLinuxDesktopLike(target)) {
|
if (isLinuxDesktopLike(step.target_info.target)) {
|
||||||
inline for ([_][]const u8{
|
inline for ([_][]const u8{
|
||||||
"src/dawn/native/vulkan/external_memory/MemoryServiceOpaqueFD.cpp",
|
"src/dawn/native/vulkan/external_memory/MemoryServiceOpaqueFD.cpp",
|
||||||
"src/dawn/native/vulkan/external_semaphore/SemaphoreServiceFD.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;
|
const abs_path = comptime thisDir() ++ "/libs/dawn/" ++ path;
|
||||||
cpp_sources.append(abs_path) catch unreachable;
|
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{
|
inline for ([_][]const u8{
|
||||||
"src/dawn/native/vulkan/external_memory/MemoryServiceZirconHandle.cpp",
|
"src/dawn/native/vulkan/external_memory/MemoryServiceZirconHandle.cpp",
|
||||||
"src/dawn/native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("tint", main_abs);
|
const separate_lib = b.addStaticLibrary("tint", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -961,8 +966,7 @@ pub fn Sdk(deps: anytype) type {
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
|
|
||||||
var cpp_sources = std.ArrayList([]const u8).init(b.allocator);
|
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 (step.target_info.target.os.tag) {
|
||||||
switch (target.os.tag) {
|
|
||||||
.windows => cpp_sources.append(comptime thisDir() ++ "/libs/dawn/src/tint/diagnostic/printer_windows.cc") catch unreachable,
|
.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,
|
.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,
|
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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("spirv-tools", main_abs);
|
const separate_lib = b.addStaticLibrary("spirv-tools", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1124,15 +1129,16 @@ pub fn Sdk(deps: anytype) type {
|
||||||
const lib = if (!options.separate_libs) step else blk: {
|
const lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("abseil-cpp-common", main_abs);
|
const separate_lib = b.addStaticLibrary("abseil-cpp-common", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
deps.system_sdk.include(b, 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 == .macos) lib.linkFramework("CoreFoundation");
|
||||||
if (target.os.tag == .windows) lib.linkSystemLibraryName("bcrypt");
|
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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-wire", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-wire", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1221,10 +1228,11 @@ pub fn Sdk(deps: anytype) type {
|
||||||
const lib = if (!options.separate_libs) step else blk: {
|
const lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dawn-utils", main_abs);
|
const separate_lib = b.addStaticLibrary("dawn-utils", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
deps.glfw.link(b, lib, .{ .system_sdk = .{ .set_sysroot = false } });
|
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 lib = if (!options.separate_libs) step else blk: {
|
||||||
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
const main_abs = comptime thisDir() ++ "/src/dawn/dummy.zig";
|
||||||
const separate_lib = b.addStaticLibrary("dxcompiler", main_abs);
|
const separate_lib = b.addStaticLibrary("dxcompiler", main_abs);
|
||||||
separate_lib.install();
|
|
||||||
separate_lib.setBuildMode(step.build_mode);
|
separate_lib.setBuildMode(step.build_mode);
|
||||||
separate_lib.setTarget(step.target);
|
separate_lib.setTarget(step.target);
|
||||||
separate_lib.linkLibCpp();
|
separate_lib.linkLibCpp();
|
||||||
|
if (options.install_libs)
|
||||||
|
separate_lib.install();
|
||||||
break :blk separate_lib;
|
break :blk separate_lib;
|
||||||
};
|
};
|
||||||
deps.system_sdk.include(b, lib, .{});
|
deps.system_sdk.include(b, lib, .{});
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ const soundio_pkg = std.build.Pkg{
|
||||||
.source = .{ .path = thisDir() ++ "/soundio/main.zig" },
|
.source = .{ .path = thisDir() ++ "/soundio/main.zig" },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Options = struct {};
|
pub const Options = struct {
|
||||||
|
install_libs: bool = false,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn build(b: *Builder) void {
|
pub fn build(b: *Builder) void {
|
||||||
const mode = b.standardReleaseOptions();
|
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 {
|
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
||||||
_ = options;
|
|
||||||
if (step.target.toTarget().cpu.arch != .wasm32) {
|
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.linkLibrary(soundio_lib);
|
||||||
step.addIncludePath(soundio_path);
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
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;
|
config_file.writeAll(config_base) catch unreachable;
|
||||||
|
|
||||||
const lib = b.addStaticLibrary("soundio", null);
|
const lib = b.addStaticLibrary("soundio", null);
|
||||||
lib.setTarget(step.target);
|
lib.setBuildMode(mode);
|
||||||
lib.setBuildMode(step.build_mode);
|
lib.setTarget(target);
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
lib.addIncludePath(soundio_path);
|
lib.addIncludePath(soundio_path);
|
||||||
lib.addCSourceFiles(soundio_sources, &.{});
|
lib.addCSourceFiles(soundio_sources, &.{});
|
||||||
|
|
||||||
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.isDarwin()) {
|
if (target_info.isDarwin()) {
|
||||||
lib.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{});
|
lib.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{});
|
||||||
lib.linkFramework("AudioToolbox");
|
lib.linkFramework("AudioToolbox");
|
||||||
lib.linkFramework("CoreFoundation");
|
lib.linkFramework("CoreFoundation");
|
||||||
lib.linkFramework("CoreAudio");
|
lib.linkFramework("CoreAudio");
|
||||||
config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable;
|
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.addCSourceFile(soundio_path ++ "/src/alsa.c", &.{});
|
||||||
lib.linkSystemLibrary("asound");
|
lib.linkSystemLibrary("asound");
|
||||||
config_file.writeAll("#define SOUNDIO_HAVE_ALSA\n") catch unreachable;
|
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", &.{});
|
lib.addCSourceFile(soundio_path ++ "/src/wasapi.c", &.{});
|
||||||
config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable;
|
config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
config_file.writeAll("#endif\n") catch unreachable;
|
config_file.writeAll("#endif\n") catch unreachable;
|
||||||
|
|
||||||
lib.install();
|
if (options.install_libs)
|
||||||
|
lib.install();
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue