Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nix setup #56

Merged
merged 20 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ cabal.sandbox.config
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
output/
*.ibc
*.agdai
.output
.grin-output/
grin/.end-to-end-test/
.vscode/
*.out
*.out.ll
*.out.s
.ghc.environment.*
13 changes: 13 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
haskell = import ./nix/haskell.nix;
llvm-overlay = self: super: {
llvm-config = self.llvm_7;
};
extra-overlays = [ llvm-overlay ];
pkgs = import ./nix/packages.nix (haskell // {
overlays = haskell.overlays ++ extra-overlays;
});
in
pkgs.haskell-nix.stackProject {
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
}
2 changes: 1 addition & 1 deletion grin/app/CLI/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import System.IO

import Grin.Grin
import Grin.PrimOpsPrelude
import Grin.Parse hiding (value)
import Grin.Parse
import Grin.Nametable as Nametable
import Pipeline.Pipeline

Expand Down
41 changes: 0 additions & 41 deletions grin/default.nix

This file was deleted.

15 changes: 10 additions & 5 deletions grin/src/Pipeline/Pipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import qualified AbstractInterpretation.EffectTracking.CodeGenBase as ET
import qualified AbstractInterpretation.Sharing.CodeGen as Sharing
import qualified Reducer.LLVM.CodeGen as CGLLVM
import qualified Reducer.LLVM.JIT as JITLLVM
import System.Environment ( lookupEnv )
import System.Directory
import qualified System.Process
import Data.Bifunctor
Expand Down Expand Up @@ -718,23 +719,27 @@ saveLLVM path = do
pipelineLog "* to LLVM *"
void $ liftIO $ CGLLVM.toLLVM llName code
pipelineLog"* LLVM X64 codegen *"
callCommand $ printf "opt-7 -O3 %s | llc-7 -o %s" llName (sName :: String)
llcExe <- liftIO $ fromMaybe "llc-7" <$> lookupEnv "GRIN_LLC"
optExe <- liftIO $ fromMaybe "opt-7" <$> lookupEnv "GRIN_OPT"
callCommand $ printf "%s -O3 %s | %s -o %s" optExe llName llcExe (sName :: String)

saveExecutable :: Bool -> Path -> PipelineM ()
saveExecutable debugSymbols path = do
pipelineLog "* generate llvm x64 optcode *"
let grinOptCodePath = Rel "grin-opt-code"
clangExe <- liftIO $ fromMaybe "clang-7" <$> lookupEnv "GRIN_CC"
llcExe <- liftIO $ fromMaybe "llc-7" <$> lookupEnv "GRIN_LLC"
pipelineStep $ SaveLLVM grinOptCodePath
grinOptCodeFile <- relPath grinOptCodePath
fname <- relPath path
pipelineLog "* generate executable *"
callCommand $ printf
("llc-7 -O3 -relocation-model=pic -filetype=obj %s.ll" ++ if debugSymbols then " -debugger-tune=gdb" else "")
grinOptCodeFile
("%s -O3 -relocation-model=pic -filetype=obj %s.ll" ++ if debugSymbols then " -debugger-tune=gdb" else "")
llcExe grinOptCodeFile
cfg <- ask
callCommand $ printf
("clang-7 -O3 %s %s.o -s -o %s" ++ if debugSymbols then " -g" else "")
(intercalate " " $ _poCFiles cfg) grinOptCodeFile fname
("%s -O3 %s %s.o -s -o %s" ++ if debugSymbols then " -g" else "")
clangExe (intercalate " " $ _poCFiles cfg) grinOptCodeFile fname

debugTransformation :: (Exp -> Exp) -> PipelineM ()
debugTransformation t = do
Expand Down
20 changes: 0 additions & 20 deletions nix/free.nix

This file was deleted.

7 changes: 7 additions & 0 deletions nix/haskell-nix-src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"url": "https://github.com/input-output-hk/haskell.nix",
"rev": "ebdc0030e6973629c1ed7dba53c1b1d154c3e75e",
"date": "2019-12-11T01:12:46+00:00",
"sha256": "1q25sw8kz7r0wwzq780qq1cgsiy1g7iwnywckixa28psim8rp2nw",
"fetchSubmodules": false
}
8 changes: 8 additions & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
spec = builtins.fromJSON (builtins.readFile ./haskell-nix-src.json);
haskell-nix-src = builtins.fetchGit {
name = "haskell-lib";
inherit (spec) url rev;
};
in
import haskell-nix-src
20 changes: 0 additions & 20 deletions nix/llvm-hs-pretty.nix

This file was deleted.

20 changes: 0 additions & 20 deletions nix/llvm-hs-pure.nix

This file was deleted.

26 changes: 0 additions & 26 deletions nix/llvm-hs.nix

This file was deleted.

10 changes: 10 additions & 0 deletions nix/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let
commit = "4c6e9a553872366e485766fa8b574b54b15957f8";
nixpkgs = builtins.fetchTarball {
name = "nixpkgs-19.09";
url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz";
sha256 = "1az9yg2lwwfw3aypi6bdsk7ghld2963vqdp8ajkxciyxdfkaxb3b";
};
pkgs = import nixpkgs;
in
pkgs
84 changes: 12 additions & 72 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,74 +1,14 @@
{ fetchFromGitHub ? (import <nixpkgs> {}).fetchFromGitHub
# peg nix packages to specific version
, pkgs ?
import
( fetchFromGitHub
{
owner = "NixOS";
repo = "nixpkgs-channels";
rev = "696c6bed4e8e2d9fd9b956dea7e5d49531e9d13f";
sha256 = "1v3yrpj542niyxp0h3kffsdjwlrkvj0mg4ljb85d142gyn3sdzd4";
}
) {}
}:
let
# extract the Haskell dependencies of a package
extractHaskellDependencies = (hpkg:
with builtins;
let
isHaskellPkg = x: (isAttrs x) && (x ? pname) && (x ? version) && (x ? env);
packagesFromDrv = x:
let
inputs =
(x.buildInputs or []) ++
(x.nativeBuildInputs or []) ++
(x.propagatedBuildInputs or []) ++
(x.propagatedNativeBuildInputs or []);

in
(filter isHaskellPkg inputs);
go1 = s: xs: foldl' go2 s xs;
go2 = s: x:
if s ? "${x.pname}"
then s
else go1 (s // {"${x.pname}" = x;}) (packagesFromDrv x);
in assert isAttrs hpkg; attrNames (go1 {} (packagesFromDrv hpkg)));

# Haskell custom overrides
haskellPackages = pkgs.haskell.packages.ghc822.override (old:
{ overrides = self: super:
{
free = self.callPackage ./nix/free.nix {};
functor-infix = pkgs.haskell.lib.doJailbreak (super.functor-infix);
llvm-hs = self.callPackage ./nix/llvm-hs.nix {llvm-config = pkgs.llvm_5;};
llvm-hs-pure = self.callPackage ./nix/llvm-hs-pure.nix {};
llvm-hs-pretty = pkgs.haskell.lib.dontCheck (self.callPackage ./nix/llvm-hs-pretty.nix {});
};
});

# the grin package
grin = pkgs.haskellPackages.callPackage ./grin {};
# grin's dependencies
grinDeps = extractHaskellDependencies grin;
# use a GHC with all the Hakell dependencies and the documentation for them and a Hoogle server to search them
ghcWith = haskellPackages.ghcWithHoogle (hs: map (x: builtins.getAttr x hs) grinDeps);

llc5 = pkgs.runCommand "llc5"
{
buildInputs = [pkgs.llvm_5];
}
''
mkdir -p $out/bin
cd $out/bin
ln -s ${pkgs.llvm_5}/bin/llc llc-5.0
'';
pkgs = import ./nix/packages.nix {};
haskellPkgs = import ./.;
in
# environment setup with all the needed tools
pkgs.runCommand "grin-shell"
{
shellHook = ''
eval $(egrep ^export ${ghcWith}/bin/ghc)
'';
buildInputs = [ghcWith llc5 pkgs.llvm_5 haskellPackages.cabal-install];
}
"touch $out"
haskellPkgs.shellFor {
buildInputs = with pkgs.haskellPackages; [
hlint
ghcid
];

GRIN_CC = "${pkgs.clang_7}/bin/clang";
GRIN_OPT = "${pkgs.llvm_7}/bin/opt";
GRIN_LLC = "${pkgs.llvm_7}/bin/llc";
}