Skip to content

Commit 5539c0d

Browse files
authored
Build custom sysroot with --always-encode-mir on (rust-lang#1717)
* Build sysroot and repurpose make-kani-release This change builds a custom sysroot for Kani. This new sysroot will contain a "lib/" folder with Kani libraries as well as the standard libraries compiled with --always-encode-mir. This enable us to fully traverse the std MIR and fix the missing functions errors. Other changes to the build were described in the issue here: rust-lang#1605 (comment) * Add pre-compiled libraries to the bundle. The size of the bundle did increase quite a bit on my linux machine. It went from 24MB to 67MB. This is still pretty far from GitHub's max size of 2GB: https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases#storage-and-bandwidth-quotas
1 parent f3b5a97 commit 5539c0d

29 files changed

+547
-254
lines changed

.cargo/config.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Copyright Kani Contributors
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

4+
# Command aliases
5+
[alias]
6+
# Build kani with development configuration.
7+
build-dev = "run -p build-kani -- build-dev"
8+
# Build kani release bundle.
9+
bundle = "run -p build-kani -- bundle"
10+
11+
# Constants used by different processes.
12+
# These constants should be evaluated during compilation via `env!()`.
13+
[env]
14+
# Path to the repository root.
15+
KANI_REPO_ROOT={value = "", relative = true}
16+
# Path to the sysroot build. This folder will contain a bin/ and a lib/ folder.
17+
KANI_SYSROOT ={value = "target/kani", relative = true}
18+
# Target for building Kani's libraries. Their configuration is different than the binary build, so we must use
19+
# something different than regular `target/`.
20+
KANI_BUILD_LIBS ={value = "target/build-libs", relative = true}
21+
# Build Kani library without `build-std`.
22+
KANI_LEGACY_LIBS ={value = "target/legacy-libs", relative = true}
23+
424
[target.'cfg(all())']
525
rustflags = [ # Global lints/warnings. Need to use underscore instead of -.
626

.github/workflows/kani.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
os: ${{ matrix.os }}
2929

3030
- name: Build Kani
31-
run: cargo build
31+
run: cargo build-dev
3232

3333
- name: Execute Kani regression
3434
run: ./scripts/kani-regression.sh
@@ -47,7 +47,7 @@ jobs:
4747
os: ubuntu-20.04
4848

4949
- name: Build Kani
50-
run: cargo build
50+
run: cargo build-dev
5151

5252
- name: Execute Kani regression
5353
run: ./scripts/kani-regression.sh
@@ -64,7 +64,7 @@ jobs:
6464
os: ubuntu-20.04
6565

6666
- name: Build Kani using release mode
67-
run: cargo build --release
67+
run: cargo build-dev -- --release
6868

6969
- name: Execute Kani performance tests
7070
run: ./scripts/kani-perf.sh
@@ -83,7 +83,7 @@ jobs:
8383
os: ubuntu-20.04
8484

8585
- name: Build Kani
86-
run: cargo build
86+
run: cargo build-dev
8787

8888
- name: Install book runner dependencies
8989
run: ./scripts/setup/install_bookrunner_deps.sh
@@ -133,7 +133,7 @@ jobs:
133133

134134
- name: Build release bundle
135135
run: |
136-
cargo run -p make-kani-release -- latest
136+
cargo bundle -- latest
137137
cargo package -p kani-verifier
138138
139139
- name: Build container test

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080

8181
- name: Build release bundle
8282
run: |
83-
cargo run -p make-kani-release -- ${{ needs.Release.outputs.version }}
83+
cargo bundle
8484
8585
- name: Upload artifact
8686
uses: actions/upload-release-asset@v1
@@ -113,7 +113,7 @@ jobs:
113113

114114
- name: 'Build release bundle'
115115
run: |
116-
cargo run -p make-kani-release -- ${{ needs.Release.outputs.version }}
116+
cargo bundle
117117
cargo package -p kani-verifier
118118
119119
- name: 'Login to GitHub Container Registry'

Cargo.lock

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ dependencies = [
8989
"walkdir",
9090
]
9191

92+
[[package]]
93+
name = "build-kani"
94+
version = "0.11.0"
95+
dependencies = [
96+
"anyhow",
97+
"cargo_metadata",
98+
"clap 3.2.22",
99+
"which",
100+
]
101+
92102
[[package]]
93103
name = "camino"
94104
version = "1.1.1"
@@ -135,12 +145,51 @@ dependencies = [
135145
"ansi_term",
136146
"atty",
137147
"bitflags",
138-
"strsim",
139-
"textwrap",
148+
"strsim 0.8.0",
149+
"textwrap 0.11.0",
140150
"unicode-width",
141151
"vec_map",
142152
]
143153

154+
[[package]]
155+
name = "clap"
156+
version = "3.2.22"
157+
source = "registry+https://github.com/rust-lang/crates.io-index"
158+
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
159+
dependencies = [
160+
"atty",
161+
"bitflags",
162+
"clap_derive",
163+
"clap_lex",
164+
"indexmap",
165+
"once_cell",
166+
"strsim 0.10.0",
167+
"termcolor",
168+
"textwrap 0.15.1",
169+
]
170+
171+
[[package]]
172+
name = "clap_derive"
173+
version = "3.2.18"
174+
source = "registry+https://github.com/rust-lang/crates.io-index"
175+
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
176+
dependencies = [
177+
"heck 0.4.0",
178+
"proc-macro-error",
179+
"proc-macro2",
180+
"quote",
181+
"syn",
182+
]
183+
184+
[[package]]
185+
name = "clap_lex"
186+
version = "0.2.4"
187+
source = "registry+https://github.com/rust-lang/crates.io-index"
188+
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
189+
dependencies = [
190+
"os_str_bytes",
191+
]
192+
144193
[[package]]
145194
name = "compiletest"
146195
version = "0.0.0"
@@ -312,7 +361,7 @@ dependencies = [
312361
"ar",
313362
"atty",
314363
"bitflags",
315-
"clap",
364+
"clap 2.34.0",
316365
"cprover_bindings",
317366
"home",
318367
"kani_metadata",
@@ -337,7 +386,7 @@ version = "0.11.0"
337386
dependencies = [
338387
"anyhow",
339388
"cargo_metadata",
340-
"clap",
389+
"clap 2.34.0",
341390
"console",
342391
"glob",
343392
"kani_metadata",
@@ -426,14 +475,6 @@ dependencies = [
426475
"cfg-if",
427476
]
428477

429-
[[package]]
430-
name = "make-kani-release"
431-
version = "0.1.0"
432-
dependencies = [
433-
"anyhow",
434-
"which",
435-
]
436-
437478
[[package]]
438479
name = "matchers"
439480
version = "0.1.0"
@@ -553,6 +594,12 @@ dependencies = [
553594
"winapi",
554595
]
555596

597+
[[package]]
598+
name = "os_str_bytes"
599+
version = "6.3.0"
600+
source = "registry+https://github.com/rust-lang/crates.io-index"
601+
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
602+
556603
[[package]]
557604
name = "parking_lot"
558605
version = "0.12.1"
@@ -810,13 +857,19 @@ version = "0.8.0"
810857
source = "registry+https://github.com/rust-lang/crates.io-index"
811858
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
812859

860+
[[package]]
861+
name = "strsim"
862+
version = "0.10.0"
863+
source = "registry+https://github.com/rust-lang/crates.io-index"
864+
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
865+
813866
[[package]]
814867
name = "structopt"
815868
version = "0.3.26"
816869
source = "registry+https://github.com/rust-lang/crates.io-index"
817870
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
818871
dependencies = [
819-
"clap",
872+
"clap 2.34.0",
820873
"lazy_static",
821874
"structopt-derive",
822875
]
@@ -864,6 +917,15 @@ dependencies = [
864917
"unicode-ident",
865918
]
866919

920+
[[package]]
921+
name = "termcolor"
922+
version = "1.1.3"
923+
source = "registry+https://github.com/rust-lang/crates.io-index"
924+
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
925+
dependencies = [
926+
"winapi-util",
927+
]
928+
867929
[[package]]
868930
name = "terminal_size"
869931
version = "0.1.17"
@@ -883,6 +945,12 @@ dependencies = [
883945
"unicode-width",
884946
]
885947

948+
[[package]]
949+
name = "textwrap"
950+
version = "0.15.1"
951+
source = "registry+https://github.com/rust-lang/crates.io-index"
952+
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
953+
886954
[[package]]
887955
name = "thread_local"
888956
version = "1.1.4"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ members = [
4040
"library/std",
4141
"tools/bookrunner",
4242
"tools/compiletest",
43-
"tools/make-kani-release",
43+
"tools/build-kani",
4444
"kani-driver",
4545
"kani-compiler",
4646
"kani_metadata",

deny.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allow = [
3131
allow-osi-fsf-free = "neither"
3232
confidence-threshold = 0.8
3333

34-
# All these exceptions should probably appear in: tools/make-kani-release/license-notes.txt
34+
# All these exceptions should probably appear in: tools/build-kani/license-notes.txt
3535
exceptions = [
3636
{ name = "Inflector", allow=["BSD-2-Clause"] },
3737
{ name = "unicode-ident", allow=["Unicode-DFS-2016"] },

kani-compiler/build.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use std::env;
55
use std::path::PathBuf;
6-
use std::process::Command;
76

87
macro_rules! path_str {
98
($input:expr) => {
@@ -17,34 +16,6 @@ macro_rules! path_str {
1716
};
1817
}
1918

20-
/// Build the target library, and setup cargo to rerun them if the source has changed.
21-
fn setup_lib(out_dir: &str, lib_out: &str, lib: &str) {
22-
let kani_lib = vec!["..", "library", lib];
23-
println!("cargo:rerun-if-changed={}", path_str!(kani_lib));
24-
25-
let mut kani_lib_toml = kani_lib;
26-
kani_lib_toml.push("Cargo.toml");
27-
let args = [
28-
"build",
29-
"--manifest-path",
30-
&path_str!(kani_lib_toml),
31-
"-Z",
32-
"unstable-options",
33-
"--out-dir",
34-
lib_out,
35-
"--target-dir",
36-
out_dir,
37-
];
38-
let result = Command::new("cargo")
39-
.env("CARGO_ENCODED_RUSTFLAGS", "--cfg=kani")
40-
.args(args)
41-
.status()
42-
.unwrap();
43-
if !result.success() {
44-
std::process::exit(1);
45-
}
46-
}
47-
4819
/// Configure the compiler to build kani-compiler binary. We currently support building
4920
/// kani-compiler with nightly only. We also link to the rustup rustc_driver library for now.
5021
pub fn main() {
@@ -58,12 +29,4 @@ pub fn main() {
5829
// in a relative location for a symlink to the local rust toolchain
5930
let origin = if cfg!(target_os = "macos") { "@loader_path" } else { "$ORIGIN" };
6031
println!("cargo:rustc-link-arg-bin=kani-compiler=-Wl,-rpath,{}/../toolchain/lib", origin);
61-
62-
// Compile kani library and export KANI_LIB_PATH variable with its relative location.
63-
let out_dir = env::var("OUT_DIR").unwrap();
64-
let lib_out = path_str!([&out_dir, "lib"]);
65-
setup_lib(&out_dir, &lib_out, "kani");
66-
setup_lib(&out_dir, &lib_out, "kani_macros");
67-
setup_lib(&out_dir, &lib_out, "std");
68-
println!("cargo:rustc-env=KANI_LIB_PATH={}", lib_out);
6932
}

0 commit comments

Comments
 (0)