- OCaml 100%
homebrew #
Homebrew primitives for OCaml: platforms, bottle names, formulas and taps.
A few Homebrew words first. A formula is the Ruby recipe for one package. A
bottle is a prebuilt binary tarball of that package for one platform, and
pouring it unpacks it into the cellar, the directory where installed packages
live (such as /opt/homebrew/Cellar). A tap is a git repository of formulas
that brew adds next to its own.
To publish a binary through Homebrew, you write a Ruby formula whose
bottle do block gives a SHA-256 digest for each platform, name each bottle
tarball exactly as brew expects, and commit the formula to a tap. Each step
is simple, but brew checks every one of these conventions without saying
what it expects, and a wrong platform tag or class name only shows up when
someone else tries to install. homebrew turns the conventions into OCaml
values. It detects the build platform, names and parses bottle files, and
renders formulas, including bottles, git sources, platform requirements,
version_scheme and disable! lines. It can also read fields back from an
existing formula file, keep formula_renames.json up to date, and clone,
commit to and push a tap.
Building and uploading bottles is left to the bottler command-line tool,
which uses this library; its README describes the homebrew.yml file it
reads.
Installation #
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam install homebrew
API #
Homebrew.Platform: the platform tags brew uses in bottle names and formulas (arm64_sonoma,x86_64_linux, ...) anddetectfor the machine running the build.Homebrew.Bottle: bottle tarball names (filename,parse_filename) and the SHA-256 digests a formula records (sha256_string,sha256_file).Homebrew.Cellar: the cellar a bottle pours into.Homebrew.Formula: the formula record,to_rubyto render it, anddesc_of_file,version_of_fileandhomepage_of_fileto read fields back from a formula file.Homebrew.Renames: the tap'sformula_renames.json, which redirects an old formula name to its replacement.Homebrew.Tap: cloning a tap, committing and pushing to it, and resetting or restoring its files.
Two formula fields need a word. requires renders depends_on lines, which
brew treats as fatal, so a package built for one platform is refused on the
others instead of falling back to a build from source. arch and os are
checked separately: an arm64 Linux machine satisfies arch: arm64 alone,
and an Intel Mac satisfies os: macos alone.
version_scheme is there because brew compares versions token by token. A
package that goes from a date stamp such as 20260223 to a semantic version
such as 0.1.0 looks to brew like a downgrade, and raising the scheme makes
brew take the new formula as the newer one.
Related work #
- homebrew-core, the official Homebrew formula repository.
- goreleaser, release automation for Go binaries.
- cargo-dist, binary distribution for Rust.
License #
ISC. See LICENSE.md.