2019-11-07 14:31:23 +00:00
{ stdenv , callPackage , fetchFromGitHub , clang , go , nim , sqlite , pcre , rocksdb }:
{ buildSamples ? true }:
let
inherit ( stdenv . lib ) concatMapStringsSep makeLibraryPath optional optionalString ;
mkFilter = callPackage ./mkFilter.nix { inherit ( stdenv ) lib ; } ;
vendorDeps = [
" n i m - c h r o n i c l e s " " n i m - f a s t s t r e a m s " " n i m - j s o n - s e r i a l i z a t i o n " " n i m - c h r o n o s " " n i m - e t h " " n i m - j s o n "
" n i m - m e t r i c s " " n i m - s e c p 2 5 6 k 1 " " n i m - s e r i a l i z a t i o n " " n i m - s t e w " " n i m - s t i n t " " n i m c r y p t o "
] ;
in
stdenv . mkDerivation rec {
name = " n i m b u s - ${ version } " ;
version = " 0 . 0 . 1 " ;
src =
let path = ./.. ; # Import the root /android and /mobile/js_files folders clean of any build artifacts
in builtins . path { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control
inherit path ;
name = " n i m b u s - s o u r c e s " ;
filter =
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
mkFilter {
dirRootsToInclude = [
" v e n d o r " " w r a p p e r s "
] ;
dirsToExclude = [ " . g i t " " . s v n " " C V S " " . h g " " n i m b u s - b u i l d - s y s t e m " " t e s t s " ]
++ ( builtins . map ( dep : " v e n d o r / ${ dep } " ) vendorDeps ) ;
filesToInclude = [ ] ;
filesToExclude = [ " V E R S I O N " " a n d r o i d / g r a d l e w " ] ;
root = path ;
} ;
} ;
nativeBuildInputs = optional buildSamples go ;
buildInputs = [ clang nim rocksdb pcre sqlite ] ;
LD_LIBRARY_PATH = " ${ makeLibraryPath buildInputs } " ;
buildPhase = ''
2019-11-27 10:06:58 +00:00
mkdir - p $ TMPDIR/.nimcache $ TMPDIR/.nimcache_static ./build
2019-11-07 14:31:23 +00:00
BUILD_MSG = " \\ e [ 9 2 m B u i l d i n g : \\ e [ 3 9 m "
export CC = " ${ clang } / b i n / c l a n g "
ln - s nimbus . nimble nimbus . nims
vendorPathOpts = " ${ concatMapStringsSep " " ( dep : " - - p a t h : . / v e n d o r / ${ dep } " ) vendorDeps } "
echo - e $ BUILD_MSG " b u i l d / l i b n i m b u s . s o " && \
$ { nim } /bin/nim c - - app:lib - - noMain - - nimcache:$TMPDIR/.nimcache - d:release '' ${ vendorPathOpts } - o : . / b u i l d / l i b n i m b u s . s o w r a p p e r s / l i b n i m b u s . n i m
echo - e $ BUILD_MSG " b u i l d / l i b n i m b u s . a " && \
2019-11-27 10:06:58 +00:00
$ { nim } /bin/nim c - - app:staticlib - - noMain - - nimcache:$TMPDIR/.nimcache_static - d:release '' ${ vendorPathOpts } - o : b u i l d / l i b n i m b u s . a w r a p p e r s / l i b n i m b u s . n i m & & \
[ [ - e " l i b n i m b u s . a " ] ] && mv " l i b n i m b u s . a " build / # workaround for https://github.com/nim-lang/Nim/issues/12745
2019-11-07 14:31:23 +00:00
2019-11-27 10:06:58 +00:00
rm - rf $ TMPDIR/.nimcache $ TMPDIR/.nimcache_static
2019-11-07 14:31:23 +00:00
'' +
optionalString buildSamples ''
mkdir - p $ TMPDIR/.home/.cache
export HOME = $ TMPDIR/.home
echo - e $ BUILD_MSG " b u i l d / C _ w r a p p e r _ e x a m p l e " && \
$ CC wrappers/wrapper_example.c - Wl , - rpath , ' $ $ ORIGIN' - Lbuild - lnimbus - lm - g - o build/C_wrapper_example
echo - e $ BUILD_MSG " b u i l d / g o _ w r a p p e r _ e x a m p l e " && \
2019-11-27 10:06:58 +00:00
$ { go } /bin/go build - o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
2019-11-07 14:31:23 +00:00
echo - e $ BUILD_MSG " b u i l d / g o _ w r a p p e r _ w h i s p e r _ e x a m p l e " && \
2019-11-27 10:06:58 +00:00
$ { go } /bin/go build - o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
2019-11-07 14:31:23 +00:00
rm - rf $ TMPDIR/.home/.cache
'' ;
installPhase = ''
mkdir - p $ out / { include , lib }
cp ./wrappers/libnimbus.h $ out/include /
cp ./build/libnimbus. { a , so } $ out/lib /
'' +
optionalString buildSamples ''
mkdir - p $ out/samples
cp ./build / { C_wrapper_example , go_wrapper_example , go_wrapper_whisper_example } $ out/samples
'' ;
meta = with stdenv . lib ; {
description = " A C w r a p p e r o f t h e N i m b u s E t h e r e u m 2 . 0 S h a r d i n g C l i e n t f o r R e s o u r c e - R e s t r i c t e d D e v i c e s " ;
homepage = https://github.com/status-im/nimbus ;
license = with licenses ; [ asl20 ] ;
platforms = with platforms ; unix ++ windows ;
} ;
}