Files
ghostty/pkg/utfcpp/build.zig
Mitchell Hashimoto afa8f059e5 build: skip linkLibCpp on MSVC targets
Zig's bundled libc++/libc++abi conflicts with the MSVC C++ runtime
headers (vcruntime_typeinfo.h, vcruntime_exception.h, etc.) when
targeting native-native-msvc. This caused compilation failures in
the SIMD C++ code due to -nostdinc++ suppressing MSVC headers and
libc++ types clashing with MSVC runtime types.

Skip linkLibCpp() for MSVC targets across all packages (highway,
simdutf, utfcpp) and the main build (SharedDeps, GhosttyZig) since
MSVC provides its own C++ standard library natively. Also add
missing <iterator> and <cstddef> includes that were previously
pulled in transitively through libc++ headers but are not
guaranteed by MSVC's headers.
2026-03-23 11:57:14 -07:00

66 lines
1.9 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addLibrary(.{
.name = "utfcpp",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
.linkage = .static,
});
// On MSVC, the C++ standard library is provided by the MSVC runtime
// and linking Zig's bundled libc++ would conflict with it.
if (target.result.abi != .msvc) {
lib.linkLibCpp();
}
if (target.result.os.tag.isDarwin()) {
const apple_sdk = @import("apple_sdk");
try apple_sdk.addPaths(b, lib);
}
if (target.result.abi.isAndroid()) {
const android_ndk = @import("android_ndk");
try android_ndk.addPaths(b, lib);
}
var flags: std.ArrayList([]const u8) = .empty;
defer flags.deinit(b.allocator);
lib.addCSourceFiles(.{
.flags = flags.items,
.files = &.{"empty.cc"},
});
if (b.lazyDependency("utfcpp", .{})) |upstream| {
lib.addIncludePath(upstream.path(""));
lib.installHeadersDirectory(
upstream.path("source"),
"",
.{ .include_extensions = &.{".h"} },
);
}
b.installArtifact(lib);
// {
// const test_exe = b.addTest(.{
// .name = "test",
// .root_source_file = .{ .path = "main.zig" },
// .target = target,
// .optimize = optimize,
// });
// test_exe.linkLibrary(lib);
//
// var it = module.import_table.iterator();
// while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*);
// const tests_run = b.addRunArtifact(test_exe);
// const test_step = b.step("test", "Run tests");
// test_step.dependOn(&tests_run.step);
// }
}