mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-13 02:35:29 +00:00
build: only link in the C++ module during nontest
This commit is contained in:
@@ -820,15 +820,74 @@ pub fn addSimd(
|
||||
break :lib lib;
|
||||
} else null;
|
||||
|
||||
// From hwy/detect_targets.h
|
||||
const HWY_AVX10_2: c_int = 1 << 3;
|
||||
const HWY_AVX3_SPR: c_int = 1 << 4;
|
||||
const HWY_AVX3_ZEN4: c_int = 1 << 6;
|
||||
const HWY_AVX3_DL: c_int = 1 << 7;
|
||||
const HWY_AVX3: c_int = 1 << 8;
|
||||
|
||||
var flags: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||
|
||||
// Zig 0.13 bug: https://github.com/ziglang/zig/issues/20414
|
||||
// To workaround this we just disable AVX512 support completely.
|
||||
// The performance difference between AVX2 and AVX512 is not
|
||||
// significant for our use case and AVX512 is very rare on consumer
|
||||
// hardware anyways.
|
||||
const HWY_DISABLED_TARGETS: c_int = HWY_AVX10_2 | HWY_AVX3_SPR | HWY_AVX3_ZEN4 | HWY_AVX3_DL | HWY_AVX3;
|
||||
if (target.result.cpu.arch == .x86_64) try flags.append(
|
||||
b.allocator,
|
||||
b.fmt("-DHWY_DISABLED_TARGETS={}", .{HWY_DISABLED_TARGETS}),
|
||||
);
|
||||
|
||||
// MSVC requires explicit std specification otherwise these
|
||||
// are guarded, at least on Windows 2025. Doing it unconditionally
|
||||
// doesn't cause any issues on other platforms and ensures we get
|
||||
// C++17 support on MSVC.
|
||||
try flags.append(
|
||||
b.allocator,
|
||||
"-std=c++17",
|
||||
);
|
||||
|
||||
// Keep our SIMD sources in the same Highway header mode as the
|
||||
// vendored package build so HWY's inline dispatch/runtime helpers
|
||||
// have a consistent ABI.
|
||||
if (!system_highway) try flags.append(
|
||||
b.allocator,
|
||||
"-DHWY_NO_LIBCXX",
|
||||
);
|
||||
|
||||
// When using the vendored simdutf, build its headers in no-libcxx
|
||||
// mode so we don't need C++ standard library headers at all.
|
||||
// System simdutf headers may not support this define.
|
||||
if (!system_simdutf) try flags.append(
|
||||
b.allocator,
|
||||
"-DSIMDUTF_NO_LIBCXX",
|
||||
);
|
||||
|
||||
if (simd_libc == .no_libc) try flags.appendSlice(
|
||||
b.allocator,
|
||||
(b.lazyImport(@import("../../build.zig"), "simdutf") orelse unreachable).noLibcFlags(),
|
||||
);
|
||||
|
||||
// Disable ubsan for Windows C/C++ objects to avoid undefined
|
||||
// __ubsan_handle_* references. The Zig libraries on Windows don't
|
||||
// currently bundle a matching UBSan runtime for these objects in
|
||||
// our build configurations (this affects both MSVC and GNU ABIs).
|
||||
if (target.result.os.tag == .windows) try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
|
||||
// SIMD C++ files
|
||||
{
|
||||
if (simd_libc == .no_libc) {
|
||||
const simd_cpp = b.addObject(.{
|
||||
.name = "ghostty-simd",
|
||||
.root_module = b.createModule(.{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = simd_libc == .libc,
|
||||
.link_libcpp = target.result.abi != .msvc,
|
||||
.link_libc = false,
|
||||
.link_libcpp = false,
|
||||
.pic = true,
|
||||
}),
|
||||
});
|
||||
@@ -843,66 +902,6 @@ pub fn addSimd(
|
||||
simd_cpp.root_module.linkLibrary(lib);
|
||||
}
|
||||
simd_cpp.root_module.addIncludePath(b.path("src"));
|
||||
|
||||
// From hwy/detect_targets.h
|
||||
const HWY_AVX10_2: c_int = 1 << 3;
|
||||
const HWY_AVX3_SPR: c_int = 1 << 4;
|
||||
const HWY_AVX3_ZEN4: c_int = 1 << 6;
|
||||
const HWY_AVX3_DL: c_int = 1 << 7;
|
||||
const HWY_AVX3: c_int = 1 << 8;
|
||||
|
||||
var flags: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||
|
||||
// Zig 0.13 bug: https://github.com/ziglang/zig/issues/20414
|
||||
// To workaround this we just disable AVX512 support completely.
|
||||
// The performance difference between AVX2 and AVX512 is not
|
||||
// significant for our use case and AVX512 is very rare on consumer
|
||||
// hardware anyways.
|
||||
const HWY_DISABLED_TARGETS: c_int = HWY_AVX10_2 | HWY_AVX3_SPR | HWY_AVX3_ZEN4 | HWY_AVX3_DL | HWY_AVX3;
|
||||
if (target.result.cpu.arch == .x86_64) try flags.append(
|
||||
b.allocator,
|
||||
b.fmt("-DHWY_DISABLED_TARGETS={}", .{HWY_DISABLED_TARGETS}),
|
||||
);
|
||||
|
||||
// MSVC requires explicit std specification otherwise these
|
||||
// are guarded, at least on Windows 2025. Doing it unconditionally
|
||||
// doesn't cause any issues on other platforms and ensures we get
|
||||
// C++17 support on MSVC.
|
||||
try flags.append(
|
||||
b.allocator,
|
||||
"-std=c++17",
|
||||
);
|
||||
|
||||
// Keep our SIMD sources in the same Highway header mode as the
|
||||
// vendored package build so HWY's inline dispatch/runtime helpers
|
||||
// have a consistent ABI.
|
||||
if (!system_highway) try flags.append(
|
||||
b.allocator,
|
||||
"-DHWY_NO_LIBCXX",
|
||||
);
|
||||
|
||||
// When using the vendored simdutf, build its headers in no-libcxx
|
||||
// mode so we don't need C++ standard library headers at all.
|
||||
// System simdutf headers may not support this define.
|
||||
if (!b.systemIntegrationOption("simdutf", .{})) try flags.append(
|
||||
b.allocator,
|
||||
"-DSIMDUTF_NO_LIBCXX",
|
||||
);
|
||||
|
||||
if (simd_libc == .no_libc) try flags.appendSlice(
|
||||
b.allocator,
|
||||
(b.lazyImport(@import("../../build.zig"), "simdutf") orelse unreachable).noLibcFlags(),
|
||||
);
|
||||
|
||||
// Disable ubsan for Windows C/C++ objects to avoid undefined
|
||||
// __ubsan_handle_* references. The Zig libraries on Windows don't
|
||||
// currently bundle a matching UBSan runtime for these objects in
|
||||
// our build configurations (this affects both MSVC and GNU ABIs).
|
||||
if (target.result.os.tag == .windows) try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
|
||||
simd_cpp.root_module.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
"src/simd/base64.cpp",
|
||||
@@ -917,6 +916,17 @@ pub fn addSimd(
|
||||
// archives above so the no-libc VT link stays free of transitive C++
|
||||
// runtime metadata.
|
||||
m.addObjectFile(simd_cpp.getEmittedBin());
|
||||
} else {
|
||||
m.addIncludePath(b.path("src"));
|
||||
m.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
"src/simd/base64.cpp",
|
||||
"src/simd/codepoint_width.cpp",
|
||||
"src/simd/index_of.cpp",
|
||||
"src/simd/vt.cpp",
|
||||
},
|
||||
.flags = flags.items,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user