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

Build on Nixpkgs/NixOS #4405

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ab23462
Trying to enhance the experience on NixOS/Nixpkgs
jacereda Mar 30, 2018
0e0bd1a
Missing space
jacereda Mar 30, 2018
52d9600
Merge
jacereda Mar 30, 2018
44df85b
Merge branch 'build-on-nixpkgs' of https://github.com/jacereda/Idris-…
jacereda Mar 30, 2018
150e586
Enable tests
jacereda Mar 31, 2018
f723856
Merge
jacereda Apr 2, 2018
8009e2b
cabal test wasn't building the executables
jacereda Apr 2, 2018
55dc5db
Blind attempt at fixing Setup for Cabal-1
jacereda Apr 2, 2018
af91928
Apply stylish-haskell suggestion
jacereda Apr 3, 2018
5b018fe
Restore timeouts via ulimit
jacereda Apr 4, 2018
b6ed5d0
Avoid perl dependency
jacereda Apr 4, 2018
2b60976
Tests failed on windows due to ulimit -t, timeout script using node
jacereda Apr 4, 2018
6a2151b
Use another method to export IDRIS
jacereda Apr 4, 2018
f1ef4c6
Generate base nix expression with cabal2nix from Makefile
jacereda Apr 5, 2018
9db7c86
Use callCabal2nix
jacereda Apr 5, 2018
78d6af9
Warning
jacereda Apr 5, 2018
734e480
Patch node shebang
jacereda Apr 5, 2018
caccebd
Get rid of shell.nix and idris.nix
jacereda Apr 5, 2018
4c23999
Avoid duplicated CFLAGS
jacereda Apr 5, 2018
3e6e470
Don't force compiler
jacereda Apr 5, 2018
cf3d89f
Use installed idris when testing on appveyor
jacereda Apr 5, 2018
cc13c44
Merge master
jacereda Apr 5, 2018
405c415
Revert travis test
jacereda Apr 5, 2018
8d76d46
Leak warning
jacereda Apr 7, 2018
70e2514
Merge branch 'master' of https://github.com/idris-lang/Idris-dev into…
jacereda Apr 19, 2018
5e209f1
Merge master
jacereda May 3, 2018
42616f9
Merge master
jacereda May 3, 2018
93d5656
Merge
jacereda May 24, 2018
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ TAGS
.vscode
.idea

# Nix expression generated via cabal2nix
idris-generated.nix

# Nix output
result
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ script:
###
- echo 'Benchmarks...' && echo -en 'travis_fold:start:script.benchmarks\\r'
- if [[ "$TESTS" == "test_c" ]]; then
cd benchmarks && ./build.pl && ./run.pl && cd ..;
cd benchmarks && ./build && ./run && cd ..;
fi
- echo -en 'travis_fold:end:script.benchmarks\\r'
###
Expand Down
20 changes: 19 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,22 @@ encounter this then the fix is to augment the `PKG_CONFIG_PATH` for

```
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig stack build
```
```

## Experimental Support for Building on NixOS or systems with Nixpkgs

To run the full build process:

nix-build

The resulting build should be on the `result` directory.

If you wish to install it to your environment:

nix-env -f default.nix -i idris

For local development with Cabal:

nix-shell
cabal configure --enable-tests -fFFI -fGMP
cabal test
40 changes: 31 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_js test_c stylize test test_clean lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs
.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_js test_c stylize test test_clean lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs rts rts_clean

ARGS=
TEST-JOBS=
Expand All @@ -7,6 +7,8 @@ TEST-ARGS=
include config.mk
-include custom.mk

IDRIS ?= $(CURDIR)/dist/build/idris/idris

ifdef CI
CABALFLAGS += -f CI
ifndef APPVEYOR
Expand All @@ -22,7 +24,10 @@ pinstall: dist/setup-config
$(CABAL) install $(CABALFLAGS)

build: dist/setup-config
$(CABAL) build $(CABALFLAGS)
$(CABAL) build

$(IDRIS): dist/setup-config
$(CABAL) build "exe:idris"

test: doc test_c stylize

Expand All @@ -45,8 +50,29 @@ test_clean:
rm -f test/*~
rm -f test/*/output

rts:
$(MAKE) -C rts

rts_install:
$(MAKE) -C rts install

rts_clean:
$(MAKE) -C rts clean

lib:
$(MAKE) -C libs

lib_install:
$(MAKE) -C libs install

lib_clean:
$(MAKE) -C libs IDRIS=../../dist/build/idris/idris RTS=../../dist/build/rts/libidris_rts clean
$(MAKE) -C libs clean

lib_doc:
$(MAKE) -C libs doc

lib_doc_clean:
$(MAKE) -C libs doc_clean

relib: lib_clean
$(CABAL) install $(CABALFLAGS)
Expand All @@ -58,12 +84,6 @@ linecount:
doc: dist/setup-config
$(CABAL) haddock --hyperlink-source --html --hoogle --html-location="http://hackage.haskell.org/packages/archive/\$$pkg/latest/doc/html" --haddock-options="--title Idris"

lib_doc:
$(MAKE) -C libs IDRIS=../../dist/build/idris/idris doc

lib_doc_clean:
$(MAKE) -C libs IDRIS=../../dist/build/idris/idris doc_clean

user_docs: user_doc_html user_doc_pdf

user_doc_clean:
Expand All @@ -80,3 +100,5 @@ fast:

dist/setup-config:
$(CABAL) configure $(CABALFLAGS)

.EXPORT_ALL_VARIABLES:
114 changes: 60 additions & 54 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import Control.Monad
import Data.IORef
import Data.Maybe (fromMaybe)
import Data.List (nub, isInfixOf)
import Control.Exception (SomeException, catch)

import Distribution.Simple
Expand Down Expand Up @@ -36,14 +38,11 @@ import Distribution.Types.UnqualComponentName

-- -----------------------------------------------------------------------------
-- Idris Command Path
idrisCmd local = Px.joinPath $ splitDirectories $ ".." </> ".." </> buildDir local </> "idris" </> "idris"


shinvoke verbosity cmd = P.runProgramInvocation verbosity . P.simpleProgramInvocation cmd

-- make on mingw32 exepects unix style separators
#ifdef mingw32_HOST_OS
(<//>) = (Px.</>)
idrisCmd local = Px.joinPath $ splitDirectories $ ".." <//> ".." <//> buildDir local <//> "idris" <//> "idris"
#else
idrisCmd local = ".." </> ".." </> buildDir local </> "idris" </> "idris"
#endif

-- -----------------------------------------------------------------------------
-- Make Commands
Expand All @@ -55,63 +54,55 @@ mymake = "gmake"
#else
mymake = "make"
#endif
make verbosity =
P.runProgramInvocation verbosity . P.simpleProgramInvocation mymake
make verbosity = shinvoke verbosity mymake

#ifdef mingw32_HOST_OS
windres verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "windres"
#endif
-- -----------------------------------------------------------------------------
-- Flags

usesGMP :: S.ConfigFlags -> Bool
usesGMP flags =
case lookupFlagAssignment (mkFlagName "gmp") (S.configConfigurationsFlags flags) of

flag nm flags = case lookupFlagAssignment (mkFlagName nm) (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False


usesGMP :: S.ConfigFlags -> Bool
usesGMP = flag "gmp"

execOnly :: S.ConfigFlags -> Bool
execOnly flags =
case lookupFlagAssignment (mkFlagName "execonly") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False
execOnly = flag "execonly"

isRelease :: S.ConfigFlags -> Bool
isRelease flags =
case lookupFlagAssignment (mkFlagName "release") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False
isRelease = flag "release"

isFreestanding :: S.ConfigFlags -> Bool
isFreestanding flags =
case lookupFlagAssignment (mkFlagName "freestanding") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False
isFreestanding = flag "freestanding"

#if !(MIN_VERSION_Cabal(2,0,0))
mkFlagName :: String -> FlagName
mkFlagName = FlagName

unUnqualComponentName = id
#endif

#if !(MIN_VERSION_Cabal(2,2,0))
lookupFlagAssignment :: FlagName -> FlagAssignment -> Maybe Bool
lookupFlagAssignment = lookup
#endif


-- -----------------------------------------------------------------------------
-- Clean

idrisClean _ flags _ _ = cleanStdLib
idrisClean _ flags _ _ = cleanStdLib >> cleanRts
where
verbosity = S.fromFlag $ S.cleanVerbosity flags

cleanStdLib = makeClean "libs"

makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]
cleanStdLib = make verbosity ["lib_clean"]
cleanRts = make verbosity ["rts_clean"]

-- -----------------------------------------------------------------------------
-- Configure
Expand Down Expand Up @@ -183,12 +174,16 @@ generateToolchainModule verbosity srcDir toolDir = do
createDirectoryIfMissingVerbose verbosity True srcDir
rewriteFileEx verbosity toolPath (commonContent ++ toolContent)

idrisConfigure _ flags pkgdesc local = do
idrisPostConf _ flags pkgdesc local = do
nixLDFLAGS <- lookupEnv "NIX_LDFLAGS"
configureRTS
withLibLBI pkgdesc local $ \lib libcfg -> do
let libAutogenDir = autogenComponentModulesDir local libcfg
let libDirs = extraLibDirs $ libBuildInfo lib
generateBuildFlagsModule verbosity libAutogenDir libDirs
let nixLibDirs = map (drop 2)
$ filter ("-gmp-" `Data.List.isInfixOf`)
$ words $ fromMaybe "" nixLDFLAGS
generateBuildFlagsModule verbosity libAutogenDir (nub $ libDirs ++ nixLibDirs)
generateVersionModule verbosity libAutogenDir (isRelease (configFlags local))
if isFreestanding $ configFlags local
then do
Expand All @@ -209,7 +204,7 @@ idrisConfigure _ flags pkgdesc local = do
-- installing but shouldn't be in the distribution. And it won't make the
-- distribution if it's not there, so instead I just delete
-- the file after configure.
configureRTS = make verbosity ["-C", "rts", "clean"]
configureRTS = make verbosity ["rts_clean"]

#if !(MIN_VERSION_Cabal(2,0,0))
autogenComponentModulesDir lbi _ = autogenModulesDir lbi
Expand Down Expand Up @@ -273,27 +268,34 @@ idrisPreBuild args flags = do
verbosity = S.fromFlag $ S.buildVerbosity flags
dir = S.fromFlagOrDefault "dist" $ S.buildDistPref flags
#else
return (Nothing, [])
preBuild simpleUserHooks args flags
#endif

idrisBuild _ flags _ local
idrisBuildHook pd lbi hooks flags = do
let exe = ("exe:" ++) . unUnqualComponentName . exeName
exes = map exe (executables pd)
nflags = case S.buildArgs flags of
orig@["regression-and-feature-tests"] ->
flags { S.buildArgs = exes ++ orig }
_ -> flags
buildHook simpleUserHooks pd lbi hooks nflags


idrisPostBuild _ flags _ local
= if (execOnly (configFlags local)) then buildRTS
else do buildStdLib
buildRTS
where
verbosity = S.fromFlag $ S.buildVerbosity flags

buildStdLib = do
putStrLn "Building libraries..."
makeBuild "libs"
where
makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]

buildRTS = make verbosity (["-C", "rts", "build"] ++
gmpflag (usesGMP (configFlags local)))

putStrLn "Building libraries..."
make verbosity [ "-j8", "lib", "IDRIS=" ++ idrisCmd local]
buildRTS = do
putStrLn "Building runtime..."
make verbosity $ ["rts"] ++ gmp
gmpflag False = []
gmpflag True = ["GMP=-DIDRIS_GMP"]
gmp = gmpflag (usesGMP (configFlags local))

-- -----------------------------------------------------------------------------
-- Copy/Install
Expand All @@ -307,22 +309,22 @@ idrisInstall verbosity copy pkg local
target = datadir $ L.absoluteInstallDirs pkg local copy

installStdLib = do
let target' = target -- </> "libs"
putStrLn $ "Installing libraries in " ++ target'
makeInstall "libs" target'
let target' = target -- </> "libs"
putStrLn $ "Installing libraries in " ++ target'
make' "lib_install" target'

installRTS = do
let target' = target </> "rts"
putStrLn $ "Installing run time system in " ++ target'
makeInstall "rts" target'
make' "rts_install" target'

installManPage = do
let mandest = mandir (L.absoluteInstallDirs pkg local copy) ++ "/man1"
notice verbosity $ unwords ["Copying man page to", mandest]
installOrdinaryFiles verbosity mandest [("man", "idris.1")]

makeInstall src target =
make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
make' x target =
make verbosity [ x, "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]

-- -----------------------------------------------------------------------------
-- Test
Expand All @@ -335,7 +337,10 @@ fixPkg pkg target = pkg { dataDir = target }

idrisTestHook args pkg local hooks flags = do
let target = datadir $ L.absoluteInstallDirs pkg local NoCopyDest
testHook simpleUserHooks args (fixPkg pkg target) local hooks flags
idris <- canonicalizePath (buildDir local </> "idris" </> "idris")
setEnv "IDRIS" idris
-- testHook simpleUserHooks args (fixPkg pkg target) local hooks flags
testHook simpleUserHooks args pkg local hooks flags

-- -----------------------------------------------------------------------------
-- Main
Expand All @@ -344,9 +349,10 @@ idrisTestHook args pkg local hooks flags = do
-- See https://github.com/haskell/cabal/issues/709
main = defaultMainWithHooks $ simpleUserHooks
{ postClean = idrisClean
, postConf = idrisConfigure
, postConf = idrisPostConf
, preBuild = idrisPreBuild
, postBuild = idrisBuild
, buildHook = idrisBuildHook
, postBuild = idrisPostBuild
, postCopy = \_ flags pkg local ->
idrisInstall (S.fromFlag $ S.copyVerbosity flags)
(S.fromFlag $ S.copyDest flags) pkg local
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Benchmarks

To run:

$ ./build.pl -- builds all benchmark binaries
$ ./run.pl -- runs all benchmarks
$ ./build -- builds all benchmark binaries
$ ./run -- runs all benchmarks

Adding a test
Adding a test
-------------

Add a line to the 'ALL' file of the following form:
Expand All @@ -15,7 +15,7 @@ dir/main arg

where 'dir' is the directory the benchmark lives in, 'main' is the name of the
ipkg file and executable (these must be the same), 'arg' is the input to give
to the binary.
to the binary.

It is assumed that all benchmarks take exactly one argument, which helps to
ensure that they are not simply doing all the work at compile time.
15 changes: 15 additions & 0 deletions benchmarks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eu

build() {
while read dir nm arg; do
idr=${IDRIS:-idris}
pkg=$nm.ipkg
cd $dir
$idr --clean $pkg
$idr --build $pkg
cd ..
done
}

sed 's-/- -g' ALL | build
Loading