-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_binary.py
More file actions
executable file
·115 lines (100 loc) · 3.27 KB
/
Copy pathbuild_binary.py
File metadata and controls
executable file
·115 lines (100 loc) · 3.27 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
"""
Cross-platform Single-File Binary Builder for Antigravity Proxy.
Packages the entire FastAPI server, static assets, and client into a single executable.
"""
import os
import platform
import shutil
import subprocess
import sys
from pathlib import Path
ROOT_DIR = Path(__file__).parent.resolve()
DIST_DIR = ROOT_DIR / "dist"
BUILD_DIR = ROOT_DIR / "build"
STATIC_DIR = ROOT_DIR / "agy_proxy" / "static"
TEMPLATES_DIR = ROOT_DIR / "agy_proxy" / "templates"
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
if hasattr(sys.stderr, "reconfigure"):
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
def build():
print("==================================================")
print(" Building Antigravity Proxy Standalone Binary ")
print("==================================================")
system = platform.system()
arch = platform.machine().lower()
if arch in ("x86_64", "amd64"):
arch_name = "amd64"
elif arch in ("arm64", "aarch64"):
arch_name = "arm64"
else:
arch_name = arch
binary_name = "agy-proxy"
if system == "Windows":
binary_name += ".exe"
print(f"Target OS: {system}")
print(f"Target Arch: {arch_name}")
print(f"Output File: {binary_name}\n")
# PyInstaller command arguments
sep = ";" if system == "Windows" else ":"
data_static = f"{STATIC_DIR}{sep}agy_proxy/static"
data_templates = f"{TEMPLATES_DIR}{sep}agy_proxy/templates"
cmd = [
sys.executable,
"-m",
"PyInstaller",
"--name",
"agy-proxy",
"--onefile",
"--clean",
"--add-data",
data_static,
"--add-data",
data_templates,
"--collect-all",
"uvicorn",
"--collect-all",
"fastapi",
"--collect-all",
"sse_starlette",
"--hidden-import",
"uvicorn.logging",
"--hidden-import",
"uvicorn.loops",
"--hidden-import",
"uvicorn.loops.auto",
"--hidden-import",
"uvicorn.protocols",
"--hidden-import",
"uvicorn.protocols.http",
"--hidden-import",
"uvicorn.protocols.http.auto",
"--hidden-import",
"uvicorn.lifespan",
"--hidden-import",
"uvicorn.lifespan.on",
str(ROOT_DIR / "main.py"),
]
print("Running PyInstaller...")
res = subprocess.run(cmd, cwd=ROOT_DIR)
if res.returncode != 0:
print(f"\n[ERROR] Build failed with exit code {res.returncode}")
sys.exit(res.returncode)
built_file = DIST_DIR / binary_name
if built_file.exists():
size_mb = built_file.stat().st_size / (1024 * 1024)
print("\n==================================================")
print(f" [SUCCESS] Standalone binary built: {built_file}")
print(f" [PACKAGE] Size: {size_mb:.2f} MB")
print("==================================================\n")
print("To run:")
if system == "Windows":
print(" dist\\agy-proxy.exe --port 8000")
else:
print(" ./dist/agy-proxy --port 8000")
else:
print(f"\n[ERROR] Output binary not found at {built_file}")
sys.exit(1)
if __name__ == "__main__":
build()