Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/dcimgui/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ pub fn build(b: *std.Build) !void {
"-DIMGUI_USE_WCHAR32=1",
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
});
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}
if (freetype) try flags.appendSlice(b.allocator, &.{
"-DIMGUI_ENABLE_FREETYPE=1",
});
Expand Down
9 changes: 9 additions & 0 deletions pkg/harfbuzz/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
try flags.appendSlice(b.allocator, &.{
"-DHAVE_STDBOOL_H",
});
// Disable ubsan for MSVC: Zig's ubsan runtime cannot be bundled
// on Windows (LNK4229), leaving __ubsan_handle_* unresolved when
// the static archive is consumed by an external linker.
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}
if (target.result.os.tag != .windows) {
try flags.appendSlice(b.allocator, &.{
"-DHAVE_UNISTD_H",
Expand Down
6 changes: 6 additions & 0 deletions pkg/libpng/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ pub fn build(b: *std.Build) !void {
"-DPNG_INTEL_SSE_OPT=0",
"-DPNG_MIPS_MSA_OPT=0",
});
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}

lib.addCSourceFiles(.{
.root = upstream.path(""),
Expand Down
6 changes: 6 additions & 0 deletions pkg/oniguruma/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu

var flags: std.ArrayList([]const u8) = .empty;
defer flags.deinit(b.allocator);
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}
lib.addCSourceFiles(.{
.root = upstream.path(""),
.flags = flags.items,
Expand Down
4 changes: 4 additions & 0 deletions pkg/wuffs/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub fn build(b: *std.Build) !void {
var flags: std.ArrayList([]const u8) = .empty;
defer flags.deinit(b.allocator);
try flags.append(b.allocator, "-DWUFFS_IMPLEMENTATION");
if (target.result.abi == .msvc) {
try flags.append(b.allocator, "-fno-sanitize=undefined");
try flags.append(b.allocator, "-fno-sanitize-trap=undefined");
}
inline for (@import("src/c.zig").defines) |key| {
try flags.append(b.allocator, "-D" ++ key);
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/zlib/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub fn build(b: *std.Build) !void {
"-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H",
});
if (target.result.abi == .msvc) {
try flags.appendSlice(b.allocator, &.{
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
}
if (target.result.os.tag != .windows) {
try flags.append(b.allocator, "-DZ_HAVE_UNISTD_H");
}
Expand Down
47 changes: 47 additions & 0 deletions src/build/CombineArchivesStep.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Combines multiple static archives into a single fat archive.
//! Uses libtool on Darwin and a cross-platform MRI-script build tool
//! on all other platforms (including Windows).
const std = @import("std");
const LibtoolStep = @import("LibtoolStep.zig");

/// Combine multiple static archives into a single fat archive.
///
/// `name` identifies the library (e.g. "ghostty-internal", "ghostty-vt").
/// Output uses a `-fat` suffix to distinguish the combined archive from
/// the single-library archive in the build cache.
pub fn create(
b: *std.Build,
target: std.Build.ResolvedTarget,
name: []const u8,
sources: []const std.Build.LazyPath,
) struct { step: *std.Build.Step, output: std.Build.LazyPath } {
if (target.result.os.tag.isDarwin()) {
const libtool = LibtoolStep.create(b, .{
.name = name,
.out_name = b.fmt("lib{s}-fat.a", .{name}),
.sources = @constCast(sources),
});
return .{ .step = libtool.step, .output = libtool.output };
}

// On non-Darwin, use a build tool that generates an MRI script and
// pipes it to `zig ar -M`. This works on all platforms including
// Windows (the previous /bin/sh approach did not).
const tool = b.addExecutable(.{
.name = "combine_archives",
.root_module = b.createModule(.{
.root_source_file = b.path("src/build/combine_archives.zig"),
.target = b.graph.host,
}),
});
const run = b.addRunArtifact(tool);
run.addArg(b.graph.zig_exe);
const out_name = if (target.result.os.tag == .windows)
b.fmt("{s}-fat.lib", .{name})
else
b.fmt("lib{s}-fat.a", .{name});
const output = run.addOutputFileArg(out_name);
for (sources) |source| run.addFileArg(source);

return .{ .step = &run.step, .output = output };
}
27 changes: 8 additions & 19 deletions src/build/GhosttyLib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const GhosttyLib = @This();

const std = @import("std");
const RunStep = std.Build.Step.Run;
const CombineArchivesStep = @import("CombineArchivesStep.zig");
const Config = @import("Config.zig");
const SharedDeps = @import("SharedDeps.zig");
const LibtoolStep = @import("LibtoolStep.zig");
const LipoStep = @import("LipoStep.zig");

/// The step that generates the file.
Expand Down Expand Up @@ -48,29 +48,18 @@ pub fn initStatic(
}

// Add our dependencies. Get the list of all static deps so we can
// build a combined archive if necessary.
// build a combined archive.
var lib_list = try deps.add(lib);
try lib_list.append(b.allocator, lib.getEmittedBin());

if (!deps.config.target.result.os.tag.isDarwin()) return .{
.step = &lib.step,
.output = lib.getEmittedBin(),
.dsym = null,
.pkg_config = null,
.pkg_config_static = null,
};

// Create a static lib that contains all our dependencies.
const libtool = LibtoolStep.create(b, .{
.name = "ghostty",
.out_name = "libghostty-fat.a",
.sources = lib_list.items,
});
libtool.step.dependOn(&lib.step);
// Combine all archives into a single fat static library so
// consumers only need to link one file.
const combined = CombineArchivesStep.create(b, deps.config.target, "ghostty-internal", lib_list.items);
combined.step.dependOn(&lib.step);

return .{
.step = libtool.step,
.output = libtool.output,
.step = combined.step,
.output = combined.output,

// Static libraries cannot have dSYMs because they aren't linked.
.dsym = null,
Expand Down
38 changes: 2 additions & 36 deletions src/build/GhosttyLibVt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const RunStep = std.Build.Step.Run;
const CombineArchivesStep = @import("CombineArchivesStep.zig");
const Config = @import("Config.zig");
const GhosttyZig = @import("GhosttyZig.zig");
const LibtoolStep = @import("LibtoolStep.zig");
const LipoStep = @import("LipoStep.zig");
const SharedDeps = @import("SharedDeps.zig");
const XCFrameworkStep = @import("XCFrameworkStep.zig");
Expand Down Expand Up @@ -287,7 +287,7 @@ fn initLib(
try sources.append(b.allocator, lib.getEmittedBin());
try sources.appendSlice(b.allocator, zig.simd_libs.items);

const combined = combineArchives(b, target, sources.items);
const combined = CombineArchivesStep.create(b, target, "ghostty-vt", sources.items);
combined.step.dependOn(&lib.step);

return .{
Expand All @@ -312,40 +312,6 @@ fn initLib(
};
}

/// Combine multiple static archives into a single fat archive.
/// Uses libtool on Darwin and ar MRI scripts on other platforms.
fn combineArchives(
b: *std.Build,
target: std.Build.ResolvedTarget,
sources: []const std.Build.LazyPath,
) struct { step: *std.Build.Step, output: std.Build.LazyPath } {
if (target.result.os.tag.isDarwin()) {
const libtool = LibtoolStep.create(b, .{
.name = "ghostty-vt",
.out_name = "libghostty-vt.a",
.sources = @constCast(sources),
});
return .{ .step = libtool.step, .output = libtool.output };
}

// On non-Darwin, use a build tool that generates an MRI script and
// pipes it to `zig ar -M`. This works on all platforms including
// Windows (the previous /bin/sh approach did not).
const tool = b.addExecutable(.{
.name = "combine_archives",
.root_module = b.createModule(.{
.root_source_file = b.path("src/build/combine_archives.zig"),
.target = b.graph.host,
}),
});
const run = b.addRunArtifact(tool);
run.addArg(b.graph.zig_exe);
const output = run.addOutputFileArg("libghostty-vt.a");
for (sources) |source| run.addFileArg(source);

return .{ .step = &run.step, .output = output };
}

/// Returns the Libs.private value for the pkg-config file.
/// Vendored C++ dependencies are built in no-libcxx mode so consumers
/// don't need libc++. System-provided simdutf still requires it.
Expand Down
11 changes: 10 additions & 1 deletion src/build/SharedDeps.zig
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,16 @@ pub fn add(
// C files
step.linkLibC();
step.addIncludePath(b.path("src/stb"));
step.addCSourceFiles(.{ .files = &.{"src/stb/stb.c"} });
// Disable ubsan for MSVC: Zig's ubsan runtime cannot be bundled
// on Windows (LNK4229), leaving __ubsan_handle_* unresolved when
// the static archive is consumed by an external linker.
step.addCSourceFiles(.{
.files = &.{"src/stb/stb.c"},
.flags = if (step.rootModuleTarget().abi == .msvc)
&.{ "-fno-sanitize=undefined", "-fno-sanitize-trap=undefined" }
else
&.{},
});
if (step.rootModuleTarget().os.tag == .linux) {
step.addIncludePath(b.path("src/apprt/gtk"));
}
Expand Down
Loading