Skip to content

Commit 8914928

Browse files
authored
Add nix build to CI (#67)
* Update nix build * `hspec-discover` * Use flakes * `autoPatchelfIgnoreMissingDeps = true;` * `cabal update`, `cabal install hspec-discover` * `export LD_LIBRARY_PATH` for ci.
1 parent 5fd9033 commit 8914928

4 files changed

Lines changed: 58 additions & 62 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1-
name: CI
2-
1+
name: ArrayFire CI
32
on:
43
push:
5-
branches: [master]
4+
branches:
5+
- master
66
pull_request:
7-
branches: [master]
7+
8+
env:
9+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
810

911
jobs:
1012
build:
11-
runs-on: macos-latest
12-
13+
runs-on: ubuntu-latest
1314
steps:
1415
- uses: actions/checkout@v4
1516

16-
- name: Install ArrayFire
17-
run: brew install arrayfire
18-
19-
- name: Set up GHC
20-
uses: haskell-actions/setup@v2
21-
with:
22-
ghc-version: '9.8.4'
23-
cabal-version: 'latest'
24-
25-
- name: Cache cabal store
26-
uses: actions/cache@v4
17+
- uses: cachix/install-nix-action@v31
2718
with:
28-
path: ~/.cabal/store
29-
key: ${{ runner.os }}-cabal-${{ hashFiles('cabal.project', '*.cabal') }}
30-
restore-keys: |
31-
${{ runner.os }}-cabal-
19+
nix_path: nixpkgs=channel:nixpkgs-unstable
3220

33-
- name: Configure
34-
run: cabal configure --flags="disable-default-paths disable-build-tool-depends" --extra-include-dirs=$(brew --prefix arrayfire)/include --extra-lib-dirs=$(brew --prefix arrayfire)/lib
21+
- name: Nix channel --update
22+
run: nix-channel --update
3523

36-
- name: Build
37-
run: cabal build arrayfire
24+
- name: Cabal update
25+
run: nix develop --command bash -c 'cabal update'
3826

27+
- name: Build and run tests
28+
run: nix develop --command bash -c 'cabal install hspec-discover && cabal test'

arrayfire.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license: BSD-3-Clause
77
license-file: LICENSE
88
author: David Johnson
99
maintainer: code@dmj.io
10-
copyright: David Johnson (c) 2018-2025
10+
copyright: David Johnson (c) 2018-2026
1111
category: Math
1212
build-type: Custom
1313
extra-source-files: CHANGELOG.md
@@ -88,7 +88,7 @@ library
8888
c-sources:
8989
cbits/wrapper.c
9090
build-depends:
91-
base < 5, filepath, vector
91+
base < 5, deepseq, filepath, vector
9292
hs-source-dirs:
9393
src
9494
ghc-options:

flake.lock

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
77
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-
};
138
};
149

1510
outputs = inputs:
@@ -30,13 +25,50 @@
3025
];
3126
};
3227

28+
# Build ArrayFire from the official binary installer; avoids freeimage entirely.
29+
mkArrayfire = pkgs: pkgs.stdenv.mkDerivation rec {
30+
pname = "arrayfire";
31+
version = "3.10.0";
32+
src = pkgs.fetchurl {
33+
url = "https://arrayfire.s3.amazonaws.com/${version}/ArrayFire-v${version}_Linux_x86_64.sh";
34+
hash = "sha256-8SibCWnRxts79S6WEHb3skF2TIDl1QnjY6EiohmoIog=";
35+
};
36+
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
37+
# GPU/visualization libs (CUDA, OpenGL, GLFW, FreeImage, Intel OpenCL) are
38+
# optional ArrayFire backends not available in headless CI environments.
39+
autoPatchelfIgnoreMissingDeps = true;
40+
buildInputs = with pkgs; [
41+
stdenv.cc.cc.lib
42+
fftw
43+
fftwFloat
44+
openblas
45+
ocl-icd
46+
boost.out
47+
];
48+
unpackPhase = "true";
49+
installPhase = ''
50+
mkdir -p $out
51+
bash $src --exclude-subdir --prefix=$out
52+
'';
53+
meta = {
54+
description = "A general-purpose library for parallel and massively-parallel architectures";
55+
platforms = [ "x86_64-linux" ];
56+
};
57+
};
58+
59+
arrayfire-overlay = self: super: {
60+
arrayfire = mkArrayfire self;
61+
};
62+
3363
# An overlay that lets us test arrayfire-haskell with different GHC versions
3464
arrayfire-haskell-overlay = self: super: {
3565
haskell = super.haskell // {
3666
packageOverrides = inputs.nixpkgs.lib.composeExtensions super.haskell.packageOverrides
3767
(hself: hsuper: {
3868
arrayfire = self.haskell.lib.appendConfigureFlags
39-
(hself.callCabal2nix "arrayfire" src { af = self.arrayfire; })
69+
(hself.callCabal2nix "arrayfire" src {
70+
af = self.arrayfire;
71+
})
4072
[ "-f disable-default-paths" ];
4173
});
4274
};
@@ -55,21 +87,20 @@
5587
cabal-install
5688
doctest
5789
hsc2hs
58-
hspec-discover
59-
# Language servers
60-
haskell-language-server
90+
# hspec-discover
6191
nil
6292
# Formatters
6393
nixpkgs-fmt
6494
];
6595
shellHook = ''
96+
export LD_LIBRARY_PATH="${pkgs.arrayfire}/lib:$LD_LIBRARY_PATH"
6697
'';
6798
};
6899

69100
pkgs-for = system: import inputs.nixpkgs {
70101
inherit system;
71102
overlays = [
72-
inputs.arrayfire-nix.overlays.default
103+
arrayfire-overlay
73104
arrayfire-haskell-overlay
74105
];
75106
};
@@ -78,7 +109,6 @@
78109
packages = inputs.flake-utils.lib.eachDefaultSystemMap (system:
79110
with (pkgs-for system); {
80111
default = haskellPackages.arrayfire;
81-
haskell = haskell.packages;
82112
});
83113

84114
devShells = inputs.flake-utils.lib.eachDefaultSystemMap (system: {

0 commit comments

Comments
 (0)