2018-08-06 21:00:58 +03:00
#!/usr/bin/env bash
2018-05-14 00:25:41 +03:00
2020-06-23 18:47:43 +03:00
# NOTE: Script for the CI builds, relies on `default.nix` interface, which exposes Nixpkgs Haskell Lib interface
2020-05-27 17:42:58 +03:00
2020-06-23 19:41:38 +03:00
# The most strict error checking requirements
2020-05-31 19:34:39 +03:00
set -Eexuo pipefail
2020-06-23 18:49:29 +03:00
### NOTE: Section handles imports from env, these are settings for Nixpkgs.
2020-06-24 03:05:05 +03:00
# Settings expose most of the Nixpkgs Haskell.lib API: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib.nix
2020-06-23 19:41:38 +03:00
# Some of these options implicitly switch the dependent options.
2020-06-23 18:49:29 +03:00
2020-06-24 03:05:05 +03:00
# NOTE: If vars not imported - set to the default value
2020-06-23 21:06:02 +03:00
compiler = ${ compiler :- 'ghc8101' }
2020-06-23 18:43:47 +03:00
# NOTE: Nix by default uses nixpkgs-unstable channel
# Setup for Nixpkgs revision:
# `rev` vals in order of freshness -> cache & stability:
# { master
# , commitHash
# , haskell-updates # Haskell development branch in Nixpkgs, can be inconsistent. Weekly merged into the upstream
# , nixpkgs-unstable # Default branch on Nix installation, default for non NixOS
# , nixos-unstable # nixpkgs-unstable that passes a bunch of base tests
# , nixos-20.03 # Last stable release, gets almost no updates to recipes, gets only required backports
# ...
# }
2020-05-31 19:34:39 +03:00
rev = ${ rev :- 'nixpkgs-unstable' }
2020-06-23 18:53:37 +03:00
# If NIX_PATH not imported - construct it from `rev`
2020-05-31 19:34:39 +03:00
NIX_PATH = ${ NIX_PATH :- " nixpkgs=https://github.com/nixos/nixpkgs/archive/ $rev .tar.gz " }
export NIX_PATH
2020-06-23 19:41:38 +03:00
# NOTE: Project name, used by cachix
2020-06-23 19:09:01 +03:00
project = ${ project :- 'defaultProjectName' }
2020-06-17 15:51:28 +03:00
2020-06-17 15:51:48 +03:00
2020-06-17 15:51:28 +03:00
# Don't fail at configure time if there are multiple versions of the same package in the (recursive) dependencies of the package being built. Will delay failures, if any, to compile time.
2020-06-17 15:48:13 +03:00
allowInconsistentDependencies = ${ allowInconsistentDependencies :- 'false' }
2020-06-17 15:51:28 +03:00
# Escape the version bounds from the cabal file. You may want to avoid this function.
2020-05-31 19:34:39 +03:00
doJailbreak = ${ doJailbreak :- 'false' }
2020-06-17 15:51:28 +03:00
# Nix dependency checking, compilation and execution of test suites listed in the package description file.
2020-05-31 19:34:39 +03:00
doCheck = ${ doCheck :- 'true' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:54:38 +03:00
# Just produce a SDist src tarball
sdistTarball = ${ sdistTarball :- 'false' }
2020-06-17 15:51:28 +03:00
# Produce SDist tarball and build project from it
2020-06-23 19:41:38 +03:00
# The strict packaging process as used on Hackage. Tests consistency of the Cabal file.
2020-05-31 19:34:39 +03:00
buildFromSdist = ${ buildFromSdist :- 'false' }
2020-06-24 03:05:05 +03:00
2020-06-23 19:41:38 +03:00
# Turn all warn into err with {-Wall,-Werror}
2020-06-17 15:48:13 +03:00
failOnAllWarnings = ${ failOnAllWarnings :- 'false' }
2020-06-17 15:51:28 +03:00
# `failOnAllWarnings` + `buildFromSdist`
2020-05-31 19:34:39 +03:00
buildStrictly = ${ buildStrictly :- 'false' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:54:38 +03:00
# 2020-06-02: NOTE: enableDeadCodeElimination = true: On GHC =< 8.8.3 macOS build falls due to https://gitlab.haskell.org/ghc/ghc/issues/17283
enableDeadCodeElimination = ${ enableDeadCodeElimination :- 'false' }
2020-06-23 19:41:38 +03:00
# Disabled GHC code optimizations make build/tolling/dev loops faster. Works for Haskel IDE Engine and GHCID
# Enable optimizations for production use, and to pass benchmarks.
2020-05-31 19:34:39 +03:00
disableOptimization = ${ disableOptimization :- 'true' }
2020-06-17 15:54:38 +03:00
# Use faster `gold` ELF linker from GNU binutils instead of older&slower but more versatile GNU linker. Is not available by default since macOS does not have it.
linkWithGold = ${ linkWithGold :- 'false' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:51:28 +03:00
# Provide an inventory of performance events and timings for the execution. Provides informaiton in an absolute sense. Nothing is timestamped.
2020-06-17 15:48:13 +03:00
enableLibraryProfiling = ${ enableLibraryProfiling :- 'false' }
enableExecutableProfiling = ${ enableExecutableProfiling :- 'false' }
2020-06-17 15:54:38 +03:00
# Include tracing information & abilities. Tracing records the chronology, often with timestamps and is extensive in time
doTracing = ${ doTracing :- 'false' }
# Include DWARF debugging information & abilities
enableDWARFDebugging = ${ enableDWARFDebugging :- 'false' }
# Strip results from all debugging symbols
doStrip = ${ doStrip :- 'false' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:54:38 +03:00
# Nixpkgs expects shared libraries
enableSharedLibraries = ${ enableSharedLibraries :- 'true' }
# Ability to make static libraries
enableStaticLibraries = ${ enableStaticLibraries :- 'false' }
# Make hybrid executable that is also a shared library
enableSharedExecutables = ${ enableSharedExecutables :- 'false' }
# link executables statically against haskell libs to reduce closure size
justStaticExecutables = ${ justStaticExecutables :- 'false' }
enableSeparateBinOutput = ${ enableSeparateBinOutput :- 'false' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:51:28 +03:00
# Add a post-build check to verify that dependencies declared in the .cabal file are actually used.
2020-06-23 19:41:38 +03:00
# checkUnusedPackages: is `failOnAllWarnings` + `cabal sdist` to ensure all needed files are listed in the Cabal file. Currently uses `packunused` or GHC 8.8 internals, later switches into GHC internal feature. Adds a post-build check to verify that dependencies declared in the cabal file are actually used.
2020-06-17 15:48:13 +03:00
checkUnusedPackages = ${ checkUnusedPackages :- 'false' }
2020-06-17 15:51:28 +03:00
# Generation and installation of haddock API documentation
2020-06-17 15:48:13 +03:00
doHaddock = ${ doHaddock :- 'false' }
2020-06-23 20:31:39 +03:00
# Generate hyperlinked source code for documentation using HsColour, and have Haddock documentation link to it.
doHyperlinkSource = ${ doHyperlinkSource :- 'false' }
2020-06-17 15:51:28 +03:00
# Generation and installation of a coverage report. See https://wiki.haskell.org/Haskell_program_coverage
2020-06-17 15:48:13 +03:00
doCoverage = ${ doCoverage :- 'false' }
2020-06-17 15:51:28 +03:00
# doBenchmark: Dependency checking + compilation and execution for benchmarks listed in the package description file.
2020-06-17 15:48:13 +03:00
doBenchmark = ${ doBenchmark :- 'false' }
2020-06-23 19:41:38 +03:00
# For binaries named in `executableNamesToShellComplete` list, generate and bundle-into package an automatically loaded shell complettions
2020-05-31 19:34:39 +03:00
generateOptparseApplicativeCompletions = ${ generateOptparseApplicativeCompletions :- 'false' }
2020-06-23 19:41:38 +03:00
# [ "binary1" "binary2" ] - should pass " quotes into Nix interpreter
2020-06-17 19:40:21 +03:00
executableNamesToShellComplete = ${ executableNamesToShellComplete :- '[ "defaultBinaryName" ]' }
2020-06-24 03:05:05 +03:00
2020-06-17 15:54:38 +03:00
# Include Hoogle into derivation
withHoogle = ${ withHoogle :- 'false' }
2020-06-23 19:41:38 +03:00
# Log file to dump GHCJS build into
2020-05-31 19:34:39 +03:00
ghcjsTmpLogFile = ${ ghcjsTmpLogFile :- '/tmp/ghcjsTmpLogFile.log' }
2020-06-23 19:41:38 +03:00
# Length of the GHCJS log tail (<40000)
2020-05-31 19:34:39 +03:00
ghcjsLogTailLength = ${ ghcjsLogTailLength :- '10000' }
2020-06-23 19:41:38 +03:00
# If key not provided (branch is not inside the central repo) - init CACHIX_SIGNING_KEY as empty
2020-05-31 22:30:24 +03:00
CACHIX_SIGNING_KEY = ${ CACHIX_SIGNING_KEY :- "" }
2020-05-31 19:34:39 +03:00
2020-05-27 17:50:11 +03:00
GHCJS_BUILD( ) {
# NOTE: Function for GHCJS build that outputs its huge log into a file
# NOTE: Run the build into Log (log is too long for Travis)
" $@ " & > " $ghcjsTmpLogFile "
}
2020-05-27 17:50:33 +03:00
SILENT( ) {
2020-05-28 17:42:01 +03:00
# NOTE: Function that silences the build process
2020-05-27 17:50:33 +03:00
# In normal mode outputs only the /nix/store paths
echo " Log: $ghcjsTmpLogFile "
# NOTE: Pass into the ghcjsbuild function the build command
if GHCJS_BUILD " $@ "
then
# NOTE: Output log lines for stdout -> cachix caching
grep '^/nix/store/' " $ghcjsTmpLogFile "
else
# NOTE: Output log lines for stdout -> cachix caching
grep '^/nix/store/' " $ghcjsTmpLogFile "
# NOTE: Propagate the error state, fail the CI build
exit 1
fi
}
2020-05-28 00:57:48 +03:00
BUILD_PROJECT( ) {
2020-05-27 17:44:49 +03:00
2020-05-27 20:13:32 +03:00
2020-05-31 19:34:39 +03:00
IFS = $'\n\t'
2020-05-27 20:13:32 +03:00
2020-06-23 21:06:02 +03:00
if [ " $compiler " = "ghcjs" ]
2020-05-28 01:01:12 +03:00
then
2020-05-28 17:45:29 +03:00
# NOTE: GHCJS build
# By itself, GHCJS creates >65000 lines of log that are >4MB in size, so Travis terminates due to log size quota.
2020-05-28 01:01:12 +03:00
# nixbuild --quiet (x5) does not work on GHC JS build
# So there was a need to make it build.
2020-05-28 17:45:29 +03:00
# The solution is to silence the stdout
2020-05-28 01:01:12 +03:00
# But Travis then terminates on 10 min no stdout timeout
# so HACK: SILENT wrapper allows to surpress the huge log, while still preserves the Cachix caching ability in any case of the build
# On build failure outputs the last 10000 lines of log (that should be more then enough), and terminates
2020-06-17 19:42:24 +03:00
SILENT nix-build \
--arg allowInconsistentDependencies " $allowInconsistentDependencies " \
2020-05-28 01:01:12 +03:00
--arg doJailbreak " $doJailbreak " \
--arg doCheck " $doCheck " \
2020-06-17 19:42:24 +03:00
--arg sdistTarball " $sdistTarball " \
2020-05-28 01:01:12 +03:00
--arg buildFromSdist " $buildFromSdist " \
2020-06-17 19:42:24 +03:00
--arg failOnAllWarnings " $failOnAllWarnings " \
2020-05-28 01:01:12 +03:00
--arg buildStrictly " $buildStrictly " \
2020-06-17 19:42:24 +03:00
--arg enableDeadCodeElimination " $enableDeadCodeElimination " \
2020-05-28 01:01:12 +03:00
--arg disableOptimization " $disableOptimization " \
2020-06-17 19:42:24 +03:00
--arg linkWithGold " $linkWithGold " \
--arg enableLibraryProfiling " $enableLibraryProfiling " \
--arg enableExecutableProfiling " $enableExecutableProfiling " \
--arg doTracing " $doTracing " \
--arg enableDWARFDebugging " $enableDWARFDebugging " \
--arg doStrip " $doStrip " \
--arg doHyperlinkSource " $doHyperlinkSource " \
--arg enableSharedLibraries " $enableSharedLibraries " \
--arg enableStaticLibraries " $enableStaticLibraries " \
--arg enableSharedExecutables " $enableSharedExecutables " \
--arg justStaticExecutables " $justStaticExecutables " \
--arg checkUnusedPackages " $checkUnusedPackages " \
--arg doCoverage " $doCoverage " \
--arg doHaddock " $doHaddock " \
--arg doBenchmark " $doBenchmark " \
2020-06-17 19:40:21 +03:00
--arg generateOptparseApplicativeCompletions " $generateOptparseApplicativeCompletions " \
--arg executableNamesToShellComplete " $executableNamesToShellComplete " \
2020-06-17 19:42:24 +03:00
--arg withHoogle " $withHoogle " \
2020-06-23 21:06:02 +03:00
" $compiler "
2020-05-28 01:01:12 +03:00
2020-05-28 01:00:14 +03:00
else
# NOTE: Normal GHC build
# NOTE: GHC sometimes produces logs so big - that Travis terminates builds, so multiple --quiet
2020-06-17 19:42:24 +03:00
nix-build \
--quiet --quiet \
2020-06-23 21:06:02 +03:00
--argstr compiler " $compiler " \
2020-06-17 19:42:24 +03:00
--arg allowInconsistentDependencies " $allowInconsistentDependencies " \
2020-05-28 01:00:14 +03:00
--arg doJailbreak " $doJailbreak " \
--arg doCheck " $doCheck " \
2020-06-17 19:42:24 +03:00
--arg sdistTarball " $sdistTarball " \
2020-05-28 01:00:14 +03:00
--arg buildFromSdist " $buildFromSdist " \
2020-06-17 19:42:24 +03:00
--arg failOnAllWarnings " $failOnAllWarnings " \
2020-05-28 01:00:14 +03:00
--arg buildStrictly " $buildStrictly " \
2020-06-17 19:42:24 +03:00
--arg enableDeadCodeElimination " $enableDeadCodeElimination " \
2020-05-28 01:00:14 +03:00
--arg disableOptimization " $disableOptimization " \
2020-06-17 19:42:24 +03:00
--arg linkWithGold " $linkWithGold " \
--arg enableLibraryProfiling " $enableLibraryProfiling " \
--arg enableExecutableProfiling " $enableExecutableProfiling " \
--arg doTracing " $doTracing " \
--arg enableDWARFDebugging " $enableDWARFDebugging " \
--arg doStrip " $doStrip " \
--arg doHyperlinkSource " $doHyperlinkSource " \
--arg enableSharedLibraries " $enableSharedLibraries " \
--arg enableStaticLibraries " $enableStaticLibraries " \
--arg enableSharedExecutables " $enableSharedExecutables " \
--arg justStaticExecutables " $justStaticExecutables " \
--arg checkUnusedPackages " $checkUnusedPackages " \
--arg doCoverage " $doCoverage " \
--arg doHaddock " $doHaddock " \
--arg doBenchmark " $doBenchmark " \
2020-06-17 19:40:21 +03:00
--arg generateOptparseApplicativeCompletions " $generateOptparseApplicativeCompletions " \
2020-06-17 19:42:24 +03:00
--arg executableNamesToShellComplete " $executableNamesToShellComplete " \
--arg withHoogle " $withHoogle "
2020-05-28 01:00:14 +03:00
fi
2020-05-28 00:57:48 +03:00
}
2020-05-28 00:57:13 +03:00
MAIN( ) {
2020-06-01 18:43:26 +03:00
# NOTE: Overall it is useful to have in CI test builds the latest stable Nix
2020-06-24 01:53:16 +03:00
# NOTE: User-run Linux setup old update command, or superuser update for macOS setup
# 2020-06-24: HACK: Do not ask why different commands on Linux and macOS. IDK, wished they we the same. These are the only commands that worked on according platforms right after the fresh Nix installer rollout.
( nix-channel --update && nix-env -iA nixpkgs.nix) || ( sudo nix upgrade-nix)
2020-06-01 19:08:37 +03:00
2020-06-01 18:43:26 +03:00
2020-05-28 00:57:13 +03:00
# NOTE: Secrets are not shared to PRs from forks
2020-06-23 19:09:01 +03:00
# NOTE: nix-build | cachix push <project> - uploads binaries, runs&works only in the branches of the main repository, so for PRs - else case runs
2020-05-28 00:57:13 +03:00
if [ ! " $CACHIX_SIGNING_KEY " = "" ]
then
# NOTE: Build of the inside repo branch - enable push Cachix cache
2020-06-23 19:09:01 +03:00
BUILD_PROJECT | cachix push " $project "
2020-05-28 00:57:13 +03:00
else
# NOTE: Build of the side repo/PR - can not push Cachix cache
BUILD_PROJECT
fi
}
# NOTE: Run the entry function of the script
MAIN