Skip to content

Commit

Permalink
Example packages
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Apr 23, 2024
1 parent caa65b0 commit e8c97c7
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 15 deletions.
36 changes: 25 additions & 11 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# This GitHub workflow config has been generated by a script via
#
# haskell-ci 'github' 'cabal.project.ci'
# haskell-ci 'github' 'cabal.project'
#
# To regenerate the script (for example after adjusting tested-with) run
#
# haskell-ci regenerate
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.19.20240402
# version: 0.19.20240421
#
# REGENDATA ("0.19.20240402",["github","cabal.project.ci"])
# REGENDATA ("0.19.20240421",["github","cabal.project"])
#
name: Haskell-CI
on:
Expand All @@ -23,7 +23,7 @@ jobs:
timeout-minutes:
60
container:
image: buildpack-deps:bionic
image: buildpack-deps:jammy
continue-on-error: ${{ matrix.allow-failure }}
strategy:
matrix:
Expand Down Expand Up @@ -119,13 +119,15 @@ jobs:
chmod a+x $HOME/.cabal/bin/cabal-plan
cabal-plan --version
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: source
- name: initial cabal.project for sdist
run: |
touch cabal.project
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
echo "packages: $GITHUB_WORKSPACE/source/trace-foreign-calls" >> cabal.project
echo "packages: $GITHUB_WORKSPACE/source/example-pkg-A" >> cabal.project
echo "packages: $GITHUB_WORKSPACE/source/example-pkg-B" >> cabal.project
cat cabal.project
- name: sdist
run: |
Expand All @@ -139,25 +141,33 @@ jobs:
run: |
PKGDIR_trace_foreign_calls="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/trace-foreign-calls-[0-9.]*')"
echo "PKGDIR_trace_foreign_calls=${PKGDIR_trace_foreign_calls}" >> "$GITHUB_ENV"
PKGDIR_example_pkg_A="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/example-pkg-A-[0-9.]*')"
echo "PKGDIR_example_pkg_A=${PKGDIR_example_pkg_A}" >> "$GITHUB_ENV"
PKGDIR_example_pkg_B="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/example-pkg-B-[0-9.]*')"
echo "PKGDIR_example_pkg_B=${PKGDIR_example_pkg_B}" >> "$GITHUB_ENV"
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_trace_foreign_calls}" >> cabal.project
echo "packages: ${PKGDIR_example_pkg_A}" >> cabal.project
echo "packages: ${PKGDIR_example_pkg_B}" >> cabal.project
echo "package trace-foreign-calls" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
echo "package example-pkg-A" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
echo "package example-pkg-B" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
package trace-foreign-calls
tests: True
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(trace-foreign-calls)$/; }' >> cabal.project.local
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(example-pkg-A|example-pkg-B|trace-foreign-calls)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all
cabal-plan
- name: restore cache
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
Expand All @@ -179,6 +189,10 @@ jobs:
run: |
cd ${PKGDIR_trace_foreign_calls} || false
${CABAL} -vnormal check
cd ${PKGDIR_example_pkg_A} || false
${CABAL} -vnormal check
cd ${PKGDIR_example_pkg_B} || false
${CABAL} -vnormal check
- name: haddock
run: |
$CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
Expand All @@ -187,7 +201,7 @@ jobs:
rm -f cabal.project.local
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
- name: save cache
uses: actions/cache/save@v3
uses: actions/cache/save@v4
if: always()
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
Expand Down
10 changes: 10 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
packages: trace-foreign-calls, example-pkg-A, example-pkg-B

package trace-foreign-calls
tests: True

package example-pkg-A
tests: True

package example-pkg-B
tests: True
30 changes: 30 additions & 0 deletions example-pkg-A/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2024, Edsko de Vries

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Edsko de Vries nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions example-pkg-A/cbits/cbits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int xkcdRandomNumber() {
return 4;
}
2 changes: 2 additions & 0 deletions example-pkg-A/cbits/cbits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// https://xkcd.com/221/
int xkcdRandomNumber();
47 changes: 47 additions & 0 deletions example-pkg-A/example-pkg-A.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cabal-version: 3.0
name: example-pkg-A
version: 0.1.0
synopsis: Example package A
description: This is an example that imports a foreign function. The
function is used in example package B.
license: BSD-3-Clause
license-file: LICENSE
author: Edsko de Vries
maintainer: [email protected]
category: Development
build-type: Simple
extra-source-files: cbits/cbits.h
cbits/cbits.c
tested-with: GHC ==9.6.4

common lang
ghc-options:
-Wall
build-depends:
base >= 4.18 && < 4.19
default-language:
GHC2021

library
import:
lang
exposed-modules:
ExamplePkgA
hs-source-dirs:
src
include-dirs:
cbits
c-sources:
cbits/cbits.c

test-suite test-A
import:
lang
ghc-options:
-main-is TestA
type:
exitcode-stdio-1.0
main-is:
test/TestA.hs
build-depends:
example-pkg-A
7 changes: 7 additions & 0 deletions example-pkg-A/src/ExamplePkgA.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE CApiFFI #-}

module ExamplePkgA (someForeignFunInA) where

import Foreign.C

foreign import capi "cbits.h xkcdRandomNumber" someForeignFunInA :: IO CInt
6 changes: 6 additions & 0 deletions example-pkg-A/test/TestA.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TestA (main) where

import ExamplePkgA

main :: IO ()
main = print =<< someForeignFunInA
30 changes: 30 additions & 0 deletions example-pkg-B/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2024, Edsko de Vries

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Edsko de Vries nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 changes: 45 additions & 0 deletions example-pkg-B/example-pkg-B.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cabal-version: 3.0
name: example-pkg-B
version: 0.1.0
synopsis: Example package B
description: This is an example of a package with a /dependency/ that
imports a foreign function. We want to be able to enable
the plugin on that dependency, without changing its
cabal file.
license: BSD-3-Clause
license-file: LICENSE
author: Edsko de Vries
maintainer: [email protected]
category: Development
build-type: Simple
tested-with: GHC ==9.6.4

common lang
ghc-options:
-Wall
build-depends:
base >= 4.18 && < 4.19
default-language:
GHC2021

library
import:
lang
exposed-modules:
ExamplePkgB
hs-source-dirs:
src
build-depends:
example-pkg-A >= 0.1 && < 2

test-suite test-B
import:
lang
ghc-options:
-main-is TestB
type:
exitcode-stdio-1.0
main-is:
test/TestB.hs
build-depends:
example-pkg-B
6 changes: 6 additions & 0 deletions example-pkg-B/src/ExamplePkgB.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ExamplePkgB (someWrapperInB) where

import ExamplePkgA

someWrapperInB :: IO Int
someWrapperInB = fromIntegral <$> someForeignFunInA
6 changes: 6 additions & 0 deletions example-pkg-B/test/TestB.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TestB (main) where

import ExamplePkgB

main :: IO ()
main = print =<< someWrapperInB
4 changes: 0 additions & 4 deletions trace-foreign-calls/cabal.project

This file was deleted.

0 comments on commit e8c97c7

Please sign in to comment.