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

Improve the build process for Homebrew #1983

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickstenning
Copy link
Member

We've recently run into issues where Homebrew's build process for cog doesn't match the build process we use for our own binaries.

This commit makes changes to our build process that will hopefully allow us to update Homebrew to use our Makefile to run its builds.

  1. Use python -m pip wheel to build the wheel rather than relying on a manual pip install -e .[dev] and python -m build.

  2. Allow COG_VERSION_OVERRIDE and COG_COMMIT_OVERRIDE to specify the version and commit values used by goreleaser.

  3. Set the -trimpath flag for go build so we don't capture directory names from the Homebrew build process or GitHub Actions.

We've recently run into issues where Homebrew's build process for cog
doesn't match the build process we use for our own binaries.

This commit makes changes to our build process that will hopefully allow
us to update Homebrew to use our Makefile to run its builds.

1. Use `python -m pip wheel` to build the wheel rather than relying on a
   manual `pip install -e .[dev]` and `python -m build`.

2. Allow COG_VERSION_OVERRIDE and COG_COMMIT_OVERRIDE to specify the
   version and commit values used by goreleaser.

3. Set the `-trimpath` flag for `go build` so we don't capture directory
   names from the Homebrew build process or GitHub Actions.
@nickstenning nickstenning requested a review from a team October 10, 2024 14:00
Copy link
Contributor

@meatballhat meatballhat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

@nickstenning
Copy link
Member Author

Marking this as draft for now because while this works (with the following cog.rb) for brew install cog --HEAD, it's not going to work for bottle builds because make cog uses a snapshot build with goreleaser. I think we'll need to figure out how to do release builds through the Makefile, or at least how to do a full release build when needed.

cog.rb

class Cog < Formula
  desc "Containers for machine learning"
  homepage "https://cog.run/"
  url "https://github.com/replicate/cog/archive/refs/tags/v0.9.26.tar.gz"
  sha256 "46ae16f928c8591622c8c61c44bce029a9a5202b5d65609ce505686d935f4e08"
  license "Apache-2.0"
  head "https://github.com/replicate/cog.git", branch: "homebrew-friendly-build"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_sequoia: "d3343952291b3eee0656ba53c3f4a9342432071fc1701f03054a5e5d4afe1f20"
    sha256 cellar: :any_skip_relocation, arm64_sonoma:  "d3343952291b3eee0656ba53c3f4a9342432071fc1701f03054a5e5d4afe1f20"
    sha256 cellar: :any_skip_relocation, arm64_ventura: "d3343952291b3eee0656ba53c3f4a9342432071fc1701f03054a5e5d4afe1f20"
    sha256 cellar: :any_skip_relocation, sonoma:        "056ca086a31900b35b9e0517483cad9da89665d5f3250a8f628191bbaf96dc39"
    sha256 cellar: :any_skip_relocation, ventura:       "056ca086a31900b35b9e0517483cad9da89665d5f3250a8f628191bbaf96dc39"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "727ce1d0bcb33af40b10b67a6750b3994fc24ab29fa4cc75f5873d6bd2e01efe"
  end

  depends_on "go" => :build
  depends_on "python@3.12" => :build

  conflicts_with "cocogitto", because: "both install `cog` binaries"

  def install
    python3 = "python3.12"

    # If we're building --HEAD then we'll have the git metadata that eliminates
    # the need for these overrides.
    if !build.head?
      ENV["COG_VERSION_OVERRIDE"] = version
      ENV["COG_COMMIT_OVERRIDE"] = tap.user
    end

    system "make", "cog", "PYTHON=#{python3}"
    bin.install "cog"

    generate_completions_from_executable(bin/"cog", "completion")
  end

  test do
    system bin/"cog", "init"
    assert_match "Configuration for Cog", (testpath/"cog.yaml").read

    assert_match "cog version #{version}", shell_output("#{bin}/cog --version")
  end
end

@nickstenning nickstenning marked this pull request as draft October 10, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants