Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto generate zenoh version in header from version.txt #800

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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