File tree 9 files changed +242
-5
lines changed 9 files changed +242
-5
lines changed Original file line number Diff line number Diff line change 1
- cmake_minimum_required (VERSION 3.8 )
1
+ cmake_minimum_required (VERSION 3.15 )
2
2
3
3
# Compile with /usr/bin/clang on MacOS
4
4
# See https://github.com/diffblue/cbmc/issues/4956
@@ -254,4 +254,16 @@ if(WITH_JBMC)
254
254
add_subdirectory (jbmc)
255
255
endif ()
256
256
257
+ option (WITH_RUST_API "Build with the CPROVER Rust API" ON )
258
+ if (WITH_RUST_API)
259
+ find_package (Corrosion REQUIRED)
260
+
261
+ corrosion_import_crate(MANIFEST_PATH cprover-rust-api/Cargo.toml)
262
+
263
+ target_link_libraries (cprover-api cprover-rust-api)
264
+ install (TARGETS cprover-rust-api RUNTIME DESTINATION lib)
265
+ # TODO: cargo builds the artifact with underscores - we need to change to hyphens
266
+ # to bring to same naming convention as the rest of CBMC
267
+ endif ()
268
+
257
269
include (cmake/packaging.cmake)
Original file line number Diff line number Diff line change @@ -49,3 +49,13 @@ void cprover_api::load_model_from_files(const std::vector<std::string> &files)
49
49
model = util_make_unique<goto_modelt>(
50
50
initialize_goto_model (files, *message_handler, *options));
51
51
}
52
+
53
+ std::unique_ptr<cprover_api> new_cprover_api ()
54
+ {
55
+ return std::unique_ptr<cprover_api>(new cprover_api ());
56
+ }
57
+
58
+ std::unique_ptr<std::string> get_api_version (std::unique_ptr<cprover_api> api_handle)
59
+ {
60
+ return util_make_unique<std::string>(api_handle->get_api_version ());
61
+ }
Original file line number Diff line number Diff line change @@ -29,12 +29,16 @@ struct cprover_api
29
29
30
30
// A simple API version information function.
31
31
// TODO: Investigate best way to store and expose version string.
32
- std::string get_api_version () { return std::string{" 0.1" }; }
32
+ std::string get_api_version () const { return std::string{" 0.1" }; }
33
33
34
34
private:
35
35
std::unique_ptr<goto_modelt> model;
36
36
std::unique_ptr<message_handlert> message_handler;
37
37
std::unique_ptr<optionst> options;
38
38
};
39
39
40
+ // TODO: Investigate best way to define this
41
+ std::unique_ptr<cprover_api> new_cprover_api ();
42
+ std::unique_ptr<std::string> get_api_version (std::unique_ptr<cprover_api> api_handle);
43
+
40
44
#endif
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # ignore build artefacts folder
2
+ target /
Original file line number Diff line number Diff line change @@ -6,3 +6,10 @@ edition = "2021"
6
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
8
8
[dependencies ]
9
+ cxx = " 1.0"
10
+
11
+ [build-dependencies ]
12
+ cxx-build = " 1.0"
13
+
14
+ [lib ]
15
+ crate-type = [" staticlib" ]
Original file line number Diff line number Diff line change
1
+ use std:: path:: Path ;
2
+
3
+ fn main ( ) {
4
+ let cpp_api_path = Path :: new ( "../cprover-cpp-api/src" ) ;
5
+ println ! ( "{}" , cpp_api_path. display( ) ) ;
6
+ let _build = cxx_build:: bridge ( "src/lib.rs" )
7
+ // .file("target/cxxbridge/cprover-rust-api/src/lib.rs.cc")
8
+ . include ( cpp_api_path)
9
+ . flag_if_supported ( "-std=c++11" )
10
+ . compile ( "cprover-rust-api" ) ;
11
+
12
+ println ! ( "cargo:rustc-link-search=native=/Users/fotiskoutoulakis/Devel/cbmc/build/lib/" ) ;
13
+ println ! ( "cargo:rustc-link-lib=static=goto-programs" ) ;
14
+ println ! ( "cargo:rustc-link-lib=static=util" ) ;
15
+ println ! ( "cargo:rustc-link-lib=static=langapi" ) ;
16
+ println ! ( "cargo:rustc-link-lib=static=ansi-c" ) ;
17
+ println ! ( "cargo:rustc-link-lib=static=big-int" ) ;
18
+ println ! ( "cargo:rustc-link-lib=static=linking" ) ;
19
+ println ! ( "cargo:rustc-link-lib=static=cprover-api" ) ;
20
+ }
Original file line number Diff line number Diff line change
1
+ #[ cxx:: bridge]
2
+ pub mod ffi {
3
+ unsafe extern "C++" {
4
+ include ! ( "api.h" ) ;
5
+ type cprover_api ;
6
+
7
+ fn new_cprover_api ( ) -> UniquePtr < cprover_api > ;
8
+ fn get_api_version ( api_handle : UniquePtr < cprover_api > ) -> UniquePtr < CxxString > ;
9
+ }
10
+ }
11
+
12
+
13
+ // To test run "cargo test -- --nocapture"
1
14
#[ cfg( test) ]
2
15
mod tests {
16
+ use super :: * ;
17
+
3
18
#[ test]
4
19
fn it_works ( ) {
5
- let result = 2 + 2 ;
6
- assert_eq ! ( result, 4 ) ;
20
+ let client = ffi:: new_cprover_api ( ) ;
21
+ let result = ffi:: get_api_version ( client) ;
22
+ println ! ( "{}" , * result) ;
23
+ // assert_eq!(*result, "0.1");
7
24
}
8
25
}
You can’t perform that action at this time.
0 commit comments