Skip to content

Commit 93f7c04

Browse files
committed
cross-compile wheels
1 parent c4f8f4a commit 93f7c04

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.github/workflows/release.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ jobs:
3434
name: release
3535
permissions:
3636
id-token: write
37+
strategy:
38+
matrix:
39+
os-arch:
40+
- { goos: "linux", goarch: "amd64" }
41+
- { goos: "linux", goarch: "arm64" }
42+
- { goos: "windows", goarch: "amd64" }
43+
- { goos: "windows", goarch: "arm64" }
44+
- { goos: "darwin", goarch: "amd64" }
45+
- { goos: "darwin", goarch: "arm64" }
46+
- { goos: "", goarch: "" }
3747
steps:
3848
- uses: actions/checkout@v4
3949
with:
@@ -46,5 +56,8 @@ jobs:
4656
- uses: astral-sh/setup-uv@v5
4757
with:
4858
enable-cache: false
49-
- run: uv build
59+
- run: |
60+
GOOS="${{ matrix.os-arch.goos }}" \
61+
GOARCH="${{ matrix.os-arch.goarch }}" \
62+
uv build
5063
- run: uv publish

hatch_build.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
import subprocess
33

44
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
5+
import manygo
56

67

78
class GoBinaryBuildHook(BuildHookInterface):
89
def initialize(self, version, build_data):
910
build_data["pure_python"] = False
11+
goos = os.getenv("GOOS")
12+
goarch = os.getenv("GOARCH")
13+
if goos and goarch:
14+
build_data["tag"] = "py3-none-" + manygo.get_platform_tag(goos=goos, goarch=goarch)
1015
binary_name = self.config["binary_name"]
1116
tag = os.getenv("GITHUB_REF_NAME", "dev")
1217
commit = os.getenv("GITHUB_SHA", "none")
@@ -15,7 +20,6 @@ def initialize(self, version, build_data):
1520
print(f"Building Go binary '{binary_name}'...")
1621
subprocess.check_call(
1722
["go", "build", f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w", "-o", binary_name],
18-
env={"GOOS": "linux", "GOARCH": "amd64", **os.environ},
1923
)
2024

2125
build_data["shared_scripts"] = {binary_name: binary_name}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling", "hatch-vcs"]
2+
requires = ["hatchling", "hatch-vcs", "go-bin~=1.23", "manygo"]
33
build-backend = "hatchling.build"
44

55
[project]

0 commit comments

Comments
 (0)