diff --git a/.ci/build_docs.sh b/.ci/build_docs.sh new file mode 100755 index 0000000..0f4caa5 --- /dev/null +++ b/.ci/build_docs.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -xueo pipefail + +mkdir -p hadocs + +# Cache dependencies +cabal v2-build clash-cores -O0 --enable-documentation --only-dependencies + +cabal v2-haddock clash-cores -O0 --enable-documentation \ + | tee haddock_log + +set +e + +# Temporarily disabled, as there are hundreds of TH-generated instances without +# documentation. +#if grep -q "Missing documentation" haddock_log; then +# echo -e "\e[1m\e[31mMissing documentation! Scroll up for full log.\e[0m" +# grep --color=always -n -C 5 "Missing documentation" haddock_log +# exit 1 +#fi + +out_of_scope_warn="If you qualify the identifier, haddock can try to link it anyway" +if grep -q "${out_of_scope_warn}" haddock_log; then + echo -e "\e[1m\e[31mIdentifier out of scope! Scroll up for full log.\e[0m" + grep --color=always -n -C 5 "${out_of_scope_warn}" haddock_log + exit 1 +fi + +link_dest_warn="could not find link destinations for:" +if grep -q "${link_dest_warn}" haddock_log; then + echo -e "\e[1m\e[31mCould not find link destination! Scroll up for full log.\e[0m" + grep --color=always -n -C 5 "${link_dest_warn}" haddock_log + exit 1 +fi + +ambiguous_warn="You may be able to disambiguate the identifier by" +if grep -q "${ambiguous_warn}" haddock_log; then + echo -e "\e[1m\e[31mAmbiguous identifier found! Scroll up for full log.\e[0m" + grep --color=always -n -C 5 "${ambiguous_warn}" haddock_log + exit 1 +fi + +# Copy documention to hadocs/ +ln -s "$(dirname "$(tail -n1 haddock_log)")" hadocs/ diff --git a/.ci/cabal.project.local b/.ci/cabal.project.local new file mode 100644 index 0000000..abb26d7 --- /dev/null +++ b/.ci/cabal.project.local @@ -0,0 +1,2 @@ +package clash-cores + ghc-options: -Werror diff --git a/.ci/test_cabal.sh b/.ci/test_cabal.sh new file mode 100755 index 0000000..6ca70f6 --- /dev/null +++ b/.ci/test_cabal.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -xeou pipefail + +cabal v2-build all -fci +cabal v2-run unittests -fci --enable-tests +cabal v2-run doctests -fci --enable-tests +cabal v2-sdist diff --git a/.ci/test_whitespace.sh b/.ci/test_whitespace.sh new file mode 100755 index 0000000..fb4ea88 --- /dev/null +++ b/.ci/test_whitespace.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -xou pipefail + +grep \ + -E ' $' -n -r . \ + --include=*.{hs,hs-boot,sh,cabal,md,yml} \ + --exclude-dir=dist-newstyle --exclude-dir=deps +if [[ $? == 0 ]]; then + echo "EOL whitespace detected. See ^" + exit 1; +fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1d44842 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,141 @@ +name: CI + +# Trigger the workflow on all pull requests and pushes/merges to main branch +on: + pull_request: + push: + branches: [main] + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + cabal: + name: Cabal tests - ghc ${{ matrix.ghc }} / clash ${{ matrix.clash }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + clash: + - "1.8.1" + cabal: + - "3.10" + ghc: + - "9.6.5" + + env: + clash_version: ${{ matrix.clash }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Haskell + uses: haskell-actions/setup@v2 + id: setup-haskell-cabal + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Use CI specific settings + run: | + cp .ci/cabal.project.local . + + - name: Setup CI + run: | + cabal v2-freeze + mv cabal.project.freeze frozen + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} + key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }} + restore-keys: | + ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }} + ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}- + ${{ matrix.os }}-ghc-${{ matrix.ghc }}- + + - name: Unit Tests + run: | + .ci/test_cabal.sh + + - name: Setup binaries for testsuite + run: | + cabal v2-install --lib exe:clash + + - name: Testsuite (VHDL) + run: | + cabal v2-run cores-testsuite -- --hide-successes -p .VHDL --no-vivado + + - name: Testsuite (Verilog) + run: | + cabal v2-run cores-testsuite -- --hide-successes -p .Verilog --no-vivado + + - name: Testsuite (SystemVerilog) + run: | + cabal v2-run cores-testsuite -- --hide-successes -p .SystemVerilog --no-modelsim --no-vivado + + documentation: + name: Haddock Documentation - ghc ${{ matrix.ghc }} / clash ${{ matrix.clash }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + clash: + - "1.8.1" + cabal: + - "3.10" + ghc: + - "9.6.5" + + env: + clash_version: ${{ matrix.clash }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Haskell + uses: haskell-actions/setup@v2 + id: setup-haskell-cabal + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Use CI specific settings + run: | + cp .ci/cabal.project.local . + + - name: Setup CI + run: | + cabal v2-freeze + mv cabal.project.freeze frozen + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} + key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }} + restore-keys: | + ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}-${{ hashFiles('frozen') }} + ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ matrix.clash }}- + ${{ matrix.os }}-ghc-${{ matrix.ghc }}- + + - name: Build + run: | + .ci/build_docs.sh + linting: + name: Source code linting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Whitespace + run: | + .ci/test_whitespace.sh + diff --git a/.gitignore b/.gitignore index 7579cca..f4db831 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ dist-newstyle/ stack.yaml.lock cabal-dev /cabal.project.local +haddock_log .ghc.environment.* *.o *.o-boot diff --git a/cabal.project b/cabal.project index 8b3a3a0..b318b80 100644 --- a/cabal.project +++ b/cabal.project @@ -8,3 +8,35 @@ write-ghc-environment-files: always -- Eliminates the need for `--enable-tests`, which is needed for HLS. tests: true + +-- Bleeding edge Clash libraries. +source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: f946617561565440d82f67747acb2486f6526a66 + subdir: clash-prelude + +source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: f946617561565440d82f67747acb2486f6526a66 + subdir: clash-ghc + +source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: f946617561565440d82f67747acb2486f6526a66 + subdir: clash-lib + +-- clash-testsuite +source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: f946617561565440d82f67747acb2486f6526a66 + subdir: tests + +source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: f946617561565440d82f67747acb2486f6526a66 + subdir: clash-prelude-hedgehog diff --git a/clash-cores.cabal b/clash-cores.cabal index a6177a4..376e26a 100644 --- a/clash-cores.cabal +++ b/clash-cores.cabal @@ -184,7 +184,7 @@ library reducers >= 3.12.2 && < 4.0, text >= 1.2.2 && < 2.2, constraints >= 0.9 && < 1.0, - template-haskell >= 2.12.0.0 && < 2.22 + template-haskell >= 2.12.0.0 && < 2.23 test-suite unittests import: basic-config @@ -258,3 +258,4 @@ test-suite cores-testsuite clash-lib, clash-prelude, clash-testsuite + diff --git a/default.nix b/default.nix index febd360..3dbade5 100644 --- a/default.nix +++ b/default.nix @@ -3,4 +3,10 @@ with nixpkgs.pkgs; with gitignore; -haskellPackages.callCabal2nix "clash-cores" (gitignoreSource ./.) {} +let + clash-cores = haskellPackages.callCabal2nix "clash-cores" (gitignoreSource ./.) {}; +in + clash-cores.overrideAttrs (final: prev: { + buildInputs = prev.buildInputs ++ [ pkgs.git ]; + }) +