1{ stdenv, fetchFromGitHub, maven, openjdk8, releaseTools }:
2
3# TODO:
4# - Investigate builds on platforms other than 64-bit linux
5# - Separate package for Maven cache? This would speed up builds and
6# theoretically could still be pure
7# - Find a way to prevent Maven from downloading artifacts irrelevant
8# to the platform for which we are building
9
10releaseTools.mvnBuild rec {
11 name = "kframework-20150415";
12
13 mvn8 = maven.override {
14 jdk = openjdk8; # K uses Java 8. The official docs reference the
15 # Oracle VM, but it's been working with OpenJDK
16 };
17
18 src = fetchFromGitHub {
19 owner = "kframework";
20 repo = "k";
21 rev = "85a41bc024"; # nightly build for April 15th, 2015
22 sha256 = "01ndfdnqxp2w86pg3ax39sxayb2pfm39lj1h3818zzn86gqwa1vc";
23 };
24
25 buildInputs = [ mvn8 openjdk8 ];
26
27 preSetupPhase = ''
28 # z3 needs this to pass tests
29 export LD_LIBRARY_PATH=$(cat $NIX_CC/nix-support/orig-cc)/lib
30 # not sure if this does anything, since it might only speed up incremental builds
31 export MAVEN_OPTS="-XX:+TieredCompilation"
32 '';
33
34 mvnAssembly = ''
35 mvn package -Dcheckstyle.skip -Dmaven.test.skip=true -Dmaven.repo.local=$M2_REPO
36 '';
37
38 mvnRelease = ''
39 true # do nothing, since mvn package is sufficient
40 '';
41
42 # this is a custom version of k-distribution/src/main/scripts/lib/k
43 kscript = ''
44 #!/usr/bin/env bash
45 export JAVA=${openjdk8}/bin/java
46
47 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$out/lib"
48
49 export K_OPTS="-Xms64m -Xmx1024m -Xss32m -XX:+TieredCompilation"
50 export MISC_ARGS="-Djava.awt.headless=true"
51 export ARGS="$MISC_ARGS $K_OPTS"
52 $JAVA $ARGS -cp "$out/share/kframework/lib/java/*" org.kframework.main.Main "$@"
53 '';
54
55 finalPhase = ''
56 # set some environment variables
57 export K_ROOT=$PWD/k-distribution/target/release/k/
58 export K_SHARE=$out/share/kframework/
59 # make requisite directories
60 mkdir -p $out/lib $K_SHARE/lib/native
61 # copy over bin
62 cp -R $K_ROOT/bin $K_SHARE/
63 # symlink $out/bin to $out/share/kframework/bin
64 ln -s $K_SHARE/bin $out/bin
65 # copy everything relevant to $out/share/kframework
66 # we may want to consider adding the documentation etc.
67 cp -R $K_ROOT/include $K_SHARE/
68 cp -R $K_ROOT/lib/java $K_SHARE/lib/
69 cp -R $K_ROOT/lib/native/linux $K_SHARE/lib/native/
70 cp -R $K_ROOT/lib/native/linux64 $K_SHARE/lib/native/
71 # remove Windows batch scripts
72 rm $K_SHARE/bin/*.bat # */
73 # TODO: fix these scripts so they work
74 rm $K_SHARE/bin/kserver $K_SHARE/bin/stop-kserver
75 # make our k wrapper script and substitute $out for its value
76 echo -n "$kscript" | sed "s:\$out:$out:g" > $K_SHARE/lib/k
77 chmod +x $K_SHARE/lib/k
78 # symlink requisite binaries
79 ln -s $K_SHARE/lib/k $out/lib/k
80 ln -s $K_SHARE/lib/native/linux/sdf2table $out/bin/sdf2table
81 ln -s $K_SHARE/lib/native/linux64/z3 $out/bin/z3
82 ln -s $K_SHARE/lib/native/linux64/libz3.so $out/lib/libz3.so
83 ln -s $K_SHARE/lib/native/linux64/libz3java.so $out/lib/libz3java.so
84 # patch Z3 so it uses the right interpreter/libs
85 patchelf \
86 --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
87 --set-rpath $(cat $NIX_CC/nix-support/orig-cc)/lib \
88 --force-rpath \
89 $K_SHARE/lib/native/linux64/z3
90 '';
91
92 meta = {
93 description = "A rewrite-based executable semantic framework in which programming languages, type systems and formal analysis tools can be defined";
94 homepage = http://www.kframework.org;
95 license = stdenv.lib.licenses.bsd3; # technically it is the UIUC/NCSA license
96 # but LLVM uses that license as well and
97 # it is marked as BSD3
98 maintainers = [ stdenv.lib.maintainers.taktoa ];
99 platforms = stdenv.lib.platforms.linux; # I haven't done testing on other OSes, but
100 # since it's Java it should run anywhere
101 };
102}