diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3a3d0d7..c321cf2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,13 +25,26 @@ jobs: - name: Install packages run: | if [ ${{ matrix.os }} == "ubuntu-latest" ] ; then - sudo apt-get update -qq && sudo apt-get install -y gobjc++ libgnustep-base-dev + sudo apt-get update -qq && sudo apt-get install -y gobjc++ libgnustep-base-dev libgsl-dev + else + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + brew install gsl || true fi - uses: actions/cache@v3 with: path: ~/.stack key: stack-${{ matrix.os }}-${{ matrix.stackage }}-${{ hashFiles('stack.yaml') }} - name: Build - run: stack build --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c-cpp:std-vector-example + run: | + if [ ${{ matrix.os }} == "ubuntu-latest" ] ; then + stack build --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example + else + stack build --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c-cpp:std-vector-example + fi - name: Test - run: stack test --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c-cpp:std-vector-example + run: | + if [ ${{ matrix.os }} == "ubuntu-latest" ] ; then + stack test --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example + else + stack test --stack-yaml stack-${{ matrix.stackage }}.yaml --flag inline-c-cpp:std-vector-example + fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1849d5e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,78 +0,0 @@ -# Use new container infrastructure to enable caching -sudo: false - -# Choose a lightweight base image; we provide our own build tools. -language: c - -# GHC depends on GMP. You can add other dependencies here as well. -addons: - apt: - packages: - - libgmp-dev - - libgsl0-dev - - libcairo2-dev - homebrew: - packages: - - cairo - - gsl - -matrix: - include: - - env: ARGS="--flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example" - - env: ARGS="--stack-yaml stack-nightly-2021-01-01.yaml --flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example" - - env: ARGS="--stack-yaml stack-lts-14.27.yaml --flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example" - - env: ARGS="--stack-yaml stack-lts-12.26.yaml --flag inline-c:gsl-example --flag inline-c-cpp:std-vector-example" - - - env: ARGS="--flag inline-c-cpp:std-vector-example" - os: osx - - env: ARGS="--stack-yaml stack-nightly-2021-01-01.yaml --flag inline-c-cpp:std-vector-example" - os: osx - - env: ARGS="--stack-yaml stack-lts-14.27.yaml --flag inline-c-cpp:std-vector-example" - os: osx - # LTS 12.26 fails with - # inline-c-cpp > Linking .stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/tests/tests ... - # inline-c-cpp > clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] - # inline-c-cpp > clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument] - # inline-c-cpp > - # inline-c-cpp > /Users/travis/build/fpco/inline-c/inline-c-cpp/In file included from /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/ghc9189_0/ghc_3.c:1:0: error: - # inline-c-cpp > - # inline-c-cpp > - # inline-c-cpp > /Users/travis/build/fpco/inline-c/inline-c-cpp/In file included from /Users/travis/.stack/programs/x86_64-osx/ghc-8.4.4/lib/ghc-8.4.4/include/Rts.h:29:0: error: - # inline-c-cpp > - # inline-c-cpp > - # inline-c-cpp > /Users/travis/build/fpco/inline-c/inline-c-cpp//Users/travis/.stack/programs/x86_64-osx/ghc-8.4.4/lib/ghc-8.4.4/include/Stg.h:29:3: error: - # inline-c-cpp > error: __STDC_VERSION__ does not advertise C99 or later - # inline-c-cpp > | - # inline-c-cpp > 29 | # error __STDC_VERSION__ does not advertise C99 or later - # inline-c-cpp > | ^ - # inline-c-cpp > # error __STDC_VERSION__ does not advertise C99 or later - # - env: ARGS="--stack-yaml stack-lts-12.26.yaml --flag inline-c-cpp:std-vector-example" - # os: osx - -before_install: -# Download and unpack the stack executable -- mkdir -p ~/.local/bin -- export PATH=$HOME/.local/bin:$PATH -- | - if [ `uname` = "Darwin" ] - then - travis_retry sh -c "curl --insecure -L https://get.haskellstack.org/stable/osx-x86_64.tar.gz | tar xz --strip-components=1 --include '*/stack' -C ~/.local/bin" - else - travis_retry sh -c "curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'" - fi - -# This line does all of the work: installs GHC if necessary, build the library, -# executables, and test suites, and runs the test suites. --no-terminal works -# around some quirks in Travis's terminal implementation. -# -j1: work around /tmp/stack-ce322b87c3e4fa73/test-ghc-env: openBinaryFile: resource busy (file is locked) -# as suggested by ulidtko here https://github.com/commercialhaskell/stack/issues/5024#issuecomment-690063488 -script: stack --no-terminal --install-ghc test -j1 --haddock $ARGS - -# Caching so the next build will be fast too. -cache: - directories: - - $HOME/.stack - - .stack-work - - inline-c/.stack-work/ - - inline-c-cpp/.stack-work/ - - sample-cabal-project/.stack-work/ diff --git a/inline-c/examples/gsl-ode.hs b/inline-c/examples/gsl-ode.hs index b1d5007..9ec8ce9 100644 --- a/inline-c/examples/gsl-ode.hs +++ b/inline-c/examples/gsl-ode.hs @@ -3,7 +3,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE MultiWayIf #-} -import Data.Coerce (coerce) +import Unsafe.Coerce (unsafeCoerce) import Data.Monoid ((<>)) import qualified Data.Vector.Storable as V import qualified Data.Vector.Storable.Mutable as VM @@ -11,11 +11,11 @@ import Foreign.C.Types import Foreign.ForeignPtr (newForeignPtr_) import Foreign.Ptr (Ptr) import Foreign.Storable (Storable) -import qualified Graphics.Rendering.Chart.Backend.Cairo as Chart -import qualified Graphics.Rendering.Chart.Easy as Chart import qualified Language.C.Inline as C import qualified Language.C.Inline.Unsafe as CU import System.IO.Unsafe (unsafePerformIO) +import Control.Monad (forM_) +import System.IO (withFile, hPutStrLn, IOMode(..)) C.context (C.baseCtx <> C.vecCtx <> C.funCtx) @@ -94,7 +94,7 @@ solveOde -> Either String (V.Vector Double) -- ^ Solution at end point, or error. solveOde fun x0 f0 xend = - coerce $ solveOdeC (coerce fun) (coerce x0) (coerce f0) (coerce xend) + unsafeCoerce $ solveOdeC (unsafeCoerce fun) (unsafeCoerce x0) (unsafeCoerce f0) (unsafeCoerce xend) lorenz :: Double @@ -121,9 +121,9 @@ lorenz x0 f0 xend = solveOde fun x0 f0 xend ] main :: IO () -main = Chart.toFile Chart.def "lorenz.png" $ do - Chart.layout_title Chart..= "Lorenz" - Chart.plot $ Chart.line "curve" [pts] +main = withFile "lorenz.csv" WriteMode $ \h -> + forM_ pts $ \(x,y) -> + hPutStrLn h $ show x ++ ", " ++ show y where pts = [(f V.! 0, f V.! 2) | (_x, f) <- go 0 (V.fromList [10.0 , 1.0 , 1.0])] diff --git a/inline-c/inline-c.cabal b/inline-c/inline-c.cabal index ae33e51..04c8f96 100644 --- a/inline-c/inline-c.cabal +++ b/inline-c/inline-c.cabal @@ -88,7 +88,5 @@ executable gsl-ode build-depends: base >=4 && <5 , inline-c , vector - , Chart >= 1.3 - , Chart-cairo else buildable: False diff --git a/stack-lts-20.yaml b/stack-lts-20.yaml index 1823663..9959c4e 100644 --- a/stack-lts-20.yaml +++ b/stack-lts-20.yaml @@ -4,7 +4,3 @@ packages: - inline-c-cpp - inline-c-objc - sample-cabal-project -extra-deps: -- Chart-cairo-1.9.3@sha256:f484a7194ca08ed67f02aa626e2f8f4d1a9b50624e0d50e3ced62958f7481cca,925 -- cairo-0.13.8.0@sha256:9b64a376ebaa4f153bba5866a32291fd4bed48147009cce9158ce6533928eba8,4075 -- gtk2hs-buildtools-0.13.8.0@sha256:132f38155fc677430a47ea750918973161c876fb6f281d342ac2f07eb99229ce,5238 diff --git a/stack-lts-21.yaml b/stack-lts-21.yaml index 635befd..e339fe4 100644 --- a/stack-lts-21.yaml +++ b/stack-lts-21.yaml @@ -4,7 +4,3 @@ packages: - inline-c-cpp - inline-c-objc - sample-cabal-project -extra-deps: -- Chart-cairo-1.9.3@sha256:f484a7194ca08ed67f02aa626e2f8f4d1a9b50624e0d50e3ced62958f7481cca,925 -- cairo-0.13.8.0@sha256:9b64a376ebaa4f153bba5866a32291fd4bed48147009cce9158ce6533928eba8,4075 -- gtk2hs-buildtools-0.13.8.0@sha256:132f38155fc677430a47ea750918973161c876fb6f281d342ac2f07eb99229ce,5238 diff --git a/stack-nightly.yaml b/stack-nightly.yaml index 2e612a0..aba2285 100644 --- a/stack-nightly.yaml +++ b/stack-nightly.yaml @@ -4,7 +4,3 @@ packages: - inline-c-cpp - inline-c-objc - sample-cabal-project -extra-deps: -- Chart-cairo-1.9.3@sha256:f484a7194ca08ed67f02aa626e2f8f4d1a9b50624e0d50e3ced62958f7481cca,925 -- cairo-0.13.8.0@sha256:9b64a376ebaa4f153bba5866a32291fd4bed48147009cce9158ce6533928eba8,4075 -- gtk2hs-buildtools-0.13.8.0@sha256:132f38155fc677430a47ea750918973161c876fb6f281d342ac2f07eb99229ce,5238