From e8c97c7bf8488910d1396913c7a4f4b4ff4d4032 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Tue, 23 Apr 2024 17:40:13 +0200 Subject: [PATCH] Example packages --- .github/workflows/haskell-ci.yml | 36 +++++++++++++++-------- cabal.project | 10 +++++++ example-pkg-A/LICENSE | 30 ++++++++++++++++++++ example-pkg-A/cbits/cbits.c | 3 ++ example-pkg-A/cbits/cbits.h | 2 ++ example-pkg-A/example-pkg-A.cabal | 47 +++++++++++++++++++++++++++++++ example-pkg-A/src/ExamplePkgA.hs | 7 +++++ example-pkg-A/test/TestA.hs | 6 ++++ example-pkg-B/LICENSE | 30 ++++++++++++++++++++ example-pkg-B/example-pkg-B.cabal | 45 +++++++++++++++++++++++++++++ example-pkg-B/src/ExamplePkgB.hs | 6 ++++ example-pkg-B/test/TestB.hs | 6 ++++ trace-foreign-calls/cabal.project | 4 --- 13 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 cabal.project create mode 100644 example-pkg-A/LICENSE create mode 100644 example-pkg-A/cbits/cbits.c create mode 100644 example-pkg-A/cbits/cbits.h create mode 100644 example-pkg-A/example-pkg-A.cabal create mode 100644 example-pkg-A/src/ExamplePkgA.hs create mode 100644 example-pkg-A/test/TestA.hs create mode 100644 example-pkg-B/LICENSE create mode 100644 example-pkg-B/example-pkg-B.cabal create mode 100644 example-pkg-B/src/ExamplePkgB.hs create mode 100644 example-pkg-B/test/TestB.hs delete mode 100644 trace-foreign-calls/cabal.project diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index ab7a3b3..4e109ba 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -1,6 +1,6 @@ # 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 # @@ -8,9 +8,9 @@ # # 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: @@ -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: @@ -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: | @@ -139,17 +141,25 @@ 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 <> 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 @@ -157,7 +167,7 @@ jobs: $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 @@ -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 @@ -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 }} diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..cf330a2 --- /dev/null +++ b/cabal.project @@ -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 diff --git a/example-pkg-A/LICENSE b/example-pkg-A/LICENSE new file mode 100644 index 0000000..5ecac80 --- /dev/null +++ b/example-pkg-A/LICENSE @@ -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. diff --git a/example-pkg-A/cbits/cbits.c b/example-pkg-A/cbits/cbits.c new file mode 100644 index 0000000..542ad71 --- /dev/null +++ b/example-pkg-A/cbits/cbits.c @@ -0,0 +1,3 @@ +int xkcdRandomNumber() { + return 4; +} \ No newline at end of file diff --git a/example-pkg-A/cbits/cbits.h b/example-pkg-A/cbits/cbits.h new file mode 100644 index 0000000..5a62d49 --- /dev/null +++ b/example-pkg-A/cbits/cbits.h @@ -0,0 +1,2 @@ +// https://xkcd.com/221/ +int xkcdRandomNumber(); \ No newline at end of file diff --git a/example-pkg-A/example-pkg-A.cabal b/example-pkg-A/example-pkg-A.cabal new file mode 100644 index 0000000..748d74b --- /dev/null +++ b/example-pkg-A/example-pkg-A.cabal @@ -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: edsko@well-typed.com +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 \ No newline at end of file diff --git a/example-pkg-A/src/ExamplePkgA.hs b/example-pkg-A/src/ExamplePkgA.hs new file mode 100644 index 0000000..b99bc19 --- /dev/null +++ b/example-pkg-A/src/ExamplePkgA.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE CApiFFI #-} + +module ExamplePkgA (someForeignFunInA) where + +import Foreign.C + +foreign import capi "cbits.h xkcdRandomNumber" someForeignFunInA :: IO CInt diff --git a/example-pkg-A/test/TestA.hs b/example-pkg-A/test/TestA.hs new file mode 100644 index 0000000..10343ca --- /dev/null +++ b/example-pkg-A/test/TestA.hs @@ -0,0 +1,6 @@ +module TestA (main) where + +import ExamplePkgA + +main :: IO () +main = print =<< someForeignFunInA \ No newline at end of file diff --git a/example-pkg-B/LICENSE b/example-pkg-B/LICENSE new file mode 100644 index 0000000..5ecac80 --- /dev/null +++ b/example-pkg-B/LICENSE @@ -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. diff --git a/example-pkg-B/example-pkg-B.cabal b/example-pkg-B/example-pkg-B.cabal new file mode 100644 index 0000000..3c76e20 --- /dev/null +++ b/example-pkg-B/example-pkg-B.cabal @@ -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: edsko@well-typed.com +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 \ No newline at end of file diff --git a/example-pkg-B/src/ExamplePkgB.hs b/example-pkg-B/src/ExamplePkgB.hs new file mode 100644 index 0000000..2a99480 --- /dev/null +++ b/example-pkg-B/src/ExamplePkgB.hs @@ -0,0 +1,6 @@ +module ExamplePkgB (someWrapperInB) where + +import ExamplePkgA + +someWrapperInB :: IO Int +someWrapperInB = fromIntegral <$> someForeignFunInA \ No newline at end of file diff --git a/example-pkg-B/test/TestB.hs b/example-pkg-B/test/TestB.hs new file mode 100644 index 0000000..bb97825 --- /dev/null +++ b/example-pkg-B/test/TestB.hs @@ -0,0 +1,6 @@ +module TestB (main) where + +import ExamplePkgB + +main :: IO () +main = print =<< someWrapperInB \ No newline at end of file diff --git a/trace-foreign-calls/cabal.project b/trace-foreign-calls/cabal.project deleted file mode 100644 index 3f69c86..0000000 --- a/trace-foreign-calls/cabal.project +++ /dev/null @@ -1,4 +0,0 @@ -packages: . - -package trace-foreign-calls - tests: True