diff --git a/.github/workflows/release-tip.yml b/.github/workflows/release-tip.yml index 65229f1bc..81d2b633f 100644 --- a/.github/workflows/release-tip.yml +++ b/.github/workflows/release-tip.yml @@ -31,9 +31,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 # Install Nix and use that to run our tests so our environment matches exactly. - uses: cachix/install-nix-action@v23 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b1e4c1b6..d1997dbb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,9 +27,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 # Install Nix and use that to run our tests so our environment matches exactly. - uses: cachix/install-nix-action@v23 @@ -50,9 +47,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 # Install Nix and use that to run our tests so our environment matches exactly. - uses: cachix/install-nix-action@v23 @@ -77,9 +71,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 + # This could be from a script if we wanted to but inlining here for now # in one place. # Using powershell so that we do not need to install WSL components. Also, @@ -130,9 +122,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 # Install Nix and use that to run our tests so our environment matches exactly. - uses: cachix/install-nix-action@v23 diff --git a/.gitmodules b/.gitmodules index 0e951e350..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "vendor/harfbuzz"] - path = vendor/harfbuzz - url = https://github.com/harfbuzz/harfbuzz.git -[submodule "vendor/libxml2"] - path = vendor/libxml2 - url = https://github.com/GNOME/libxml2.git diff --git a/Makefile b/Makefile index 5db8f24ff..b469ff443 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,7 @@ -# Init initializes the repo for development. init: - git submodule update --init --recursive + @echo You probably want to run "zig build" instead. .PHONY: init -# Slightly cursed way that we setup a dev version of this locally on NixOS. -dev/install: - zig build -Dcpu=baseline -Doptimize=ReleaseFast - if [ -f "/etc/NIXOS" ]; then patchelf --set-rpath "${LD_LIBRARY_PATH}" zig-out/bin/ghostty; fi - mkdir -p ${HOME}/bin - cp zig-out/bin/ghostty ${HOME}/bin/devtty -.PHONY: dev/install - # glad updates the GLAD loader. To use this, place the generated glad.zip # in this directory next to the Makefile, remove vendor/glad and run this target. # diff --git a/README.md b/README.md index e5d379c98..4eaa1aac2 100644 --- a/README.md +++ b/README.md @@ -282,12 +282,6 @@ closer to generally releasing this to ease downstream packagers. During development, I'm sticking to nightly Zig. You can find binary releases of nightly builds on the [Zig downloads page](https://ziglang.org/download/). -Install dependencies by running `make`: - -```shell-session -$ make -``` - With Zig installed, a binary can be built using `zig build`: ```shell-session diff --git a/pkg/apple-sdk/build.zig b/pkg/apple-sdk/build.zig index 248fd5fea..1aae3088f 100644 --- a/pkg/apple-sdk/build.zig +++ b/pkg/apple-sdk/build.zig @@ -3,139 +3,11 @@ const std = @import("std"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - - const lib = b.addStaticLibrary(.{ - .name = "stub", - .target = target, - .optimize = optimize, - }); - lib.linkLibC(); - lib.addCSourceFiles(&.{"stub.c"}, &.{}); - try addPaths(b, lib); - - b.installArtifact(lib); + _ = target; + _ = optimize; } -/// Add the necessary paths to the given compilation step for the Xcode SDK. -/// -/// This is required to workaround a Zig issue where we can't depend directly -/// on the hexops/xcode-frameworks repository: https://github.com/ziglang/zig/pull/15382 -/// -/// This is copied and adapted from hexops/mach. I modified it slightly -/// for my own personal taste (nothing wrong with theirs!), but the logic -/// is effectively identical. pub fn addPaths(b: *std.Build, step: *std.build.CompileStep) !void { - // branch: mach - try ensureGitRepoCloned( - b.allocator, - // WARNING: forked temporarily for https://github.com/hexops/xcode-frameworks/issues/4 - "https://github.com/mitchellh/xcode-frameworks", - "983deb1ab8d03861db30ea297cc78e6d121da4db", - xSdkPath("/zig-cache/xcode_frameworks"), - ); - - // https://github.com/ziglang/zig/issues/17358 - if (step.target.isNative()) b.sysroot = xSdkPath("/zig-cache/xcode_frameworks"); - - step.addSystemFrameworkPath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/Frameworks") }); - step.addSystemIncludePath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/include") }); - step.addLibraryPath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/lib") }); -} - -fn ensureGitRepoCloned( - allocator: std.mem.Allocator, - clone_url: []const u8, - revision: []const u8, - dir: []const u8, -) !void { - if (envVarIsTruthy(allocator, "NO_ENSURE_SUBMODULES") or - envVarIsTruthy(allocator, "NO_ENSURE_GIT")) return; - - ensureGit(allocator); - - if (std.fs.openDirAbsolute(dir, .{})) |_| { - const current_revision = try currentGitRevision(allocator, dir); - if (!std.mem.eql(u8, current_revision, revision)) { - // Reset to the desired revision - exec( - allocator, - &[_][]const u8{ "git", "fetch" }, - dir, - ) catch |err| std.debug.print( - "warning: failed to 'git fetch' in {s}: {s}\n", - .{ dir, @errorName(err) }, - ); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - } - return; - } else |err| return switch (err) { - error.FileNotFound => { - std.log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); - try exec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, "."); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - return; - }, - else => err, - }; -} - -fn exec( - allocator: std.mem.Allocator, - argv: []const []const u8, - cwd: []const u8, -) !void { - var child = std.ChildProcess.init(argv, allocator); - child.cwd = cwd; - _ = try child.spawnAndWait(); -} - -fn currentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { - const result = try std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = &.{ "git", "rev-parse", "HEAD" }, - .cwd = cwd, - }); - allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; -} - -fn ensureGit(allocator: std.mem.Allocator) void { - const argv = &[_][]const u8{ "git", "--version" }; - const result = std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = argv, - .cwd = ".", - }) catch { // e.g. FileNotFound - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - }; - defer { - allocator.free(result.stderr); - allocator.free(result.stdout); - } - if (result.term.Exited != 0) { - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - } -} - -fn envVarIsTruthy(allocator: std.mem.Allocator, name: []const u8) bool { - if (std.process.getEnvVarOwned(allocator, name)) |truthy| { - defer allocator.free(truthy); - if (std.mem.eql(u8, truthy, "true")) return true; - return false; - } else |_| { - return false; - } -} - -fn xSdkPath(comptime suffix: []const u8) []const u8 { - if (suffix[0] != '/') @compileError("suffix must be an absolute path"); - return comptime blk: { - const root_dir = std.fs.path.dirname(@src().file) orelse "."; - break :blk root_dir ++ suffix; - }; + _ = b; + @import("macos_sdk").addPaths(step); } diff --git a/pkg/apple-sdk/build.zig.zon b/pkg/apple-sdk/build.zig.zon new file mode 100644 index 000000000..784c13cf0 --- /dev/null +++ b/pkg/apple-sdk/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "apple-sdk", + .version = "0.1.0", + .dependencies = .{ + .macos_sdk = .{ + .url = "https://github.com/mitchellh/zig-build-macos-sdk/archive/166ff65bb7688c0a08c4ea98166ec8300aa34128.tar.gz", + .hash = "1220bfe1b32491a3448dff55c1dc0c12aa573f1e5bdb0a962bfbadaaa59e4833798b", + }, + }, +} diff --git a/pkg/apple-sdk/stub.c b/pkg/apple-sdk/stub.c deleted file mode 100644 index ce34f4ab0..000000000 --- a/pkg/apple-sdk/stub.c +++ /dev/null @@ -1 +0,0 @@ -// Blank on purpose diff --git a/pkg/harfbuzz/build.zig b/pkg/harfbuzz/build.zig index 2923f59ab..5e315347c 100644 --- a/pkg/harfbuzz/build.zig +++ b/pkg/harfbuzz/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *std.Build) !void { .@"enable-libpng" = true, }); const macos = b.dependency("macos", .{ .target = target, .optimize = optimize }); + const upstream = b.dependency("harfbuzz", .{}); const module = b.addModule("harfbuzz", .{ .source_file = .{ .path = "main.zig" }, @@ -23,8 +24,6 @@ pub fn build(b: *std.Build) !void { }, }); - const upstream_root = "../../vendor/harfbuzz"; - const lib = b.addStaticLibrary(.{ .name = "harfbuzz", .target = target, @@ -32,7 +31,7 @@ pub fn build(b: *std.Build) !void { }); lib.linkLibC(); lib.linkLibCpp(); - lib.addIncludePath(.{ .path = upstream_root ++ "/src" }); + lib.addIncludePath(upstream.path("src")); const freetype_dep = b.dependency("freetype", .{ .target = target, .optimize = optimize }); lib.linkLibrary(freetype_dep.artifact("freetype")); @@ -65,11 +64,11 @@ pub fn build(b: *std.Build) !void { } lib.addCSourceFile(.{ - .file = .{ .path = upstream_root ++ "/src/harfbuzz.cc" }, + .file = upstream.path("src/harfbuzz.cc"), .flags = flags.items, }); lib.installHeadersDirectoryOptions(.{ - .source_dir = .{ .path = upstream_root ++ "/src" }, + .source_dir = upstream.path("src"), .install_dir = .header, .install_subdir = "", .include_extensions = &.{".h"}, diff --git a/pkg/harfbuzz/build.zig.zon b/pkg/harfbuzz/build.zig.zon index 5609dab3e..2e6b34113 100644 --- a/pkg/harfbuzz/build.zig.zon +++ b/pkg/harfbuzz/build.zig.zon @@ -2,6 +2,11 @@ .name = "harfbuzz", .version = "2.13.2", .dependencies = .{ + .harfbuzz = .{ + .url = "https://github.com/harfbuzz/harfbuzz/archive/refs/tags/8.2.1.tar.gz", + .hash = "12203c1b09a2cf778367376076301322235816598eaf0639da08b233ab852548df92", + }, + .freetype = .{ .path = "../freetype" }, .macos = .{ .path = "../macos" }, .apple_sdk = .{ .path = "../apple-sdk" }, diff --git a/pkg/libxml2/build.zig b/pkg/libxml2/build.zig index 979021308..457a504bb 100644 --- a/pkg/libxml2/build.zig +++ b/pkg/libxml2/build.zig @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const upstream_root = "../../vendor/libxml2"; + const upstream = b.dependency("libxml2", .{}); const lib = b.addStaticLibrary(.{ .name = "xml2", @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) !void { }); lib.linkLibC(); - lib.addIncludePath(.{ .path = upstream_root ++ "/include" }); + lib.addIncludePath(upstream.path("include")); lib.addIncludePath(.{ .path = "override/include" }); if (target.isWindows()) { lib.addIncludePath(.{ .path = "override/config/win32" }); @@ -96,14 +96,14 @@ pub fn build(b: *std.Build) !void { inline for (srcs) |src| { lib.addCSourceFile(.{ - .file = .{ .path = upstream_root ++ "/" ++ src }, + .file = upstream.path(src), .flags = flags.items, }); } lib.installHeader("override/include/libxml/xmlversion.h", "libxml/xmlversion.h"); lib.installHeadersDirectoryOptions(.{ - .source_dir = .{ .path = upstream_root ++ "/include" }, + .source_dir = upstream.path("include"), .install_dir = .header, .install_subdir = "", .include_extensions = &.{".h"}, diff --git a/pkg/libxml2/build.zig.zon b/pkg/libxml2/build.zig.zon index 403292ca3..5776b429e 100644 --- a/pkg/libxml2/build.zig.zon +++ b/pkg/libxml2/build.zig.zon @@ -1,5 +1,10 @@ .{ .name = "libxml2", .version = "2.11.5", - .dependencies = .{}, + .dependencies = .{ + .libxml2 = .{ + .url = "https://github.com/GNOME/libxml2/archive/refs/tags/v2.11.5.tar.gz", + .hash = "122032442d95c3b428ae8e526017fad881e7dc78eab4d558e9a58a80bfbd65a64f7d", + }, + }, } diff --git a/vendor/harfbuzz b/vendor/harfbuzz deleted file mode 160000 index 0967a3e24..000000000 --- a/vendor/harfbuzz +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0967a3e24ab5d79cc55dbe224652d8aabd942def diff --git a/vendor/libxml2 b/vendor/libxml2 deleted file mode 160000 index 58de9d31d..000000000 --- a/vendor/libxml2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 58de9d31da4d0e8cb6bcf7f5e99714f9df2c4411