Cross-Compile TCC for Windows #14
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: Cross-Platform Build and Release | |
| on: | |
| schedule: | |
| - cron: '*/15 * * * *' | |
| workflow_dispatch: | |
| jobs: | |
| git-sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Sync repositories | |
| uses: wei/git-sync@v3 | |
| with: | |
| source_repo: "https://repo.or.cz/tinycc.git" | |
| source_branch: "mob" | |
| destination_repo: "git@github.com:Tiny-C-Compiler/mirror-repository" | |
| destination_branch: "mob" | |
| ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| build-binaries: | |
| needs: git-sync | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout mirror repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Tiny-C-Compiler/mirror-repository | |
| ref: mob | |
| ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| fetch-depth: 0 | |
| - name: Install build dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| gcc \ | |
| make \ | |
| gcc-mingw-w64-x86-64 \ | |
| binutils-mingw-w64-x86-64 \ | |
| mingw-w64-x86-64-dev \ | |
| build-essential | |
| - name: Build Linux host compiler | |
| run: | | |
| ./configure | |
| make | |
| mv tcc tcc-host | |
| - name: Build Linux binary | |
| run: | | |
| ./configure | |
| make | |
| mv tcc tcc-linux | |
| - name: Prepare Windows build environment | |
| run: | | |
| # Clean previous build artifacts but keep host compiler | |
| make clean | |
| rm -f config.mak config.h | |
| # Configure for Windows cross-compilation | |
| ./configure \ | |
| --cross-prefix=x86_64-w64-mingw32- \ | |
| --cpu=x86_64 \ | |
| --extra-cflags="-static" \ | |
| --extra-ldflags="-static" | |
| # Patch Makefile for cross-compilation | |
| sed -i 's/^\(HOST_CC\s*=\s*\).*/\1.\/tcc-host/' Makefile | |
| sed -i 's/^\(CC\s*=\s*\).*/\1x86_64-w64-mingw32-gcc/' Makefile | |
| sed -i 's/\(CFLAGS\s*+=\)/\1 -DWIN32/' Makefile | |
| - name: Build Windows binary | |
| run: | | |
| # First build helper tools with host compiler | |
| make libtcc1.a | |
| # Then build Windows executable | |
| make tcc | |
| mv tcc tcc-windows.exe | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries | |
| path: | | |
| tcc-linux | |
| tcc-windows.exe | |
| create-release: | |
| needs: build-binaries | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| repository: Tiny-C-Compiler/mirror-repository | |
| token: ${{ secrets.MIRROR_REPO_TOKEN }} | |
| tag_name: latest | |
| overwrite: true | |
| files: | | |
| tcc-linux | |
| tcc-windows.exe | |
| body: | | |
| Automated cross-platform build containing: | |
| - Linux executable (ELF64) | |
| - Windows executable (PE32+) | |
| Built from mob branch at $(date -u +"%Y-%m-%dT%H:%M:%SZ") |