Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Homebrew formula to install on macOS #87

Open
baggiponte opened this issue Jun 14, 2023 · 4 comments
Open

Add Homebrew formula to install on macOS #87

baggiponte opened this issue Jun 14, 2023 · 4 comments

Comments

@baggiponte
Copy link

Hello! I don't have a lot of experience with that, but it would be great to distribute ttyper through homebrew as well. If you are interested, I can volunteer to help out.

@max-niederman
Copy link
Owner

I don't have any experience with Homebrew, so it would be great if you're interested in working on that. As I mentioned in #7, I'm happy to add something to our CD if it's helpful.

@baggiponte
Copy link
Author

I am busy until the end of the month (🥲) but after that I would gladly look into it!

@baggiponte
Copy link
Author

baggiponte commented Jun 18, 2023

Hi @max-niederman, I carved out some time to test out. Turns out, it is pretty straightforward, and I can install ttyper now with my formula, though some tweaks are still needed.

Create a custom formula

Here's what I went through as macOS user:

  1. Fork homebrew-core.
  2. Toggle brew developer on. This will activate homebrew "developer mode", i.e. homebrew is just a GH repo: now when you run brew update you will trigger a git pull in your local clone from the master branch.
  3. Run brew update.
  4. Run cd (brew --repository homebrew/core) to cd into the repo.
  5. Create a new branch
  6. Add my fork as a remote repo
  7. Run brew create --set-name=ttyper --rust https://github.com/max-niederman/ttyper/archive/refs/tags/v1.2.2.tar.gz

The URL is the url of the latest version of ttyper that I got from ttyper tags page

Command 4. creates a template of a short ruby file with a couple of info about your project filled in. See below what I put into the formula.

  1. Commit and push to my fork.

Ruby formula

Also available online here.

class Ttyper < Formula
  desc "Terminal-based typing test"
  homepage "https://github.com/max-niederman/ttyper"
  url "https://github.com/max-niederman/ttyper/archive/refs/tags/v1.2.2.tar.gz"
  sha256 "de168b56dfe71ac24c91c012b2c6bbd30fa5102a15dae53a8566ec2930c6b10e"
  license "MIT"
  head "https://github.com/max-niederman/ttyper", branch: "main"

  depends_on "rust" => :build

  def install
    system "cargo", "install", *std_cargo_args
  end

  test do
    assert_equal "ttyper #{version}", shell_output(bin/"ttyper --version").chomp
  end
end

A couple of notes:

  1. class Ttyper has to stay in this case, otherwise it won't work (I tried TTYper to no avail).
  2. the depends_on "rust" => :build says that if you install ttyper from source you also need to install rust. This is only necessary for the Homebrew bot to build the package, which the final user will download directly.
  3. Tests are highly recommended and I simply added one to assert the version corresponds to the latest one to ensure everything installed correctly.

Of course I never wrote a line of ruby before. Turns out, brew create does a lot of the work for you and you can copy paste what other rust-based projects did. Since ttyper is a TUI, I looked at what bottom did.

Once you have completions and stuff, I guess you can add them below the def install block like bottom did.

Problems

bottle do

If you look at bottom's formula, you will find a section like this:

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_ventura:  "1feb2cbc18e4aac7256532bd10df73165adc787711566d3ca409f13bc694c172"
    sha256 cellar: :any_skip_relocation, arm64_monterey: "22f0aaa8f197085cd4f169fc972f59cc2128571bcea27fe021c7e931a06a5814"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "b5529193e79de83a601d0fb3713f0eb0ac9d2cfa536ce5ee4f51d865c0dc7fa0"
    sha256 cellar: :any_skip_relocation, ventura:        "3bd89bb468533c10feedce451259655f1a59befdba9f6ede0d02dc8762f939d0"
    sha256 cellar: :any_skip_relocation, monterey:       "9bf45d0c6f6b448049507143186a5b48f60362c8b66a45a768fa187159c935ff"
    sha256 cellar: :any_skip_relocation, big_sur:        "92879f8c249de5942690245f32120166b3b7525810391b985a9985af2251aa26"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "620d11518d266bcd8c77b23567e045953f3049ed0b40799fd00985f50d9c8c6b"
  end

I had a look at the docs but I could not figure out what this does.

How to maintain this

Brew says you only need to run brew bump-formula-pr [options] [formula] [url/sha/version] to "to automatically update the url and sha256, remove any revision lines, and submit a pull request".

The point is: you as maintainer gotta have brew installed on your machine. I guess you could have a step in your CI/CD pipeline (e.g. GH actions) that does that for you, but I checked bottom, bat and zellij and found nothing, while ripgrep does a bit of a hack.

For the meantime, I can help with that but I guess it is not sustainable in the long run.

What to do next

I would like to make a PR to homebrew/core with this formula, tagging you, and ask some clarification about the bottle do bit and how to update it. We might ask around other rust-based formulae maintainers how they manage this step a bit more thoroughly than what I did.

(gotta say, took me longer to write this than doing the whole thing)

References

@baggiponte
Copy link
Author

Technically we could also write a GH Action workflow to run brew bump-formula-pr: homebrew has a lot of actions to use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants