Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure build and ci #7

Merged
merged 10 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/workflows/main-pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: CI Pull Request

on:
pull_request:
branches: [main]

permissions:
contents: write

env:
CARGO_TERM_COLOR: always

jobs:
on-main-pull-request:

strategy:
matrix:
os: [ubuntu-latest]
cabal: [3.10.2.1]
ghc: [9.6.3]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Haskell
uses: haskell-actions/[email protected]
id: setup
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
cabal-update: true

- name: Set up rustup nightly
run: |
rustup toolchain install nightly

- name: Set up cargo-c
run: |
cargo install cargo-c

- name: Configure Cabal
run: |
cabal update
cabal configure --enable-tests --enable-benchmarks --enable-documentation

- name: Generate cache key
# Creates plan.json file
run: |
cabal build all --dry-run

- name: Restore cached dependencies
uses: actions/cache/[email protected]
id: cache
env:
key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-cabal-${{ matrix.cabal }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install stylish-haskell
run: |
cabal install stylish-haskell-0.14.5.0

- name: Cargo clippy
run: |
cargo clippy --manifest-path rust-wrapper/Cargo.toml -- -D warnings

- name: Rust format
run: |
cargo fmt --manifest-path rust-wrapper/Cargo.toml

- name: Lint Haskell
run: |
find . -name '*.hs' -exec sh -c 'for file do stylish-haskell --inplace "$file"; done' sh {} +

- name: Auto-commit lint
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: stylish-haskell auto-commit
commit_user_name: GitHub Action
commit_user_email: [email protected]
branch: ${{ github.head_ref }}

- 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/[email protected]
# 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 -f Pedantic

# - name: Test
# run: cabal test all

# - name: Check cabal file
# run: cabal check

# - name: Document package
# run: cabal haddock all

# - name: Prepare package for publishing
# run: cabal sdist all
58 changes: 58 additions & 0 deletions .github/workflows/main-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI Push

on:
push:
branches: [ main ]

workflow_dispatch:

env:
CARGO_TERM_COLOR: always

permissions:
contents: read

jobs:
on-main-update:

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: haskell-actions/[email protected]
with:
ghc-version: '9.6.3'
cabal-version: '3.10.2.1'

- name: Set up cargo-c
run: |
cargo install cargo-c

- name: Cache
uses: actions/[email protected]
env:
cache-name: cache-cabal
with:
path: ~/.cabal
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Build package
shell: bash
run: |
cabal update
cabal build all -f Pedantic

- name: Upload package
vlasin marked this conversation as resolved.
Show resolved Hide resolved
env:
HACKAGE_PASSWORD: ${{ secrets.HACKAGE_PASSWORD }}
shell: bash
run: |
cabal sdist symbolic-base
cabal upload --username=VladimirSinyakov --password="$HACKAGE_PASSWORD" dist-newstyle/sdist/*.tar.gz

cabal v2-haddock symbolic-base --haddock-for-hackage --enable-doc
cabal upload --documentation --username=VladimirSinyakov --password="$HACKAGE_PASSWORD" dist-newstyle/*-docs.tar.gz
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ cabal.project.local~
.ghc.environment.*
rust-wrapper/target/
rust-wrapper/Cargo.lock
rust-wrapper/haskell-wrapper/cbits/rust-wrapper.h
lib.so
*.data
*.svg
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ Install rustup and cargo (require `curl`):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

Install nightly:
```bash
rustup toolchain install nightly
```

<!-- gcc*
```bash
sudo apt install gcc
``` -->

Install cbindgen (require `gcc`):
```bash
cargo install --force cbindgen
```
<!-- openssl*
```bash
sudo apt-get install libssl-dev
Expand All @@ -38,14 +39,6 @@ Install cargo-c (require `openssl` and `pkg-config`):
cargo install cargo-c
```

### Build Rust wrap

You need to run the file `run.sh` from the project directory (or specify the path in the file).

```bash
source ./run.sh
```

### Build, Tests and Examples

The package compiles with GHC 9.6.3 and Cabal 3.10.2.1.
Expand Down
48 changes: 31 additions & 17 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import Distribution.Simple
import System.Process
import Control.Monad
import Distribution.Types.HookedBuildInfo
import System.Exit
import Control.Exception (throwIO)
import Control.Monad
import Data.Char (isSpace)
import Data.List (dropWhile, isPrefixOf)
import Distribution.Simple
import Distribution.Types.HookedBuildInfo
import System.Directory
import System.Exit
import System.Process (readProcess, system)

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ preConf = runMyScript

{ preConf = buildRustLib
}

runMyScript :: Args -> a -> IO HookedBuildInfo
runMyScript args flags = do
putStrLn "Running pre-script..."
executeShellCommand "source ./run.sh"
return $ emptyHookedBuildInfo

executeShellCommand cmd = putStrLn ("EXEC: " ++ cmd) >> system cmd >>= check
where
check ExitSuccess = return ()
check (ExitFailure n) = error $ "cmd: " ++ cmd ++ " failure code " ++ show n
buildRustLib :: Args -> a -> IO HookedBuildInfo
buildRustLib _ flags = do

buildResult <- system "cargo +nightly cbuild --release --manifest-path rust-wrapper/Cargo.toml"
case buildResult of
ExitSuccess -> return ()
ExitFailure exitCode -> throwIO $ userError $ "Build rust library failed with exit code " <> show exitCode

output <- readProcess "rustc" ["--version", "--verbose"] ""
case filter ("host: " `isPrefixOf`) (lines output) of
[line] -> do
let host = dropWhile isSpace $ drop 5 line
pathToLib = "rust-wrapper/target/" <> host <> "/release/librust_wrapper.so"

libExist <- doesFileExist pathToLib
unless libExist $ throwIO $ userError "Can't find rust library"

copyFile pathToLib "./lib.so"

_ -> throwIO $ userError "Can't find default rust target"
return emptyHookedBuildInfo
26 changes: 0 additions & 26 deletions haskell-wrapper/src/BN254/BN254.hs

This file was deleted.

50 changes: 0 additions & 50 deletions haskell-wrapper/src/Functions.chs

This file was deleted.

Loading
Loading