2 desc "Programming language designed for robustness, optimality, and clarity"
3 homepage "https://ziglang.org/"
4 url "https://ziglang.org/download/0.13.0/zig-0.13.0.tar.xz"
5 sha256 "06c73596beeccb71cc073805bdb9c0e05764128f16478fa53bf17dfabc1d4318"
9 url "https://ziglang.org/download/"
10 regex(/href=.*?zig[._-]v?(\d+(?:\.\d+)+)\.t/i)
14 sha256 cellar: :any, arm64_sequoia: "0cd64ccf3ff42f7857000ead7b3b2f09b78c2d4e1e0f661f8f4cb6552b6ad88e"
15 sha256 cellar: :any, arm64_sonoma: "e2fdab9f70dba65551d21e6e9fc47d98336bcdb52658ff3f7799ad244aa2f500"
16 sha256 cellar: :any, arm64_ventura: "09cbcd8fdc15b0c5cdcbdecd2f0e42337a2ddac0070b50189fb02e5db1942633"
17 sha256 cellar: :any, arm64_monterey: "2f197b24ce0a0d7167eacf89314407ef21103e963916c05c9a094d79d152ecc4"
18 sha256 cellar: :any, sonoma: "193e35179c6695aee629a8551920237cf3c94a8a8853b9edf61e91ac7ba709e2"
19 sha256 cellar: :any, ventura: "dda3491dea9cdda74d5ab8ef63a38f88ad1e73e1d7ec58c4e54333e9a3333b54"
20 sha256 cellar: :any, monterey: "ea39859d4c94d9a3b5c03d5faa7552275ad74d13d24c3ea558ae3f6397a9879e"
21 sha256 cellar: :any_skip_relocation, x86_64_linux: "ca207335ca7208dbe6198f0c12d593f7c8251457e924bc05f3cd1875874cc3af"
24 depends_on "cmake" => :build
25 depends_on "llvm" => :build
26 depends_on macos: :big_sur # https://github.com/ziglang/zig/issues/13313
27 depends_on "z3" # Remove when using versioned LLVM
30 uses_from_macos "ncurses"
31 uses_from_macos "zlib"
34 llvm = deps.find { |dep| dep.name.match?(/^llvm(@\d+)?$/) }
36 if llvm.versioned_formula? && deps.any? { |dep| dep.name == "z3" }
37 # Don't remove this check even if we're using a versioned LLVM
38 # to avoid accidentally keeping it when not needed in the future.
39 odie "`z3` dependency should be removed!"
42 # Workaround for https://github.com/Homebrew/homebrew-core/pull/141453#discussion_r1320821081.
43 # This will likely be fixed upstream by https://github.com/ziglang/zig/pull/16062.
45 ENV["NIX_LDFLAGS"] = ENV["HOMEBREW_RPATH_PATHS"].split(":")
46 .map { |p| "-rpath #{p}" }
50 cpu = case Hardware.oldest_cpu
51 when :arm_vortex_tempest then "apple_m1" # See `zig targets`.
52 else Hardware.oldest_cpu
55 args = ["-DZIG_STATIC_LLVM=ON"]
56 args << "-DZIG_TARGET_MCPU=#{cpu}" if build.bottle?
58 system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
59 system "cmake", "--build", "build"
60 system "cmake", "--install", "build"
64 (testpath/"hello.zig").write <<~ZIG
65 const std = @import("std");
67 const stdout = std.io.getStdOut().writer();
68 try stdout.print("Hello, world!", .{});
71 system bin/"zig", "build-exe", "hello.zig"
72 assert_equal "Hello, world!", shell_output("./hello")
74 # error: 'TARGET_OS_IPHONE' is not defined, evaluates to 0
75 # https://github.com/ziglang/zig/issues/10377
77 (testpath/"hello.c").write <<~C
80 fprintf(stdout, "Hello, world!");
84 system bin/"zig", "cc", "hello.c", "-o", "hello"
85 assert_equal "Hello, world!", shell_output("./hello")