File tree Expand file tree Collapse file tree 9 files changed +265
-2
lines changed Expand file tree Collapse file tree 9 files changed +265
-2
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
@@ -252,4 +252,14 @@ if(WITH_JBMC)
252
252
add_subdirectory (jbmc)
253
253
endif ()
254
254
255
+ option (WITH_RUST_API "Build with the CPROVER Rust API" ON )
256
+ if (WITH_RUST_API)
257
+ find_package (Corrosion REQUIRED)
258
+ corrosion_import_crate(MANIFEST_PATH src/libcprover-rust/Cargo.toml)
259
+ target_link_libraries (cprover-api-cpp cprover-api-rust)
260
+ install (TARGETS cprover-api-rust RUNTIME DESTINATION lib)
261
+ # TODO: cargo builds the artifact with underscores - we need to change to hyphens
262
+ # to bring to same naming convention as the rest of CBMC
263
+ endif ()
264
+
255
265
include (cmake/packaging.cmake)
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ add_subdirectory(goto-interpreter)
85
85
add_subdirectory (cbmc-sequentialization)
86
86
add_subdirectory (cpp-linter)
87
87
add_subdirectory (catch-framework )
88
- add_subdirectory (libcprover-cpp)
88
+ # add_subdirectory(libcprover-cpp)
89
89
90
90
if (WITH_MEMORY_ANALYZER)
91
91
add_subdirectory (snapshot-harness)
Original file line number Diff line number Diff line change @@ -52,3 +52,15 @@ void api_sessiont::load_model_from_files(const std::vector<std::string> &files)
52
52
model = util_make_unique<goto_modelt>(
53
53
initialize_goto_model (files, *message_handler, *options));
54
54
}
55
+
56
+ // ///////////////////////////
57
+
58
+ std::unique_ptr<api_sessiont> new_api_session ()
59
+ {
60
+ return std::unique_ptr<api_sessiont>(new api_sessiont ());
61
+ }
62
+
63
+ std::unique_ptr<std::string> get_api_version (std::unique_ptr<api_sessiont> api_handle)
64
+ {
65
+ return util_make_unique<std::string>(api_handle->get_api_version ());
66
+ }
Original file line number Diff line number Diff line change @@ -27,10 +27,18 @@ struct api_sessiont
27
27
// / \param files: A vector<string> containing the filenames to be loaded
28
28
void load_model_from_files (const std::vector<std::string> &files);
29
29
30
+ // A simple API version information function.
31
+ // TODO: Investigate best way to store and expose version string.
32
+ std::string get_api_version () const { return std::string{" 0.1" }; }
33
+
30
34
private:
31
35
std::unique_ptr<goto_modelt> model;
32
36
std::unique_ptr<message_handlert> message_handler;
33
37
std::unique_ptr<optionst> options;
34
38
};
35
39
40
+ // TODO: Investigate best way to define this
41
+ std::unique_ptr<api_sessiont> new_api_session ();
42
+ std::unique_ptr<std::string> get_api_version (std::unique_ptr<api_sessiont> api_handle);
43
+
36
44
#endif
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
1
+ [package ]
2
+ name = " cprover-api-rust"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
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 ( "../libcprover-cpp" ) ;
5
+ println ! ( "{}" , cpp_api_path. display( ) ) ;
6
+ let _build = cxx_build:: bridge ( "src/lib.rs" )
7
+ . include ( cpp_api_path)
8
+ . flag_if_supported ( "-std=c++11" )
9
+ . compile ( "cprover-rust-api" ) ;
10
+
11
+ println ! ( "cargo:rustc-link-search=native=/Users/fotiskoutoulakis/Devel/cbmc/build/lib/" ) ;
12
+ println ! ( "cargo:rustc-link-lib=static=goto-programs" ) ;
13
+ println ! ( "cargo:rustc-link-lib=static=util" ) ;
14
+ println ! ( "cargo:rustc-link-lib=static=langapi" ) ;
15
+ println ! ( "cargo:rustc-link-lib=static=ansi-c" ) ;
16
+ println ! ( "cargo:rustc-link-lib=static=big-int" ) ;
17
+ println ! ( "cargo:rustc-link-lib=static=linking" ) ;
18
+ println ! ( "cargo:rustc-link-lib=static=cprover-api-cpp" ) ;
19
+ }
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 api_sessiont ;
6
+
7
+ fn new_api_session ( ) -> UniquePtr < api_sessiont > ;
8
+ fn get_api_version ( api_handle : UniquePtr < api_sessiont > ) -> UniquePtr < CxxString > ;
9
+ }
10
+ }
11
+
12
+ // To test run "cargo test -- --nocapture"
13
+ #[ cfg( test) ]
14
+ mod tests {
15
+ use super :: * ;
16
+
17
+ #[ test]
18
+ fn it_works ( ) {
19
+ let client = ffi:: new_api_session ( ) ;
20
+ let result = ffi:: get_api_version ( client) ;
21
+ println ! ( "{}" , * result) ;
22
+ // assert_eq!(*result, "0.1");
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments