import subprocess
import sys
import os
from pathlib import Path
def build_viewer():
project_root = Path(__file__).parent
if os.environ.get("SKIP_VIEWER_BUILD"):
print("Skipping viewer build (SKIP_VIEWER_BUILD is set)")
return
print("=" * 80)
print("Building fastatomstruct-viewer binary...")
print("=" * 80)
target = os.environ.get("CARGO_BUILD_TARGET", "")
print("\n[1/2] Building frontend WASM...")
wasm_cmd = [
"cargo",
"build",
"--release",
"--target",
"wasm32-unknown-unknown",
"--package",
"fastatomstruct_frontend",
]
try:
subprocess.run(wasm_cmd, check=True, cwd=project_root)
print("✓ Frontend WASM built successfully")
except subprocess.CalledProcessError as e:
print(f"✗ Failed to build frontend WASM: {e}", file=sys.stderr)
print(
" The Python package will be built without the viewer binary.",
file=sys.stderr,
)
return
print("\n[2/2] Building viewer binary...")
viewer_cmd = ["cargo", "build", "--release", "--bin", "fastatomstruct-viewer"]
if target:
viewer_cmd.extend(["--target", target])
print(f"Building for target: {target}")
try:
subprocess.run(viewer_cmd, check=True, cwd=project_root)
print("✓ Viewer binary built successfully")
print("=" * 80)
except subprocess.CalledProcessError as e:
print(f"✗ Failed to build viewer binary: {e}", file=sys.stderr)
print(
" The Python package will be built without the viewer binary.",
file=sys.stderr,
)
if __name__ == "__main__":
build_viewer()