mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-26 13:08:36 +00:00
deps: Allow dynamic-linking of spirv-cross
- Use the pkg-config name of 'spirv-cross-c-shared' exported by the upstream SPIRV-Cross build
This commit is contained in:
@@ -4,16 +4,19 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const upstream = b.lazyDependency("spirv_cross", .{});
|
const module = b.addModule("spirv_cross", .{ .root_source_file = b.path("main.zig"), .target = target, .optimize = optimize });
|
||||||
|
|
||||||
const module = b.addModule("spirv_cross", .{ .root_source_file = b.path("main.zig") });
|
// For dynamic linking, we prefer dynamic linking and to search by
|
||||||
if (upstream) |v| module.addIncludePath(v.path(""));
|
// mode first. Mode first will search all paths for a dynamic library
|
||||||
|
// before falling back to static.
|
||||||
const lib = try buildSpirvCross(b, upstream, target, optimize);
|
const dynamic_link_opts: std.Build.Module.LinkSystemLibraryOptions = .{
|
||||||
b.installArtifact(lib);
|
.preferred_link_mode = .dynamic,
|
||||||
|
.search_strategy = .mode_first,
|
||||||
|
};
|
||||||
|
|
||||||
|
var test_exe: ?*std.Build.Step.Compile = null;
|
||||||
if (target.query.isNative()) {
|
if (target.query.isNative()) {
|
||||||
const test_exe = b.addTest(.{
|
test_exe = b.addTest(.{
|
||||||
.name = "test",
|
.name = "test",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path("main.zig"),
|
.root_source_file = b.path("main.zig"),
|
||||||
@@ -21,19 +24,28 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
test_exe.linkLibrary(lib);
|
const tests_run = b.addRunArtifact(test_exe.?);
|
||||||
const tests_run = b.addRunArtifact(test_exe);
|
|
||||||
const test_step = b.step("test", "Run tests");
|
const test_step = b.step("test", "Run tests");
|
||||||
test_step.dependOn(&tests_run.step);
|
test_step.dependOn(&tests_run.step);
|
||||||
|
|
||||||
// Uncomment this if we're debugging tests
|
// Uncomment this if we're debugging tests
|
||||||
// b.installArtifact(test_exe);
|
// b.installArtifact(test_exe.?);
|
||||||
|
}
|
||||||
|
if (b.systemIntegrationOption("spirv-cross", .{})) {
|
||||||
|
module.linkSystemLibrary("spirv-cross-c-shared", dynamic_link_opts);
|
||||||
|
if (test_exe) |exe| {
|
||||||
|
exe.linkSystemLibrary2("spirv-cross-c-shared", dynamic_link_opts);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const lib = try buildSpirvCross(b, module, target, optimize);
|
||||||
|
b.installArtifact(lib);
|
||||||
|
if (test_exe) |exe| exe.linkLibrary(lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buildSpirvCross(
|
fn buildSpirvCross(
|
||||||
b: *std.Build,
|
b: *std.Build,
|
||||||
upstream_: ?*std.Build.Dependency,
|
module: *std.Build.Module,
|
||||||
target: std.Build.ResolvedTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
) !*std.Build.Step.Compile {
|
) !*std.Build.Step.Compile {
|
||||||
@@ -62,33 +74,36 @@ fn buildSpirvCross(
|
|||||||
"-fno-sanitize-trap=undefined",
|
"-fno-sanitize-trap=undefined",
|
||||||
});
|
});
|
||||||
|
|
||||||
const upstream = upstream_ orelse return lib;
|
if (b.lazyDependency("spirv_cross", .{})) |upstream| {
|
||||||
lib.addCSourceFiles(.{
|
lib.addIncludePath(upstream.path(""));
|
||||||
.root = upstream.path(""),
|
module.addIncludePath(upstream.path(""));
|
||||||
.flags = flags.items,
|
lib.addCSourceFiles(.{
|
||||||
.files = &.{
|
.root = upstream.path(""),
|
||||||
// Core
|
.flags = flags.items,
|
||||||
"spirv_cross.cpp",
|
.files = &.{
|
||||||
"spirv_parser.cpp",
|
// Core
|
||||||
"spirv_cross_parsed_ir.cpp",
|
"spirv_cross.cpp",
|
||||||
"spirv_cfg.cpp",
|
"spirv_parser.cpp",
|
||||||
|
"spirv_cross_parsed_ir.cpp",
|
||||||
|
"spirv_cfg.cpp",
|
||||||
|
|
||||||
// C
|
// C
|
||||||
"spirv_cross_c.cpp",
|
"spirv_cross_c.cpp",
|
||||||
|
|
||||||
// GLSL
|
// GLSL
|
||||||
"spirv_glsl.cpp",
|
"spirv_glsl.cpp",
|
||||||
|
|
||||||
// MSL
|
// MSL
|
||||||
"spirv_msl.cpp",
|
"spirv_msl.cpp",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
lib.installHeadersDirectory(
|
lib.installHeadersDirectory(
|
||||||
upstream.path(""),
|
upstream.path(""),
|
||||||
"",
|
"",
|
||||||
.{ .include_extensions = &.{".h"} },
|
.{ .include_extensions = &.{".h"} },
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
@@ -260,7 +260,7 @@ pub fn add(
|
|||||||
spirv_cross_dep.module("spirv_cross"),
|
spirv_cross_dep.module("spirv_cross"),
|
||||||
);
|
);
|
||||||
if (b.systemIntegrationOption("spirv-cross", .{})) {
|
if (b.systemIntegrationOption("spirv-cross", .{})) {
|
||||||
step.linkSystemLibrary2("spirv-cross", dynamic_link_opts);
|
step.linkSystemLibrary2("spirv-cross-c-shared", dynamic_link_opts);
|
||||||
} else {
|
} else {
|
||||||
step.linkLibrary(spirv_cross_dep.artifact("spirv_cross"));
|
step.linkLibrary(spirv_cross_dep.artifact("spirv_cross"));
|
||||||
try static_libs.append(
|
try static_libs.append(
|
||||||
|
Reference in New Issue
Block a user