Cross-Compile TCC for Windows #18
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 dpkg --add-architecture i386 | |
| 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 \ | |
| wine64 \ | |
| wine32:i386 | |
| - 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 artifacts (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 the Makefile: | |
| # • Use host compiler (tcc-host) for helper tools. | |
| # • Use the cross-compiler for building Windows binary. | |
| # • Define WIN32 and use wine for any Windows executable that runs. | |
| 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 | |
| sed -i 's|./c2str.exe|wine ./c2str.exe|' Makefile | |
| # Remove -ldl from linking since it’s not available on Windows. | |
| sed -i 's/-ldl//g' Makefile | |
| - name: Build Windows binary | |
| run: | | |
| # Build any helper tools using the host compiler first. | |
| make libtcc1.a | |
| # Build the Windows executable with the cross-compiler. | |
| 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") |