Skip to content

Commit

Permalink
auto generate zenoh version in header from version.txt (#800)
Browse files Browse the repository at this point in the history
* auto generate zenoh version in header from version.txt

* copy version.txt to build directory
  • Loading branch information
milyin authored Nov 5, 2024
1 parent 2c814a0 commit c56a975
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 518 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function(configure_cargo_toml cargo_toml_dir CARGO_PROJECT_VERSION CARGO_LIB_NAM
${CMAKE_CURRENT_SOURCE_DIR}/cbindgen.toml
${CMAKE_CURRENT_SOURCE_DIR}/Cargo.lock
${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml
${CMAKE_CURRENT_SOURCE_DIR}/version.txt
DESTINATION ${cargo_toml_dir})
file(COPY
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh.h
Expand Down
42 changes: 32 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,6 @@ fn cargo_target_dir() -> PathBuf {
}

fn configure() {
let content = format!(
r#"#pragma once
#define TARGET_ARCH_{}
"#,
std::env::var("CARGO_CFG_TARGET_ARCH")
.unwrap()
.to_uppercase()
);

let mut file = std::fs::File::options()
.write(true)
.truncate(true)
Expand All @@ -293,7 +284,38 @@ fn configure() {
.open("include/zenoh_configure.h")
.unwrap();
file.lock_exclusive().unwrap();
file.write_all(content.as_bytes()).unwrap();

let version = std::fs::read_to_string("version.txt").unwrap();
let version = version.trim();
let version_parts: Vec<&str> = version.split('.').collect();
let major = version_parts[0];
let minor = version_parts[1];
let patch = version_parts[2];
let tweak = version_parts[3];
file.write_all(
format!(
r#"#pragma once
#define ZENOH_C "{}"
#define ZENOH_C_MAJOR {}
#define ZENOH_C_MINOR {}
#define ZENOH_C_PATCH {}
#define ZENOH_C_TWEAK {}
#define TARGET_ARCH_{}
"#,
version,
major,
minor,
patch,
tweak,
std::env::var("CARGO_CFG_TARGET_ARCH")
.unwrap()
.to_uppercase()
)
.as_bytes(),
)
.unwrap();

for (rust_feature, c_feature) in RUST_TO_C_FEATURES.entries() {
if test_feature(rust_feature) {
file.write_all(format!("#define {}\n", c_feature).as_bytes())
Expand Down
6 changes: 0 additions & 6 deletions include/zenoh.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
extern "C" {
#endif

#define ZENOH_C "0.7.2.0"
#define ZENOH_C_MAJOR 0
#define ZENOH_C_MINOR 7
#define ZENOH_C_PATCH 2
#define ZENOH_C_TWEAK 0

#ifdef _MSC_VER
#define ALIGN(n) __declspec(align(n))
#else
Expand Down
Loading

0 comments on commit c56a975

Please sign in to comment.