PragmaTwice commented on code in PR #5195:
URL: https://github.com/apache/opendal/pull/5195#discussion_r1804477115


##########
bindings/cpp/build.rs:
##########
@@ -15,8 +15,56 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::{
+    env::var,
+    io,
+    path::{Path, PathBuf},
+};
+
+#[cfg(unix)]
+fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> 
io::Result<()> {
+    std::os::unix::fs::symlink(original, link)
+}
+
+#[cfg(target_os = "windows")]
+fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> 
io::Result<()> {
+    std::os::windows::fs::symlink_file(original, link)
+}
+
+fn symlink_force<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> 
io::Result<()> {
+    if link.as_ref().exists() {
+        return std::fs::remove_file(link);
+    }
+
+    symlink(original, link)
+}
+
+fn print_to_cargo() {
+    println!("cargo:rerun-if-changed=src/lib.rs");
+    #[cfg(feature = "async")]
+    println!("cargo:rerun-if-changed=src/async.rs");
+}
+
+fn symlink_async_includes() {
+    let async_inc = var("DEP_CXX_ASYNC_INCLUDE").unwrap();
+    let src_dir = PathBuf::from(async_inc).join("rust");
+
+    let prj_dir = var("CARGO_MANIFEST_DIR").unwrap();
+    let dst_dir = PathBuf::from(prj_dir)
+        .join("target")
+        .join("cxxbridge")
+        .join("rust");
+
+    symlink_force(src_dir.join("cxx_async.h"), 
dst_dir.join("cxx_async.h")).unwrap();
+}
+
 fn main() {
     let _ = cxx_build::bridge("src/lib.rs");
+    #[cfg(feature = "async")]
+    {
+        let _ = cxx_build::bridge("src/async.rs");
+        symlink_async_includes();
+    }
 
-    println!("cargo:rerun-if-changed=src/lib.rs");
+    print_to_cargo()

Review Comment:
   Yeah I'll remove it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to