Skip to content

Commit 4a5c1f9

Browse files
authored
Merge pull request #7512 from NlightNFotis/rust_fmt_check
Add a rustfmt syntactic check for the Rust project
2 parents 55112f7 + 9e84483 commit 4a5c1f9

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

.github/workflows/syntax-checks.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,18 @@ jobs:
4747
BASE_BRANCH: ${{ github.base_ref }}
4848
MERGE_BRANCH: ${{ github.ref }}
4949
run: ./.github/workflows/pull-request-check-cpplint.sh
50+
51+
# This job should take about a minute (est)
52+
check-rustfmt:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout CBMC repository
56+
uses: actions/checkout@v3
57+
- name: Install latest stable Rust toolchain
58+
uses: actions-rs/toolchain@v1
59+
with:
60+
toolchain: stable
61+
override: true
62+
components: rustfmt, clippy
63+
- name: Run `cargo fmt` on top of Rust API project
64+
run: cd src/libcprover-rust; cargo fmt --all -- --check

src/libcprover-rust/build.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ fn get_library_build_dir() -> std::io::Result<PathBuf> {
2020
path.push("lib/");
2121
return Ok(path);
2222
}
23-
Err(Error::new(ErrorKind::Other, "failed to get build output directory"))
23+
Err(Error::new(
24+
ErrorKind::Other,
25+
"failed to get build output directory",
26+
))
2427
}
2528

2629
fn get_cadical_build_dir() -> std::io::Result<PathBuf> {
@@ -31,7 +34,10 @@ fn get_cadical_build_dir() -> std::io::Result<PathBuf> {
3134
path.push("cadical-src/build/");
3235
return Ok(path);
3336
}
34-
Err(Error::new(ErrorKind::Other, "failed to get build output directory"))
37+
Err(Error::new(
38+
ErrorKind::Other,
39+
"failed to get build output directory",
40+
))
3541
}
3642

3743
fn get_sat_library() -> std::io::Result<&'static str> {
@@ -40,13 +46,19 @@ fn get_sat_library() -> std::io::Result<&'static str> {
4046
if let Ok(sat_impl) = env_var_fetch_result {
4147
let solver_lib = match sat_impl.as_str() {
4248
"minisat2" => Ok("minisat2-condensed"),
43-
"glucose" => Ok("glucose-condensed"),
44-
"cadical" => Ok("cadical"),
45-
_ => Err(Error::new(ErrorKind::Other, "no identifiable solver detected"))
49+
"glucose" => Ok("glucose-condensed"),
50+
"cadical" => Ok("cadical"),
51+
_ => Err(Error::new(
52+
ErrorKind::Other,
53+
"no identifiable solver detected",
54+
)),
4655
};
4756
return solver_lib;
4857
}
49-
Err(Error::new(ErrorKind::Other, "SAT_IMPL environment variable not set"))
58+
Err(Error::new(
59+
ErrorKind::Other,
60+
"SAT_IMPL environment variable not set",
61+
))
5062
}
5163

5264
fn main() {
@@ -65,12 +77,12 @@ fn main() {
6577

6678
let libraries_path = match get_library_build_dir() {
6779
Ok(path) => path,
68-
Err(err) => panic!("Error: {}", err)
80+
Err(err) => panic!("Error: {}", err),
6981
};
7082

7183
let solver_lib = match get_sat_library() {
7284
Ok(solver) => solver,
73-
Err(err) => panic!("Error: {}", err)
85+
Err(err) => panic!("Error: {}", err),
7486
};
7587

7688
// Cadical is being built in its own directory, with the resultant artefacts being
@@ -79,12 +91,18 @@ fn main() {
7991
if solver_lib == "cadical" {
8092
let cadical_build_dir = match get_cadical_build_dir() {
8193
Ok(cadical_directory) => cadical_directory,
82-
Err(err) => panic!("Error: {}", err)
94+
Err(err) => panic!("Error: {}", err),
8395
};
84-
println!("cargo:rustc-link-search=native={}", cadical_build_dir.display());
96+
println!(
97+
"cargo:rustc-link-search=native={}",
98+
cadical_build_dir.display()
99+
);
85100
}
86101

87-
println!("cargo:rustc-link-search=native={}", libraries_path.display());
102+
println!(
103+
"cargo:rustc-link-search=native={}",
104+
libraries_path.display()
105+
);
88106
println!("cargo:rustc-link-lib=static=goto-programs");
89107
println!("cargo:rustc-link-lib=static=util");
90108
println!("cargo:rustc-link-lib=static=langapi");

src/libcprover-rust/src/lib.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cxx::{CxxVector, CxxString};
1+
use cxx::{CxxString, CxxVector};
22
#[cxx::bridge]
33
pub mod ffi {
44

@@ -31,7 +31,7 @@ fn print_response(vec: &CxxVector<CxxString>) {
3131
.iter()
3232
.map(|s| s.to_string_lossy().into_owned())
3333
.collect();
34-
34+
3535
for s in vec {
3636
println!("{}", s);
3737
}
@@ -54,24 +54,21 @@ mod tests {
5454

5555
#[test]
5656
fn translate_vector_of_rust_string_to_cpp() {
57-
let vec: Vec<String> = vec![
58-
"other/example.c".to_owned(),
59-
"/tmp/example2.c".to_owned()];
57+
let vec: Vec<String> = vec!["other/example.c".to_owned(), "/tmp/example2.c".to_owned()];
6058

6159
let vect = ffi::translate_vector_of_string(vec);
6260
assert_eq!(vect.len(), 2);
6361
}
64-
62+
6563
#[test]
6664
fn it_can_load_model_from_file() {
6765
let binding = ffi::new_api_session();
6866
let client = match binding.as_ref() {
6967
Some(api_ref) => api_ref,
7068
None => panic!("Failed to acquire API session handle"),
7169
};
72-
73-
let vec: Vec<String> = vec![
74-
"other/example.c".to_owned()];
70+
71+
let vec: Vec<String> = vec!["other/example.c".to_owned()];
7572

7673
let vect = ffi::translate_vector_of_string(vec);
7774
assert_eq!(vect.len(), 1);
@@ -87,11 +84,10 @@ mod tests {
8784
}
8885

8986
#[test]
90-
fn it_can_verify_the_loaded_model() {
87+
fn it_can_verify_the_loaded_model() {
9188
let client = ffi::new_api_session();
92-
93-
let vec: Vec<String> = vec![
94-
"other/example.c".to_owned()];
89+
90+
let vec: Vec<String> = vec!["other/example.c".to_owned()];
9591

9692
let vect = ffi::translate_vector_of_string(vec);
9793
client.load_model_from_files(vect);
@@ -112,9 +108,8 @@ mod tests {
112108
Some(api_ref) => api_ref,
113109
None => panic!("Failed to acquire API session handle"),
114110
};
115-
116-
let vec: Vec<String> = vec![
117-
"other/example.c".to_owned()];
111+
112+
let vec: Vec<String> = vec!["other/example.c".to_owned()];
118113

119114
let vect = ffi::translate_vector_of_string(vec);
120115
assert_eq!(vect.len(), 1);

0 commit comments

Comments
 (0)