Skip to content

Commit

Permalink
cross-compile wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelahman committed Jan 2, 2025
1 parent c4f8f4a commit 93f7c04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ jobs:
name: release
permissions:
id-token: write
strategy:
matrix:
os-arch:
- { goos: "linux", goarch: "amd64" }
- { goos: "linux", goarch: "arm64" }
- { goos: "windows", goarch: "amd64" }
- { goos: "windows", goarch: "arm64" }
- { goos: "darwin", goarch: "amd64" }
- { goos: "darwin", goarch: "arm64" }
- { goos: "", goarch: "" }
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -46,5 +56,8 @@ jobs:
- uses: astral-sh/setup-uv@v5
with:
enable-cache: false
- run: uv build
- run: |
GOOS="${{ matrix.os-arch.goos }}" \
GOARCH="${{ matrix.os-arch.goarch }}" \
uv build
- run: uv publish
6 changes: 5 additions & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import subprocess

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
import manygo


class GoBinaryBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
build_data["pure_python"] = False
goos = os.getenv("GOOS")
goarch = os.getenv("GOARCH")
if goos and goarch:
build_data["tag"] = "py3-none-" + manygo.get_platform_tag(goos=goos, goarch=goarch)
binary_name = self.config["binary_name"]
tag = os.getenv("GITHUB_REF_NAME", "dev")
commit = os.getenv("GITHUB_SHA", "none")
Expand All @@ -15,7 +20,6 @@ def initialize(self, version, build_data):
print(f"Building Go binary '{binary_name}'...")
subprocess.check_call(
["go", "build", f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w", "-o", binary_name],
env={"GOOS": "linux", "GOARCH": "amd64", **os.environ},
)

build_data["shared_scripts"] = {binary_name: binary_name}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
requires = ["hatchling", "hatch-vcs", "go-bin~=1.23", "manygo"]
build-backend = "hatchling.build"

[project]
Expand Down

0 comments on commit 93f7c04

Please sign in to comment.