Skip to content

Commit 1e4f909

Browse files
authored
Switch to Nix flakes; make the tests pass with newest ArrayFire (#55)
* Switch to Nix flakes; make the tests pass with nix build & nix develop for the latest version of ArrayFire * update flake.lock
1 parent 5e69254 commit 1e4f909

File tree

5 files changed

+208
-5
lines changed

5 files changed

+208
-5
lines changed

arrayfire.cabal

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ flag disable-default-paths
2121
default: False
2222
manual: True
2323

24+
flag disable-build-tool-depends
25+
description: When enabled, don't add build-tool-depends fields to the Cabal file. Needed for working inside @nix develop@.
26+
default: False
27+
manual: True
28+
2429
custom-setup
2530
setup-depends:
2631
base <5,
@@ -75,8 +80,9 @@ library
7580
ArrayFire.Internal.Types
7681
ArrayFire.Internal.Util
7782
ArrayFire.Internal.Vision
78-
build-tool-depends:
79-
hsc2hs:hsc2hs
83+
if !flag(disable-build-tool-depends)
84+
build-tool-depends:
85+
hsc2hs:hsc2hs
8086
extra-libraries:
8187
af
8288
c-sources:
@@ -148,8 +154,9 @@ test-suite test
148154
QuickCheck,
149155
quickcheck-classes,
150156
vector
151-
build-tool-depends:
152-
hspec-discover:hspec-discover
157+
if !flag(disable-build-tool-depends)
158+
build-tool-depends:
159+
hspec-discover:hspec-discover
153160
default-language:
154161
Haskell2010
155162
other-modules:

cabal.project

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignore-project: False
2+
write-ghc-environment-files: always
3+
tests: True
4+
test-options: "--color"
5+
test-show-details: streaming

flake.lock

+101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
description = "arrayfire/arrayfire-haskell: ArrayFire Haskell bindings";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
nix-filter.url = "github:numtide/nix-filter";
8+
arrayfire-nix = {
9+
url = "github:twesterhout/arrayfire-nix";
10+
inputs.flake-utils.follows = "flake-utils";
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
};
13+
};
14+
15+
outputs = inputs:
16+
let
17+
src = inputs.nix-filter.lib {
18+
root = ./.;
19+
include = [
20+
"cbits"
21+
"exe"
22+
"gen"
23+
"include"
24+
"src"
25+
"test"
26+
"arrayfire.cabal"
27+
"README.md"
28+
"CHANGELOG.md"
29+
"LICENSE"
30+
];
31+
};
32+
33+
# An overlay that lets us test arrayfire-haskell with different GHC versions
34+
arrayfire-haskell-overlay = self: super: {
35+
haskell = super.haskell // {
36+
packageOverrides = inputs.nixpkgs.lib.composeExtensions super.haskell.packageOverrides
37+
(hself: hsuper: {
38+
arrayfire = self.haskell.lib.appendConfigureFlags
39+
(hself.callCabal2nix "arrayfire" src { af = self.arrayfire; })
40+
[ "-f disable-default-paths" ];
41+
});
42+
};
43+
};
44+
45+
devShell-for = pkgs:
46+
let
47+
ps = pkgs.haskellPackages;
48+
in
49+
ps.shellFor {
50+
packages = ps: with ps; [ arrayfire ];
51+
withHoogle = true;
52+
buildInputs = with pkgs; [ ocl-icd ];
53+
nativeBuildInputs = with pkgs; with ps; [
54+
# Building and testing
55+
cabal-install
56+
doctest
57+
hsc2hs
58+
hspec-discover
59+
# Language servers
60+
haskell-language-server
61+
nil
62+
# Formatters
63+
nixpkgs-fmt
64+
];
65+
shellHook = ''
66+
'';
67+
};
68+
69+
pkgs-for = system: import inputs.nixpkgs {
70+
inherit system;
71+
overlays = [
72+
inputs.arrayfire-nix.overlays.default
73+
arrayfire-haskell-overlay
74+
];
75+
};
76+
in
77+
{
78+
packages = inputs.flake-utils.lib.eachDefaultSystemMap (system:
79+
with (pkgs-for system); {
80+
default = haskellPackages.arrayfire;
81+
haskell = haskell.packages;
82+
});
83+
84+
devShells = inputs.flake-utils.lib.eachDefaultSystemMap (system: {
85+
default = devShell-for (pkgs-for system);
86+
});
87+
88+
overlays.default = arrayfire-haskell-overlay;
89+
};
90+
}

test/ArrayFire/UtilSpec.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec =
3232
it "Should get version" $ do
3333
(major, minor, patch) <- A.getVersion
3434
major `shouldBe` 3
35-
minor `shouldBe` 8
35+
minor `shouldSatisfy` (>= 8)
3636
patch `shouldSatisfy` (>= 0)
3737
it "Should get revision" $ do
3838
x <- A.getRevision

0 commit comments

Comments
 (0)