build.bat 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. @echo off
  2. setlocal
  3. set BINARY_NAME=opencode-monitor
  4. set VERSION=dev
  5. if "%1"=="--only-ble" goto only_ble
  6. if "%1"=="--ble" goto ble
  7. goto all_platforms
  8. :only_ble
  9. echo === Building BLE relay only ===
  10. python -m pip install pyinstaller bleak
  11. if not exist bin mkdir bin
  12. python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts\ble_relay.py
  13. copy /Y bin\ble_relay.exe cmd\monitor\ble_relay.exe >nul
  14. echo.
  15. echo Done: bin\ble_relay.exe + cmd\monitor\ble_relay.exe
  16. goto end
  17. :ble
  18. echo === Building current platform with BLE ===
  19. echo Step 1: Building BLE relay...
  20. python -m pip install pyinstaller bleak
  21. if not exist bin mkdir bin
  22. python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts\ble_relay.py
  23. copy /Y bin\ble_relay.exe cmd\monitor\ble_relay.exe >nul
  24. echo Step 2: Building Go binary with BLE embedded...
  25. go mod tidy
  26. if not exist dist mkdir dist
  27. REM Detect architecture
  28. if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
  29. set GOARCH=arm64
  30. set SUFFIX=-windows-arm64.exe
  31. ) else (
  32. set GOARCH=amd64
  33. set SUFFIX=-windows-amd64.exe
  34. )
  35. set GOOS=windows
  36. go build -tags ble -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%%SUFFIX% .\cmd\monitor
  37. del /Q cmd\monitor\ble_relay.exe 2>nul
  38. echo.
  39. echo Done: dist\%BINARY_NAME%%SUFFIX%
  40. goto end
  41. :all_platforms
  42. echo === Building all platforms (no BLE) ===
  43. if not exist dist mkdir dist
  44. go mod tidy
  45. echo Building for Linux (amd64)...
  46. set GOOS=linux
  47. set GOARCH=amd64
  48. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-linux-amd64 .\cmd\monitor
  49. echo Building for Linux (arm64)...
  50. set GOARCH=arm64
  51. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-linux-arm64 .\cmd\monitor
  52. echo Building for macOS (amd64)...
  53. set GOOS=darwin
  54. set GOARCH=amd64
  55. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-darwin-amd64 .\cmd\monitor
  56. echo Building for macOS (arm64)...
  57. set GOARCH=arm64
  58. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-darwin-arm64 .\cmd\monitor
  59. echo Building for Windows (amd64)...
  60. set GOOS=windows
  61. set GOARCH=amd64
  62. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-windows-amd64.exe .\cmd\monitor
  63. echo Building for Windows (arm64)...
  64. set GOARCH=arm64
  65. go build -ldflags "-X main.Version=%VERSION%" -o dist\%BINARY_NAME%-windows-arm64.exe .\cmd\monitor
  66. echo.
  67. echo Done! Binaries in dist\
  68. dir dist\
  69. :end
  70. endlocal