-
Notifications
You must be signed in to change notification settings - Fork 108
/
flake.nix
152 lines (136 loc) · 5.02 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
description = "A static verifier for Rust, based on the Viper verification infrastructure.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
naersk.url = "github:nmattia/naersk";
rust-overlay.url = "github:oxalica/rust-overlay";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, naersk, rust-overlay, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlay ];
};
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
naersk-lib = naersk.lib."${system}".override {
cargo = rust;
rustc = rust;
};
prusti-version = "${self.tag or "${self.lastModifiedDate}.${self.shortRev or "dirty"}"}";
in rec {
packages = {
prusti = naersk-lib.buildPackage {
name = "prusti";
version = "${prusti-version}";
root = ./.;
buildInputs = [
pkgs.pkg-config
pkgs.wget
pkgs.gcc
pkgs.openssl
pkgs.jdk11
packages.viper
packages.ow2_asm
];
nativeBuildInputs = [
pkgs.makeWrapper
];
copyTarget = true;
compressTarget = false;
override = _: {
preBuild = ''
export LD_LIBRARY_PATH="${pkgs.jdk11}/lib/openjdk/lib/server"
export VIPER_HOME="${packages.viper}/backends"
export Z3_EXE="${packages.viper}/z3/bin/z3"
export ASM_JAR="${packages.ow2_asm}/asm.jar"
'';
};
overrideMain = _: {
postInstall = ''
rm $out/bin/test-crates
for f in $(find $out/bin/ $out/libexec/ -type f -executable); do
wrapProgram $f \
--set RUST_SYSROOT "${rust}" \
--set JAVA_HOME "${pkgs.jdk11}/lib/openjdk" \
--set LD_LIBRARY_PATH "${pkgs.jdk11}/lib/openjdk/lib/server" \
--set VIPER_HOME "${packages.viper}/backends" \
--set Z3_EXE "${packages.viper}/z3/bin/z3"
done
mkdir $out/bin/deps
cp $out/target/release/libprusti_contracts.rlib $out/bin
cp $out/target/release/deps/libprusti_contracts_internal-* $out/bin/deps
rm -rf $out/target
rm $out/bin/deps/*.{rlib,rmeta}
'';
};
};
viper = pkgs.fetchzip {
name = "viper";
url = "https://viper.ethz.ch/downloads/ViperToolsNightlyLinux.zip";
stripRoot = false;
hash = "sha256-82vnyO7QWaLzehnBzPJxuEmdqK0MnWWwQnmdLq28sQc=";
};
ow2_asm = pkgs.stdenv.mkDerivation rec {
name = "asm";
version = "3.3.1";
src = pkgs.fetchurl {
url = "https://repo.maven.apache.org/maven2/${name}/${name}/${version}/${name}-${version}.jar";
hash = "sha256-wrOSdfjpUbx0dQCAoSZs2rw5OZvF4T1kK/LTRkSd9/M=";
};
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir $out
cp ${src} $out/asm.jar
'';
};
};
checks = {
# prusti-test = naersk-lib.buildPackage {
# name = "prusti-test";
# version = "${prusti-version}";
# root = ./.;
# checkInputs = [
# pkgs.pkg-config
# pkgs.wget
# pkgs.gcc
# pkgs.openssl
# pkgs.jdk11
# packages.viper
# packages.ow2_asm
# ];
# doCheck = true;
# override = _: {
# preBuild = ''
# export LD_LIBRARY_PATH="${pkgs.jdk11}/lib/openjdk/lib/server"
# export VIPER_HOME="${packages.viper}/backends"
# export Z3_EXE="${packages.viper}/z3/bin/z3"
# export ASM_JAR="${packages.ow2_asm}/asm.jar"
# '';
# preCheck = ''
# export RUST_SYSROOT="${rust}"
# export JAVA_HOME="${pkgs.jdk11}/lib/openjdk"
# export LD_LIBRARY_PATH="${pkgs.jdk11}/lib/openjdk/lib/server"
# export VIPER_HOME="${packages.viper}/backends"
# export Z3_EXE="${packages.viper}/z3/bin/z3"
# '';
# };
# };
prusti-simple-test = pkgs.runCommand "prusti-simple-test" {
buildInputs = [
defaultPackage
rust
];
}
''
cargo new --name example $out/example
sed -i '1s/^/use prusti_contracts::*;\n/;s/println.*$/assert!(true);/' $out/example/src/main.rs
cargo-prusti --manifest-path=$out/example/Cargo.toml
'';
};
defaultPackage = packages.prusti;
}
);
}