From 2680c15e84366766218b628b713d883d741ab3fd Mon Sep 17 00:00:00 2001
From: Mahmoud Mazouz <mazouz.mahmoud@outlook.com>
Date: Wed, 10 Apr 2024 18:50:41 +0200
Subject: [PATCH 1/3] fix: Copy include folder into Cargo target directory

---
 Cargo.lock    |  7 +++++++
 Cargo.toml    |  1 +
 Cargo.toml.in |  1 +
 build.rs      | 39 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 644a21aaa..4d1b176cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -731,6 +731,12 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "fs_extra"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
+
 [[package]]
 name = "futures"
 version = "0.3.28"
@@ -3019,6 +3025,7 @@ dependencies = [
  "chrono",
  "env_logger 0.10.2",
  "fs2",
+ "fs_extra",
  "futures",
  "json5",
  "lazy_static",
diff --git a/Cargo.toml b/Cargo.toml
index 95867f95f..a654da5db 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -60,6 +60,7 @@ zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/ze
 cbindgen = "0.24.3"
 fs2 = "0.4.3"
 serde_yaml = "0.9.19"
+fs_extra = "1.3.0"
 
 [lib]
 path="src/lib.rs"
diff --git a/Cargo.toml.in b/Cargo.toml.in
index f434df3a1..be9b3f1b7 100644
--- a/Cargo.toml.in
+++ b/Cargo.toml.in
@@ -60,6 +60,7 @@ zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/ze
 cbindgen = "0.24.3"
 fs2 = "0.4.3"
 serde_yaml = "0.9.19"
+fs_extra = "1.3.0"
 
 [lib]
 path="@CARGO_PROJECT_DIR@src/lib.rs"
diff --git a/build.rs b/build.rs
index 17dde1894..66267e883 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,12 @@
 use fs2::FileExt;
+use std::env;
 use std::io::{Read, Write};
-use std::{borrow::Cow, collections::HashMap, io::BufWriter, path::Path};
+use std::{
+    borrow::Cow,
+    collections::HashMap,
+    io::BufWriter,
+    path::{Path, PathBuf},
+};
 
 const GENERATION_PATH: &str = "include/zenoh-gen.h";
 const SPLITGUIDE_PATH: &str = "splitguide.yaml";
@@ -33,10 +39,39 @@ fn main() {
     split_bindings(&split_guide).unwrap();
     text_replace(split_guide.rules.iter().map(|(name, _)| name.as_str()));
 
+    fs_extra::copy_items(
+        &["include"],
+        cargo_target_dir(),
+        &fs_extra::dir::CopyOptions::default().overwrite(true),
+    )
+    .expect("include should be copied to CARGO_TARGET_DIR");
+
     println!("cargo:rerun-if-changed=build.rs");
     println!("cargo:rerun-if-changed=src");
     println!("cargo:rerun-if-changed=splitguide.yaml");
-    println!("cargo:rerun-if-changed=cbindgen.toml")
+    println!("cargo:rerun-if-changed=cbindgen.toml");
+    println!("cargo:rerun-if-changed=include");
+}
+
+// See: https://github.com/rust-lang/cargo/issues/9661
+// See: https://github.com/rust-lang/cargo/issues/545
+fn cargo_target_dir() -> PathBuf {
+    let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR should be set"));
+    let profile = env::var("PROFILE").expect("PROFILE should be set");
+
+    let mut target_dir = None;
+    let mut out_dir_path = out_dir.as_path();
+    while let Some(parent) = out_dir_path.parent() {
+        if parent.ends_with(&profile) {
+            target_dir = Some(parent);
+            break;
+        }
+        out_dir_path = parent;
+    }
+
+    target_dir
+        .expect("OUT_DIR should be a child of a PROFILE directory")
+        .to_path_buf()
 }
 
 fn configure() {

From 644fc000c41870cc35725187867dfc0da5f7466c Mon Sep 17 00:00:00 2001
From: Mahmoud Mazouz <mazouz.mahmoud@outlook.com>
Date: Wed, 10 Apr 2024 18:51:26 +0200
Subject: [PATCH 2/3] fix: Use `NOT DEFINED` to check for undefined version
 tweak

---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58af3aca4..cb9000cf5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ declare_cache_var(ZENOHC_LIB_STATIC FALSE BOOL "Alias zenohc::lib target to zeno
 # Setup project version
 #
 set(project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
-if(NOT PROJECT_VERSION_TWEAK)
+if(NOT DEFINED PROJECT_VERSION_TWEAK)
 	set(project_version "${project_version}")
 elseif(PROJECT_VERSION_TWEAK EQUAL 0)
 	set(project_version "${project_version}-dev")

From fb45c005f6e90c43630c520e9d687651cb40c2cd Mon Sep 17 00:00:00 2001
From: Mahmoud Mazouz <mazouz.mahmoud@outlook.com>
Date: Wed, 10 Apr 2024 18:57:59 +0200
Subject: [PATCH 3/3] fix: Set `live-run` default in Release workflow

---
 .github/workflows/release.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 9451f6465..9c6418b0d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -43,7 +43,7 @@ jobs:
         uses: eclipse-zenoh/ci/create-release-branch@main
         with:
           repo: ${{ github.repository }}
-          live-run: ${{ inputs.live-run }}
+          live-run: ${{ inputs.live-run || false }}
           version: ${{ inputs.version }}
           github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}