-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhatch_build.py
More file actions
34 lines (27 loc) · 1.15 KB
/
hatch_build.py
File metadata and controls
34 lines (27 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations
import os
import subprocess
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
import manygo
class GoBinaryBuildHook(BuildHookInterface):
def initialize(self, version, build_data) -> None: # noqa: ANN001, ARG002
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) # type: ignore[invalid-argument-type]
binary_name = self.config["binary_name"]
tag = os.getenv("GITHUB_REF_NAME", "dev")
commit = os.getenv("GITHUB_SHA", "none")
if not os.path.exists(binary_name):
print(f"Building Go binary '{binary_name}'...")
subprocess.check_call( # noqa: S603
[
"go",
"build",
f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w",
"-o",
binary_name,
],
)
build_data["shared_scripts"] = {binary_name: binary_name}