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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__
build
dist
*.egg-info
pkg/dockerfile/embed/*.whl
pkg/dockerfile/embed/*
# Used by a vim plugin (projectionist)
.projections.json
.tox/
Expand Down
16 changes: 14 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ builds:
- amd64
- arm64
main: ./cmd/cog
flags:
- -trimpath
ldflags:
- "-s -w -X github.com/replicate/cog/pkg/global.Version={{.Version}} -X github.com/replicate/cog/pkg/global.Commit={{.Commit}} -X github.com/replicate/cog/pkg/global.BuildTime={{.Date}}"
- -s
- -w
- -X github.com/replicate/cog/pkg/global.Version={{ if index .Env "COG_VERSION_OVERRIDE" }}{{ .Env.COG_VERSION_OVERRIDE }}{{ else }}{{ .Version }}{{ end }}
- -X github.com/replicate/cog/pkg/global.Commit={{ if index .Env "COG_COMMIT_OVERRIDE" }}{{ .Env.COG_COMMIT_OVERRIDE }}{{ else }}{{ .Commit }}{{ end }}
- -X github.com/replicate/cog/pkg/global.BuildTime={{ .Date }}
- binary: base-image
id: base-image
goos:
Expand All @@ -27,8 +33,14 @@ builds:
- amd64
- arm64
main: ./cmd/base-image
flags:
- -trimpath
ldflags:
- "-s -w -X github.com/replicate/cog/pkg/global.Version={{.Version}} -X github.com/replicate/cog/pkg/global.Commit={{.Commit}} -X github.com/replicate/cog/pkg/global.BuildTime={{.Date}}"
- -s
- -w
- -X github.com/replicate/cog/pkg/global.Version={{ if index .Env "COG_VERSION_OVERRIDE" }}{{ .Env.COG_VERSION_OVERRIDE }}{{ else }}{{ .Version }}{{ end }}
- -X github.com/replicate/cog/pkg/global.Commit={{ if index .Env "COG_COMMIT_OVERRIDE" }}{{ .Env.COG_COMMIT_OVERRIDE }}{{ else }}{{ .Commit }}{{ end }}
- -X github.com/replicate/cog/pkg/global.BuildTime={{ .Date }}
archives:
- format: binary
builds:
Expand Down
32 changes: 14 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,8 @@ GORELEASER := $(GO) run github.com/goreleaser/goreleaser/v2@v2.2.0
PYTHON ?= python
TOX := $(PYTHON) -Im tox

# If cog's wheel has been prebuilt, it can be specified with the COG_WHEEL
# environment variable and we will not attempt to build it.
ifndef COG_WHEEL
COG_PYTHON_VERSION := $(shell $(PYTHON) -m setuptools_scm 2>/dev/null)
ifndef COG_PYTHON_VERSION
$(error Could not determine a version for cog! Did you `pip install -e '.[dev]'` first?)
endif
COG_WHEEL := dist/cog-$(COG_PYTHON_VERSION)-py3-none-any.whl
endif

COG_GO_SOURCE := $(shell find cmd pkg -type f)
COG_PYTHON_SOURCE := $(shell find python/cog -type f -name '*.py')
COG_EMBEDDED_WHEEL := pkg/dockerfile/embed/$(notdir $(COG_WHEEL))

COG_BINARIES := cog base-image

Expand All @@ -36,17 +25,24 @@ default: all
all: cog

.PHONY: wheel
wheel: $(COG_EMBEDDED_WHEEL)
wheel: pkg/dockerfile/embed/.wheel

$(COG_EMBEDDED_WHEEL): $(COG_WHEEL)
ifdef COG_WHEEL
pkg/dockerfile/embed/.wheel: $(COG_WHEEL)
@mkdir -p pkg/dockerfile/embed
@rm -f pkg/dockerfile/embed/*.whl # there can only be one embedded wheel
cp $< $@

$(COG_WHEEL): $(COG_PYTHON_SOURCE)
$(PYTHON) -m build
@echo "Using prebuilt COG_WHEEL $<"
cp $< pkg/dockerfile/embed/
@touch $@
else
pkg/dockerfile/embed/.wheel: $(COG_PYTHON_SOURCE)
@mkdir -p pkg/dockerfile/embed
@rm -f pkg/dockerfile/embed/*.whl # there can only be one embedded wheel
$(PYTHON) -m pip wheel --no-deps --no-binary=:all: --wheel-dir=pkg/dockerfile/embed .
@touch $@
endif

$(COG_BINARIES): $(COG_GO_SOURCE) $(COG_EMBEDDED_WHEEL)
$(COG_BINARIES): $(COG_GO_SOURCE) pkg/dockerfile/embed/.wheel
$(GORELEASER) build --clean --snapshot --single-target --id $@ --output $@

.PHONY: install
Expand Down
Loading