Skip to content

Commit

Permalink
Cabal ci (#1)
Browse files Browse the repository at this point in the history
* added flake file

* using modular arithmetic package and tests pass

* temp disable tests

* remove tests

* problem with rules

* Empty-Commit

* remove nix files

* builds with 9.8 9.6

* ormolu

* add tests

* changelog and bump package version
  • Loading branch information
martyall authored Apr 10, 2024
1 parent 8e1361d commit 59621fe
Show file tree
Hide file tree
Showing 26 changed files with 776 additions and 841 deletions.
102 changes: 61 additions & 41 deletions .github/workflows/cabal.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,71 @@
name: Cabal CI

name: build
on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches: [main, master]

# INFO: The following configuration block ensures that only one build runs per branch,
# which may be desirable for projects with a costly build process.
# Remove this block from the CI workflow to let each CI job run to completion.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: cabal-${{ matrix.cabal}} ${{ matrix.ghc }} ${{ matrix.os }}
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
ghc: ["8.10.1", "8.8.1", "8.6.5", "8.6.4", "8.6.3", "8.6.2"]
cabal: ["3.0", "3.2"]
os: [ubuntu-latest]
ghc-version: ['9.8', '9.6']

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-haskell@v1
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- uses: actions/cache@v1
name: Cache ~/.cabal/packages
with:
path: ~/.cabal/packages
key: cabal-packages-${{ matrix.ghc }}

- uses: actions/cache@v1
name: Cache ~/.cabal/store
with:
path: ~/.cabal/store
key: cabal-store-${{ matrix.ghc }}

- uses: actions/cache@v1
name: Cache dist-newstyle
with:
path: dist-newstyle
key: dist-newstyle-${{ matrix.ghc }}

- name: Install dependencies
run: |
cabal update
- name: Build
run: |
cabal new-install tasty-discover
cabal new-build
- uses: actions/checkout@v4

- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}
# Defaults, added for clarity:
cabal-version: 'latest'
cabal-update: true

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v3
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v3
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

- name: Test
run: cabal test all
60 changes: 0 additions & 60 deletions .github/workflows/stack.yml

This file was deleted.

10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log for galois-field

## 2.0.0

* Bump GHC versions to support 9.6 and 9.8 (9.4 seems to not be possible with certain
uses of RULES, see [GHC #22761](https://gitlab.haskell.org/ghc/ghc/-/issues/22761))
* Added CI with build matrix
* Bump various dep version bounds
* Switched to use `mod` package
* Removed the INLINE pragmas for `pow`, they were broken on all GHC version (see [GHC #22716](https://gitlab.haskell.org/ghc/ghc/-/issues/22716))
* Formatted with Ormolu

## 1.0.3

* Add `fromU` for RootsOfUnity
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</a>
</p>

![Stack CI](https://github.com/adjoint-io/galois-field/workflows/Stack%20CI/badge.svg)
![Cabal CI](https://github.com/adjoint-io/galois-field/workflows/Cabal%20CI/badge.svg)
[![Hackage](https://img.shields.io/hackage/v/galois-field.svg)](https://hackage.haskell.org/package/galois-field)

Expand Down
6 changes: 2 additions & 4 deletions bench/Bench/Binary.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module Bench.Binary where

import Protolude

import Bench.Galois
import Control.Monad.Random
import Criterion.Main
import Data.Field.Galois

import Bench.Galois
import Protolude

type F2m = Binary 0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425

Expand Down
14 changes: 9 additions & 5 deletions bench/Bench/Extension.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
module Bench.Extension where

import Protolude

import Bench.Galois
import Bench.Prime
import Control.Monad.Random
import Criterion.Main
import Data.Field.Galois

import Bench.Galois
import Bench.Prime
import Protolude

data PU

instance IrreducibleMonic PU Fq where
poly _ = X2 + 1

type Fq2 = Extension PU Fq

data PV

instance IrreducibleMonic PV Fq2 where
poly _ = X3 - 9 - Y X

type Fq6 = Extension PV Fq2

data PW

instance IrreducibleMonic PW Fq6 where
poly _ = X2 - Y X

type Fq12 = Extension PW Fq6

fq12 :: Fq12
Expand Down
45 changes: 23 additions & 22 deletions bench/Bench/Galois.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
module Bench.Galois where

import Protolude

import Criterion.Main
import Data.Field.Galois hiding (recip, (/))
import Data.Field.Galois
import GHC.Base
import Protolude

benchmark :: GaloisField k => String -> k -> k -> Benchmark
benchmark s a b = bgroup s
[ bench "Addition" $
nf (uncurry (+)) (a, b)
, bench "Multiplication" $
nf (uncurry (*)) (a, b)
, bench "Negation" $
nf negate a
, bench "Subtraction" $
nf (uncurry (-)) (a, b)
, bench "Inversion" $
nf recip a
, bench "Division" $
nf (uncurry (/)) (a, b)
, bench "Frobenius endomorphism" $
nf frob a
, bench "Square root" $
nf sr a
]
benchmark :: (GaloisField k) => String -> k -> k -> Benchmark
benchmark s a b =
bgroup
s
[ bench "Addition" $
nf (uncurry (+)) (a, b),
bench "Multiplication" $
nf (uncurry (*)) (a, b),
bench "Negation" $
nf negate a,
bench "Subtraction" $
nf (uncurry (-)) (a, b),
bench "Inversion" $
nf recip a,
bench "Division" $
nf (uncurry (/)) (a, b),
bench "Frobenius endomorphism" $
nf frob a,
bench "Square root" $
nf sr a
]
6 changes: 2 additions & 4 deletions bench/Bench/Prime.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module Bench.Prime where

import Protolude

import Bench.Galois
import Control.Monad.Random
import Criterion.Main
import Data.Field.Galois

import Bench.Galois
import Protolude

type Fq = Prime 21888242871839275222246405745257275088696311157297823662689037894645226208583

Expand Down
11 changes: 5 additions & 6 deletions bench/Main.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module Main where

import Protolude

import Criterion.Main

import Bench.Binary
import Bench.Extension
import Bench.Prime
import Criterion.Main
import Protolude

main :: IO ()
main = defaultMain
[benchBinary, benchExtension, benchPrime]
main =
defaultMain
[benchBinary, benchExtension, benchPrime]
10 changes: 10 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests: True
benchmarks: True

packages: .

source-repository-package
type: git
location: https://github.com/chessai/semirings.git
tag: 2631c542b57abc9bc9e92db273ab8e80ae88048c
--sha256: j/zGFd2aeowzJfgCCBmJYmG8mDsfF0irqj/cPOw9ulE=
Loading

0 comments on commit 59621fe

Please sign in to comment.