forked from google-research/dex-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
); | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
description = "Dex (named for \"index\") is a research language for typed, functional array processing."; | ||
|
||
inputs = { | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
llvm-hs-src = { | ||
url = "github:llvm-hs/llvm-hs/llvm-12"; | ||
flake = false; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils, llvm-hs-src }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = (import nixpkgs { | ||
inherit system; | ||
config.allowUnfree = true; # Needed for CUDA | ||
}); | ||
in rec { | ||
packages.dex = (pkgs.callPackage ./. { | ||
inherit pkgs; | ||
inherit llvm-hs-src; | ||
}); | ||
packages.dex-cuda = (pkgs.callPackage ./. { | ||
inherit pkgs; | ||
inherit llvm-hs-src; | ||
withCudaSupport = true; | ||
}); | ||
defaultPackage = packages.dex; | ||
|
||
devShell = (import ./shell.nix { | ||
inherit pkgs; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ nixpkgs ? import <nixpkgs> {} }: | ||
with nixpkgs; | ||
stdenv.mkDerivation { | ||
{ pkgs ? import <nixpkgs> {} }: | ||
pkgs.stdenv.mkDerivation { | ||
name = "dex"; | ||
buildInputs = [ | ||
buildInputs = with pkgs; [ | ||
cabal-install | ||
cacert | ||
clang_12 | ||
git | ||
haskell.compiler.ghc884 | ||
llvm_9 | ||
clang_9 | ||
pkg-config | ||
libpng | ||
git | ||
cacert | ||
llvm_12 | ||
pkg-config | ||
stack | ||
zlib | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters