Skip to content

Commit 2895d00

Browse files
committed
Parameterise static library version in Rust build script
1 parent 3852ddc commit 2895d00

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ file(
4242
STRINGS src/config.inc CBMC_VERSION
4343
REGEX "CBMC_VERSION = (.*)")
4444
string(REGEX REPLACE "CBMC_VERSION = (.*)" "\\1" CBMC_VERSION ${CBMC_VERSION})
45+
message(STATUS "Building CBMC version ${CBMC_VERSION}")
4546

4647
project(CBMC VERSION ${CBMC_VERSION})
4748

@@ -274,7 +275,7 @@ else()
274275

275276
corrosion_import_crate(MANIFEST_PATH src/libcprover-rust/Cargo.toml)
276277
list(JOIN sat_impl " " sat_impl_str)
277-
corrosion_set_env_vars(cprover-api-rust CBMC_BUILD_DIR=${CMAKE_BINARY_DIR})
278+
corrosion_set_env_vars(cprover-api-rust CBMC_BUILD_DIR=${CMAKE_BINARY_DIR} CBMC_VERSION=${CBMC_VERSION})
278279
corrosion_link_libraries(cprover-api-rust cprover-api-cpp)
279280
install(TARGETS cprover-api-rust RUNTIME DESTINATION lib)
280281
# NOTE: We want to rename to a name consistent with the name of the

src/libcprover-rust/build.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ fn get_build_directory() -> Result<String, VarError> {
1212
env::var("CBMC_BUILD_DIR")
1313
}
1414

15+
// Passed by the top-level CMakeLists.txt to control which version of the
16+
// static library of CBMC we're linking against. A user can also change the
17+
// environment variable to link against different versions of CBMC.
18+
fn get_cbmc_version() -> Result<String, VarError> {
19+
env::var("CBMC_VERSION")
20+
}
21+
1522
fn get_library_build_dir() -> std::io::Result<PathBuf> {
1623
let env_var_fetch_result = get_build_directory();
1724
if let Ok(build_dir) = env_var_fetch_result {
@@ -50,5 +57,10 @@ fn main() {
5057
libraries_path.display()
5158
);
5259

53-
println!("cargo:rustc-link-lib=static=cprover.5.78.0");
60+
let cprover_static_libname = match get_cbmc_version() {
61+
Ok(version) => String::from("cprover.") + &version,
62+
Err(err) => panic!("Error: {}", err),
63+
};
64+
65+
println!("cargo:rustc-link-lib=static={}", cprover_static_libname);
5466
}

0 commit comments

Comments
 (0)