-
Notifications
You must be signed in to change notification settings - Fork 108
/
default.nix
72 lines (71 loc) · 2.14 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ pkgs ? import <nixpkgs> {},
llvm-hs-src ? pkgs.fetchFromGitHub {
owner = "llvm-hs";
repo = "llvm-hs";
rev = "llvm-12";
sha256 = "IG4Mh89bY+PtBJtzlXKYsPljfHP7OSQk03pV6fSmdRY=";
},
cudaPackage ? pkgs.cudaPackages.cudatoolkit_11,
cuda ? false,
optimized ? true,
live ? true,
}:
let
llvm-hs-pure = pkgs.haskellPackages.callCabal2nix "llvm-hs-pure" "${llvm-hs-src}/llvm-hs-pure" {
};
llvm-hs = (pkgs.haskellPackages.callCabal2nix "llvm-hs" "${llvm-hs-src}/llvm-hs" {
inherit llvm-hs-pure;
}).overrideAttrs (oldAttrs: rec {
buildInputs = oldAttrs.buildInputs ++ [
pkgs.llvm_12
];
});
buildFlags = pkgs.lib.optionals optimized [
"-foptimized"
] ++ pkgs.lib.optionals live [
"-flive"
] ++ pkgs.lib.optionals cuda [
"-fcuda"
"--extra-include-dirs=${cudaPackage}/include"
"--extra-lib-dirs=${cudaPackage}/lib64/stubs"
];
cxxFlags = [
"-fPIC"
"-std=c++11"
"-fno-exceptions"
"-fno-rtti"
] ++ pkgs.lib.optional cuda "-DDEX_CUDA"
++ pkgs.lib.optional live "-DDEX_LIVE";
buildRuntimeCommand = ''
${pkgs.clang_9}/bin/clang++ \
${builtins.concatStringsSep " " cxxFlags} \
-c \
-emit-llvm \
-I${pkgs.libpng}/include \
src/lib/dexrt.cpp \
-o src/lib/dexrt.bc
'';
in
# `callCabal2nix` converts `dex.cabal` into a Nix file and builds it.
# Before we do the Haskell build though, we need to first compile the Dex runtime
# so it's properly linked in when compiling Dex. Normally the makefile does this,
# so we instead sneak compiling the runtime in the configuration phase for the Haskell build.
(pkgs.haskellPackages.callCabal2nix "dex" ./. {
inherit llvm-hs;
inherit llvm-hs-pure;
}).overrideAttrs (attrs: {
configurePhase = ''
# Compile the Dex runtime
echo 'Compiling the Dex runtime...'
set -x
${buildRuntimeCommand}
set +x
echo 'Done compiling the Dex runtime.'
# Run the Haskell configuration phase
${attrs.configurePhase}
'';
configureFlags = builtins.concatStringsSep " " buildFlags;
buildInputs = attrs.buildInputs ++ (pkgs.lib.optional cuda
cudaPackage
);
})