japaric-archived / rust-everywhere

SUPERSEDED by https://github.com/japaric/trust
Apache License 2.0
254 stars 12 forks source link

Auto-generate homebrew formulas #50

Open dashed opened 8 years ago

dashed commented 8 years ago

Unsure if it's out of scope of rust-everywhere.

I'm wondering if it'll be useful if rust-everywhere would be able to generate homebrew formula scripts for osx binaries.

japaric commented 8 years ago

I have no idea of how to write a homebrew formula :smile:. Is there any Rust program that has been packaged as a brew formula? That would give me a better idea of how complicated this would be.

dashed commented 8 years ago

I've been generating formulas manually using a template similar to this:

# hello.rb
#
# homebrew formula: https://github.com/Homebrew/brew
require  'formula'
class Hello < Formula
  _user = 'japaric'
  _repo_name = 'rust-everywhere'
  _bin_name = 'hello'
  homepage "https://github.com/#{_user}/#{_repo_name}"
  _ver = '0.1.0'
  version _ver

  if Hardware.is_64_bit?
    url "https://github.com/#{_user}/#{_repo_name}/releases/download/v#{_ver}/#{_bin_name}-v#{_ver}-x86_64-apple-darwin.tar.gz"
    sha256 '8ac8ef0758385a999787d94d28c0cbb34e4f67c7f3c5d779f3eb76fa48c9df10'
  else
    url "https://github.com/#{_user}/#{_repo_name}/releases/download/v#{_ver}/#{_bin_name}-v#{_ver}-i686-apple-darwin.tar.gz"
    sha256 '13339276e41251b29fcaa46de3a28ac42c0b7964ad5e92eff9a83ea6ee93a32d'
  end

  def install
    bin.install _bin_name
  end
end

Then the user would install as follows:

brew install https://raw.githubusercontent.com/japaric/rust-everywhere/master/hello.rb

It's a matter of pulling the hello.rb file from github, do sed magic to update the sha256 checksums, and then pushing back.

I'll see if I can update the appropriate bash scripts to be able to do this; and if you're interested in this change, I can open a PR.

japaric commented 8 years ago

Oh, I see. This is similar to this install.sh in the sense that it installs an existing GitHub release (tarball). Yeah, I'd be interested in merging the brew formula you posted above (but updated to the latest release) to have it serve as a starting template for people that want to write their own brew formulas. This formula would have to be updated on each release, right? So we should add some instructions about how to do that; this can be done as comments in the formula itself: # generate this checksum using this command: ....

I'll see if I can update the appropriate bash scripts to be able to do this; and if you're interested in this change, I can open a PR.

I'd be great if we had a (bash) script that updates the formula on each release but I would gladly accept a PR with just the formula template + instructions as I mentioned above. The bash script can be added later on as a follow up PR.