Merge pull request #19346 from botantony/zig-args

Zig template and std args
This commit is contained in:
Mike McQuaid 2025-02-21 19:29:27 +00:00 committed by GitHub
commit db657725b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 1 deletions

View File

@ -40,6 +40,8 @@ module Homebrew
description: "Create a basic template for a Ruby build."
switch "--rust",
description: "Create a basic template for a Rust build."
switch "--zig",
description: "Create a basic template for a Zig build."
switch "--no-fetch",
description: "Homebrew will not download <URL> to the cache and will thus not add its SHA-256 " \
"to the formula for you, nor will it check the GitHub API for GitHub projects " \
@ -58,7 +60,7 @@ module Homebrew
description: "Ignore errors for disallowed formula names and names that shadow aliases."
conflicts "--autotools", "--cmake", "--crystal", "--go", "--meson", "--node",
"--perl", "--python", "--ruby", "--rust", "--cask"
"--perl", "--python", "--ruby", "--rust", "--zig", "--cask"
conflicts "--cask", "--HEAD"
conflicts "--cask", "--set-license"
@ -173,6 +175,8 @@ module Homebrew
:ruby
elsif args.rust?
:rust
elsif args.zig?
:zig
end
fc = FormulaCreator.new(

View File

@ -32,6 +32,18 @@ module OS
args
end
sig {
params(
prefix: T.any(String, Pathname),
release_mode: Symbol,
).returns(T::Array[String])
}
def std_zig_args(prefix: self.prefix, release_mode: :fast)
args = super
args << "-fno-rosetta" if ::Hardware::CPU.arm?
args
end
end
end
end

View File

@ -1946,6 +1946,26 @@ class Formula
args
end
# Standard parameters for zig builds.
#
# @api public
sig {
params(prefix: T.any(String, Pathname),
release_mode: Symbol).returns(T::Array[String])
}
def std_zig_args(prefix: self.prefix, release_mode: :fast)
raise ArgumentError, "Invalid Zig release mode: #{release_mode}" if [:safe, :fast, :small].exclude?(release_mode)
release_mode_downcased = release_mode.to_s.downcase
release_mode_capitalized = release_mode.to_s.capitalize
[
"--prefix", prefix.to_s,
"--release=#{release_mode_downcased}",
"-Doptimize=Release#{release_mode_capitalized}",
"--summary", "all"
]
end
# Shared library names according to platform conventions.
#
# Optionally specify a `version` to restrict the shared library to a specific
@ -3029,6 +3049,8 @@ class Formula
pretty_args -= std_go_args
when "meson"
pretty_args -= std_meson_args
when "zig"
pretty_args -= std_zig_args
when %r{(^|/)(pip|python)(?:[23](?:\.\d{1,2})?)?$}
pretty_args -= std_pip_args
end

View File

@ -151,6 +151,8 @@ module Homebrew
uses_from_macos "ruby"
<% elsif @mode == :rust %>
depends_on "rust" => :build
<% elsif @mode == :zig %>
depends_on "zig" => :build
<% elsif @mode.nil? %>
# depends_on "cmake" => :build
<% end %>
@ -217,6 +219,8 @@ module Homebrew
bin.env_script_all_files(libexec/"bin", GEM_HOME: ENV["GEM_HOME"])
<% elsif @mode == :rust %>
system "cargo", "install", *std_cargo_args
<% elsif @mode == :zig %>
system "zig", "build", *std_zig_args
<% else %>
# Remove unrecognized options if they cause configure to fail
# https://rubydoc.brew.sh/Formula.html#std_configure_args-instance_method

View File

@ -56,6 +56,9 @@ class Homebrew::DevCmd::Create::Args < Homebrew::CLI::Args
sig { returns(T::Boolean) }
def rust?; end
sig { returns(T::Boolean) }
def zig?; end
sig { returns(T.nilable(String)) }
def set_license; end