From 3915cdaa87ee57c95bb8d6435990f305b8356ddc Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 24 May 2026 19:09:42 -0500 Subject: [PATCH 1/6] Update nix build --- .github/workflows/ci.yml | 14 ++++++++++-- flake.lock | 24 --------------------- flake.nix | 46 +++++++++++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88ced05..962d9c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,10 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable + - run: nix-channel --update - name: Install ArrayFire run: brew install arrayfire @@ -34,5 +38,11 @@ jobs: 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 - name: Build - run: cabal build arrayfire - + run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal build' + env: + LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" + + - name: Nix build + run: nix build + env: + LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" diff --git a/flake.lock b/flake.lock index 27da0e5..c767330 100644 --- a/flake.lock +++ b/flake.lock @@ -1,28 +1,5 @@ { "nodes": { - "arrayfire-nix": { - "inputs": { - "flake-utils": [ - "flake-utils" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1692793973, - "narHash": "sha256-6dG41ile3T+6dfRazlcPBdKBarGesswsBpb40Lcf35U=", - "owner": "twesterhout", - "repo": "arrayfire-nix", - "rev": "4236770612b80a3f29adbd8d670f6cea2bc098ba", - "type": "github" - }, - "original": { - "owner": "twesterhout", - "repo": "arrayfire-nix", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -74,7 +51,6 @@ }, "root": { "inputs": { - "arrayfire-nix": "arrayfire-nix", "flake-utils": "flake-utils", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" diff --git a/flake.nix b/flake.nix index d7f0af7..c79dea1 100644 --- a/flake.nix +++ b/flake.nix @@ -5,11 +5,6 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; nix-filter.url = "github:numtide/nix-filter"; - arrayfire-nix = { - url = "github:twesterhout/arrayfire-nix"; - inputs.flake-utils.follows = "flake-utils"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = inputs: @@ -30,13 +25,47 @@ ]; }; + # Build ArrayFire from the official binary installer; avoids freeimage entirely. + mkArrayfire = pkgs: pkgs.stdenv.mkDerivation rec { + pname = "arrayfire"; + version = "3.10.0"; + src = pkgs.fetchurl { + url = "https://arrayfire.s3.amazonaws.com/${version}/ArrayFire-v${version}_Linux_x86_64.sh"; + hash = "sha256-8SibCWnRxts79S6WEHb3skF2TIDl1QnjY6EiohmoIog="; + }; + nativeBuildInputs = [ pkgs.autoPatchelfHook ]; + buildInputs = with pkgs; [ + stdenv.cc.cc.lib + fftw + fftwFloat + openblas + ocl-icd + boost.out + ]; + unpackPhase = "true"; + installPhase = '' + mkdir -p $out + bash $src --exclude-subdir --prefix=$out + ''; + meta = { + description = "A general-purpose library for parallel and massively-parallel architectures"; + platforms = [ "x86_64-linux" ]; + }; + }; + + arrayfire-overlay = self: super: { + arrayfire = mkArrayfire self; + }; + # An overlay that lets us test arrayfire-haskell with different GHC versions arrayfire-haskell-overlay = self: super: { haskell = super.haskell // { packageOverrides = inputs.nixpkgs.lib.composeExtensions super.haskell.packageOverrides (hself: hsuper: { arrayfire = self.haskell.lib.appendConfigureFlags - (hself.callCabal2nix "arrayfire" src { af = self.arrayfire; }) + (hself.callCabal2nix "arrayfire" src { + af = self.arrayfire; + }) [ "-f disable-default-paths" ]; }); }; @@ -56,8 +85,6 @@ doctest hsc2hs hspec-discover - # Language servers - haskell-language-server nil # Formatters nixpkgs-fmt @@ -69,7 +96,7 @@ pkgs-for = system: import inputs.nixpkgs { inherit system; overlays = [ - inputs.arrayfire-nix.overlays.default + arrayfire-overlay arrayfire-haskell-overlay ]; }; @@ -78,7 +105,6 @@ packages = inputs.flake-utils.lib.eachDefaultSystemMap (system: with (pkgs-for system); { default = haskellPackages.arrayfire; - haskell = haskell.packages; }); devShells = inputs.flake-utils.lib.eachDefaultSystemMap (system: { From 055a7591303788b69fd0139ee429cd95c44d3cff Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 24 May 2026 20:02:04 -0500 Subject: [PATCH 2/6] `hspec-discover` --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 962d9c3..1a21a61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: - name: Configure 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 + - name: hspec-discover + run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal install hspec-discover' + - name: Build run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal build' env: From fe7a9d24742c930db00da162b03c4de9e7edc3d1 Mon Sep 17 00:00:00 2001 From: dmjio Date: Fri, 5 Jun 2026 12:31:12 -0500 Subject: [PATCH 3/6] Use flakes --- .github/workflows/ci.yml | 49 +++++++++------------------------------- flake.nix | 2 +- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a21a61..b192245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,51 +1,24 @@ -name: CI - +name: ArrayFire CI on: push: - branches: [master] + branches: + - master pull_request: - branches: [master] + +env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true jobs: build: - runs-on: macos-latest - + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 with: nix_path: nixpkgs=channel:nixpkgs-unstable - - run: nix-channel --update - - - name: Install ArrayFire - run: brew install arrayfire - - name: Set up GHC - uses: haskell-actions/setup@v2 - with: - ghc-version: '9.8.4' - cabal-version: 'latest' - - - name: Cache cabal store - uses: actions/cache@v4 - with: - path: ~/.cabal/store - key: ${{ runner.os }}-cabal-${{ hashFiles('cabal.project', '*.cabal') }} - restore-keys: | - ${{ runner.os }}-cabal- - - - name: Configure - 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 - - - name: hspec-discover - run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal install hspec-discover' - - - name: Build - run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal build' - env: - LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" + - run: nix-channel --update - - name: Nix build - run: nix build - env: - LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" + - name: Build and run tests + run: nix develop --command bash -c 'cabal test' diff --git a/flake.nix b/flake.nix index c79dea1..5fc8a05 100644 --- a/flake.nix +++ b/flake.nix @@ -84,7 +84,7 @@ cabal-install doctest hsc2hs - hspec-discover + # hspec-discover nil # Formatters nixpkgs-fmt From 0ca3f512b2cc384a8a69e03ac63ee44e5b899078 Mon Sep 17 00:00:00 2001 From: dmjio Date: Fri, 5 Jun 2026 12:47:24 -0500 Subject: [PATCH 4/6] `autoPatchelfIgnoreMissingDeps = true;` --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 5fc8a05..7a582dd 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,9 @@ hash = "sha256-8SibCWnRxts79S6WEHb3skF2TIDl1QnjY6EiohmoIog="; }; nativeBuildInputs = [ pkgs.autoPatchelfHook ]; + # GPU/visualization libs (CUDA, OpenGL, GLFW, FreeImage, Intel OpenCL) are + # optional ArrayFire backends not available in headless CI environments. + autoPatchelfIgnoreMissingDeps = true; buildInputs = with pkgs; [ stdenv.cc.cc.lib fftw From 6c7c94762959491dc8b6d3104994a9ebc9a0dc7a Mon Sep 17 00:00:00 2001 From: dmjio Date: Fri, 5 Jun 2026 12:55:38 -0500 Subject: [PATCH 5/6] `cabal update`, `cabal install hspec-discover` --- .github/workflows/ci.yml | 8 ++++++-- arrayfire.cabal | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b192245..7fc6c06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,11 @@ jobs: with: nix_path: nixpkgs=channel:nixpkgs-unstable - - run: nix-channel --update + - name: Nix channel --update + run: nix-channel --update + + - name: Cabal update + run: nix develop --command bash -c 'cabal update' - name: Build and run tests - run: nix develop --command bash -c 'cabal test' + run: nix develop --command bash -c 'cabal install hspec-discover && cabal test' diff --git a/arrayfire.cabal b/arrayfire.cabal index df41c2f..74a6c74 100644 --- a/arrayfire.cabal +++ b/arrayfire.cabal @@ -7,7 +7,7 @@ license: BSD-3-Clause license-file: LICENSE author: David Johnson maintainer: code@dmj.io -copyright: David Johnson (c) 2018-2025 +copyright: David Johnson (c) 2018-2026 category: Math build-type: Custom extra-source-files: CHANGELOG.md @@ -88,7 +88,7 @@ library c-sources: cbits/wrapper.c build-depends: - base < 5, filepath, vector + base < 5, deepseq, filepath, vector hs-source-dirs: src ghc-options: From a23996eb2cbcb3f360e1f8dec4892c99f5a48cca Mon Sep 17 00:00:00 2001 From: dmjio Date: Fri, 5 Jun 2026 13:11:36 -0500 Subject: [PATCH 6/6] `export LD_LIBRARY_PATH` for ci. --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 7a582dd..9869b69 100644 --- a/flake.nix +++ b/flake.nix @@ -93,6 +93,7 @@ nixpkgs-fmt ]; shellHook = '' + export LD_LIBRARY_PATH="${pkgs.arrayfire}/lib:$LD_LIBRARY_PATH" ''; };