From 7b8d0e6b7f4ec41fd271d28083b53d9a52c3f4c2 Mon Sep 17 00:00:00 2001 From: Patrick Linnane Date: Wed, 17 Jul 2024 17:32:37 -0700 Subject: [PATCH] Formula-Cookbook: add `std_*_args` explanations Signed-off-by: Patrick Linnane --- Library/Homebrew/formula.rb | 44 +++++++++++------------ docs/Formula-Cookbook.md | 69 ++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 23 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index dfa366fbf8..5a7f9ca048 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1773,16 +1773,16 @@ class Formula "#" end - # Standard parameters for configure builds. - sig { - params( - prefix: T.any(String, Pathname), - libdir: T.any(String, Pathname), - ).returns(T::Array[String]) - } - def std_configure_args(prefix: self.prefix, libdir: "lib") - libdir = Pathname(libdir).expand_path(prefix) - ["--disable-debug", "--disable-dependency-tracking", "--prefix=#{prefix}", "--libdir=#{libdir}"] + # Standard parameters for cabal-v2 builds. + sig { returns(T::Array[String]) } + def std_cabal_v2_args + # cabal-install's dependency-resolution backtracking strategy can + # easily need more than the default 2,000 maximum number of + # "backjumps," since Hackage is a fast-moving, rolling-release + # target. The highest known needed value by a formula was 43,478 + # for git-annex, so 100,000 should be enough to avoid most + # gratuitous backjumps build failures. + ["--jobs=#{ENV.make_jobs}", "--max-backjumps=100000", "--install-method=copy", "--installdir=#{bin}"] end # Standard parameters for cargo builds. @@ -1819,6 +1819,18 @@ class Formula end alias generic_std_cmake_args std_cmake_args + # Standard parameters for configure builds. + sig { + params( + prefix: T.any(String, Pathname), + libdir: T.any(String, Pathname), + ).returns(T::Array[String]) + } + def std_configure_args(prefix: self.prefix, libdir: "lib") + libdir = Pathname(libdir).expand_path(prefix) + ["--disable-debug", "--disable-dependency-tracking", "--prefix=#{prefix}", "--libdir=#{libdir}"] + end + # Standard parameters for Go builds. sig { params(output: T.any(String, Pathname), @@ -1830,18 +1842,6 @@ class Formula args end - # Standard parameters for cabal-v2 builds. - sig { returns(T::Array[String]) } - def std_cabal_v2_args - # cabal-install's dependency-resolution backtracking strategy can - # easily need more than the default 2,000 maximum number of - # "backjumps," since Hackage is a fast-moving, rolling-release - # target. The highest known needed value by a formula was 43,478 - # for git-annex, so 100,000 should be enough to avoid most - # gratuitous backjumps build failures. - ["--jobs=#{ENV.make_jobs}", "--max-backjumps=100000", "--install-method=copy", "--installdir=#{bin}"] - end - # Standard parameters for meson builds. sig { returns(T::Array[String]) } def std_meson_args diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index 600be521e1..9585cd2a0c 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -448,7 +448,7 @@ end ### Standard arguments -For any formula using a well-known build system, there'll be arguments that should be passed during compilation such that its build conforms to Homebrew standards. These have been collected into a set of `std_*_args` methods (like [`std_configure_args`](https://rubydoc.brew.sh/Formula#std_configure_args-instance_method) and [`std_cmake_args`](https://rubydoc.brew.sh/Formula#std_cmake_args-instance_method) as seen in the [output of `brew create`](#grab-the-url)) that set the build type and installation paths, plus any other applicable options. +For any formula using certain well-known build systems, there will be arguments that should be passed during compilation so that the build conforms to Homebrew standards. These have been collected into a set of `std_*_args` methods. Most of these methods accept parameters to customize their output. For example, to set the install prefix to [**`libexec`**](#variables-for-directory-locations) for `configure` or `cmake`: @@ -457,6 +457,73 @@ system "./configure", *std_configure_args(prefix: libexec) system "cmake", "-S", ".", "-B", "build", *std_cmake_args(install_prefix: libexec) ``` +The `std_*_args` methods, as well as the arguments they pass, are: + +#### `std_cabal_v2_args` + +```ruby +"--jobs=#{ENV.make_jobs}" +"--max-backjumps=100000" +"--install-method=copy" +"--installdir=#{bin}" +``` + +#### `std_cargo_args` + +```ruby +"--locked" +"--root=#{root}" +"--path=#{path}" +``` + +#### `std_cmake_args` + +```ruby +"-DCMAKE_INSTALL_PREFIX=#{install_prefix}" +"-DCMAKE_INSTALL_LIBDIR=#{install_libdir}" +"-DCMAKE_BUILD_TYPE=Release" +"-DCMAKE_FIND_FRAMEWORK=#{find_framework}" +"-DCMAKE_VERBOSE_MAKEFILE=ON" +"-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake" +"-Wno-dev" +"-DBUILD_TESTING=OFF" +``` + +#### `std_configure_args` + +```ruby +"--disable-debug" +"--disable-dependency-tracking" +"--prefix=#{prefix}" +"--libdir=#{libdir}" +``` + +#### `std_go_args` + +```ruby +"-trimpath" +"-o=#{output}" +``` + +#### `std_meson_args` + +```ruby +"--prefix=#{prefix}" +"--libdir=#{lib}" +"--buildtype=release" +"--wrap-mode=nofallback" +``` + +#### `std_pip_args` + +```ruby +"--verbose" +"--no-deps" +"--no-binary=:all:" +"--ignore-installed" +"--no-compile" +``` + ### `bin.install "foo"` You’ll see stuff like this in some formulae. This moves the file `foo` into the formula’s `bin` directory (`/usr/local/Cellar/pkg/0.1/bin`) and makes it executable (`chmod 0555 foo`).