diff options
| author | Jeffrey C. Ollie <jeff@ocjtech.us> | 2025-09-26 11:10:58 -0500 |
|---|---|---|
| committer | Mitchell Hashimoto <m@mitchellh.com> | 2025-09-27 12:29:39 -0700 |
| commit | 311f8ec70b675d553eccbb7a2d2042b374fab93e (patch) | |
| tree | 39cc9dc09bd0c132284c17da9ad48982bf9c3fce /build.zig | |
| parent | 7749b46463cfe39501110998d6adbfa121b04adb (diff) | |
build: limit cpu affinity to 32 cpus on Linux
Related to #8924
Zig currenly has a bug where it crashes when compiling Ghostty on
systems with more than 32 cpus (See the linked issue for the gory
details). As a temporary hack, use `sched_setaffinity` on Linux systems
to limit the compile to the first 32 cores. Note that this affects the
build only. The resulting Ghostty executable is not limited in any way.
This is a more general fix than wrapping the Zig compiler with
`taskset`. First of all, it requires no action from the user or
packagers. Second, it will be easier for us to remove once the upstream
Zig bug is fixed.
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -8,6 +8,10 @@ comptime { } pub fn build(b: *std.Build) !void { + // Works around a Zig but still present in 0.15.1. Remove when fixed. + // https://github.com/ghostty-org/ghostty/issues/8924 + try limitCoresForZigBug(); + // This defines all the available build options (e.g. `-D`). If you // want to know what options are available, you can run `--help` or // you can read `src/build/Config.zig`. @@ -298,3 +302,13 @@ pub fn build(b: *std.Build) !void { try translations_step.addError("cannot update translations when i18n is disabled", .{}); } } + +// WARNING: Remove this when https://github.com/ghostty-org/ghostty/issues/8924 is resolved! +// Limit ourselves to 32 cpus on Linux because of an upstream Zig bug. +fn limitCoresForZigBug() !void { + if (comptime builtin.os.tag != .linux) return; + const pid = std.os.linux.getpid(); + var set: std.bit_set.ArrayBitSet(usize, std.os.linux.CPU_SETSIZE * 8) = .initEmpty(); + for (0..32) |cpu| set.set(cpu); + try std.os.linux.sched_setaffinity(pid, &set.masks); +} |
