cheshire icon indicating copy to clipboard operation
cheshire copied to clipboard

Add windows support

Open HepoH3 opened this issue 5 months ago • 4 comments

This PR adds the ability to compile test software, synthesize and simulate on windows platform through WSL2.

HepoH3 avatar Jun 18 '25 15:06 HepoH3

Looks pretty good at first sight :+1: I will need to find some time to play with this on a Windows system.

An open point is if we can perhaps set up some Github runners to test Windows support as much as possible without commercial tools (mostly the build steps), as I'd hate to break it with a silly typo down the road and not notice. I will also look into this.

paulsc96 avatar Jun 19 '25 21:06 paulsc96

Sure, take your time! The documentation with WSL configuration specifics is in the linked PR.

HepoH3 avatar Jun 20 '25 11:06 HepoH3

if we can perhaps set up some Github runners to test Windows support

If it helps: WSL2 is available in the windows-2025 runner images. If you plan to use an older image, you may find this action useful.

HepoH3 avatar Jun 25 '25 20:06 HepoH3

It turned out that even when using Windows-2025 runner, it is still necessary to configure WSL, since the system image comes without a pre-installed WSL2 distribution.

I was able to write a build workflow ported for the Windows platform, but it includes some workarounds. The issue is that GitHub Actions are applied to the host itself, and I'm not aware of a way to apply them inside WSL on that host. Because of this, existing actions like setup-python, riscv-gcc-install, and bender-install are not usable in this context, so I implemented their functionality manually.

Currently, the build completes successfully, but there is a problem with the whether-clean check. During the build, line endings in the repository change from CRLF to LF, which is shown by git status. This has been worked around by temporary adding a .gitattributes file to the repository with the following content:

* text=auto

Additionally, the current check effectively tests parts of the repository that are unchanged by this pull request, since all my modifications are tied to targets depending on commercial CAD tools. Effectively, it just verifies that the build flow sw/hw/sim -all on the Windows platform via WSL2 completes without errors. It might make sense to verify that commands for Vivado by, for example, correctly expanding them to the expected text outputs. However, I'm not sure how to implement that without hardcoding paths in the checks.

This is my first workflow, so it might not be perfectly written, but I hope you'll find it useful:

name: build

on: [push, pull_request, workflow_dispatch]

jobs:
  build:
    strategy:
      matrix:
        target: [sw, hw, sim]
      fail-fast: false
    runs-on: windows-2025

    steps:
      - name: Setup WSL
        uses: vedantmgoyal9/setup-wsl2@main
        with:
          distro: Ubuntu

      - name: Set custom WSL mount root
        run: |
          wsl bash -c "echo -e '[automount]\nroot = /' | sudo tee /etc/wsl.conf"
          wsl --shutdown

      - name: Install Dependencies
        run: |
          wsl bash -c "set -e; sudo apt update; for i in {1..5}; do sudo apt install -y python3 python3-pip python3-venv unzip gdisk && break; echo 'APT failed, retrying (\$i)...'; sleep 10; done"

      - name: Install Bender
        run: |
          wsl bash -c 'curl -f -sSL https://github.com/pulp-platform/bender/releases/download/v0.27.1/bender-0.27.1-x86_64-linux-gnu-ubuntu22.04.tar.gz -o $HOME/bender.tar.gz'
          wsl bash -c 'tar -xzf $HOME/bender.tar.gz -C $HOME'
          wsl bash -c 'chmod +x $HOME/bender'

      - name: Install RISC-V GCC toolchain
        run: |
          wsl curl -f -sSL https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.03.14/riscv64-elf-ubuntu-22.04-nightly-2023.03.14-nightly.tar.gz -o toolchain.tar.gz
          wsl bash -c 'mkdir -p $HOME/riscv'
          wsl bash -c 'tar -xzf toolchain.tar.gz -C $HOME/riscv --strip-components=1'

      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Install Python requirements
        run: wsl pip3 install -r requirements.txt

      - name: Build target
        run: |
          wsl bash -c 'export CHS_SW_GCC_BINROOT=$HOME/riscv/bin BENDER=$HOME/bender && make ${{ matrix.target }}-all'

      - name: Check whether clean
        run: |
          wsl echo "* text=auto" >> .gitattributes
          wsl git add --renormalize .
          wsl rm .gitattributes
          wsl git status
          wsl bash -c 'test -z "$(git status --porcelain --ignore-submodules)"'

HepoH3 avatar Jun 26 '25 10:06 HepoH3