fix build for windows #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build S-UI for Windows | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/workflows/windows.yml' | |
| - 'frontend/**' | |
| - '**.go' | |
| - 'go.mod' | |
| - 'go.sum' | |
| - 'windows/**' | |
| jobs: | |
| build-windows: | |
| strategy: | |
| matrix: | |
| platform: | |
| - amd64 | |
| - arm64 | |
| - 386 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5.0.0 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| cache: false | |
| go-version-file: go.mod | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Build frontend | |
| run: | | |
| cd frontend | |
| npm install | |
| npm run build | |
| cd .. | |
| mv frontend/dist web/html | |
| rm -fr frontend | |
| - name: Build s-ui | |
| run: | | |
| export CGO_ENABLED=1 | |
| export GOOS=windows | |
| export GOARCH=${{ matrix.platform }} | |
| # Use Bootlin prebuilt cross-toolchains (musl 1.2.5 in stable series) | |
| case "${{ matrix.platform }}" in | |
| amd64) BOOTLIN_ARCH="x86-64" ;; | |
| arm64) BOOTLIN_ARCH="aarch64" ;; | |
| 386) BOOTLIN_ARCH="x86-i686" ;; | |
| esac | |
| echo "Resolving Bootlin musl toolchain for arch=$BOOTLIN_ARCH (platform=${{ matrix.platform }})" | |
| TARBALL_BASE="https://toolchains.bootlin.com/downloads/releases/toolchains/$BOOTLIN_ARCH/tarballs/" | |
| TARBALL_URL=$(curl -fsSL "$TARBALL_BASE" | grep -oE "${BOOTLIN_ARCH}--musl--stable-[^\"]+\\.tar\\.xz" | sort -r | head -n1) | |
| [ -z "$TARBALL_URL" ] && { echo "Failed to locate Bootlin musl toolchain for arch=$BOOTLIN_ARCH" >&2; exit 1; } | |
| echo "Downloading: $TARBALL_URL" | |
| cd /tmp | |
| curl -fL -sS -o "$(basename "$TARBALL_URL")" "$TARBALL_BASE/$TARBALL_URL" | |
| tar -xf "$(basename "$TARBALL_URL")" | |
| TOOLCHAIN_DIR=$(find . -maxdepth 1 -type d -name "${BOOTLIN_ARCH}--musl--stable-*" | head -n1) | |
| export PATH="$(realpath "$TOOLCHAIN_DIR")/bin:$PATH" | |
| export CC=$(realpath "$(find "$TOOLCHAIN_DIR/bin" -name '*-gcc.br_real' -type f -executable | head -n1)") | |
| [ -z "$CC" ] && { echo "No gcc.br_real found in $TOOLCHAIN_DIR/bin" >&2; exit 1; } | |
| cd - | |
| ### Build s-ui | |
| go build -ldflags="-w -s -linkmode external -extldflags '-static'" -tags "with_quic,with_grpc,with_utls,with_acme,with_gvisor" -o sui main.go | |
| file sui | |
| ldd sui || echo "Static binary confirmed" | |
| mkdir s-ui-windows | |
| cp sui s-ui-windows/sui.exe | |
| cp -r windows/* s-ui-windows/ | |
| - name: Package | |
| run: zip -r "s-ui-windows-${{ matrix.platform }}.zip" s-ui-windows | |
| - name: Upload files to Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: s-ui-windows-${{ matrix.platform }} | |
| path: ./s-ui-windows-${{ matrix.platform }}.zip | |
| retention-days: 30 | |
| - name: Upload to Release | |
| uses: svenstaro/upload-release-action@v2 | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| tag: ${{ github.ref }} | |
| file: s-ui-windows-${{ matrix.platform }}.zip | |
| asset_name: s-ui-windows-${{ matrix.platform }}.zip | |
| prerelease: true | |
| overwrite: true |