Allow .rs.h extension when including generated header
diff --git a/demo-cxx/demo.cc b/demo-cxx/demo.cc
index 04287b8..cd447ea 100644
--- a/demo-cxx/demo.cc
+++ b/demo-cxx/demo.cc
@@ -1,5 +1,5 @@
#include "demo-cxx/demo.h"
-#include "demo-rs/src/main.rs"
+#include "demo-rs/src/main.rs.h"
#include <iostream>
namespace org {
diff --git a/demo-rs/BUCK b/demo-rs/BUCK
index eac4182..d4164d3 100644
--- a/demo-rs/BUCK
+++ b/demo-rs/BUCK
@@ -36,7 +36,7 @@
cxx_library(
name = "include",
exported_headers = {
- "src/main.rs": ":gen-header",
+ "src/main.rs.h": ":gen-header",
},
visibility = ["PUBLIC"],
)
diff --git a/demo-rs/BUILD b/demo-rs/BUILD
index f703be3..e3ebb96 100644
--- a/demo-rs/BUILD
+++ b/demo-rs/BUILD
@@ -22,7 +22,7 @@
genrule(
name = "gen-header",
srcs = ["src/main.rs"],
- outs = ["main.rs"],
+ outs = ["main.rs.h"],
cmd = "$(location //:codegen) --header $< > $@",
tools = ["//:codegen"],
)
diff --git a/src/paths.rs b/src/paths.rs
index e318664..62fbb6e 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -22,21 +22,28 @@
}
// Symlink the header file into a predictable place. The header generated from
-// path/to/mod.rs gets linked to targets/cxxbridge/path/to/mod.h.
+// path/to/mod.rs gets linked to targets/cxxbridge/path/to/mod.rs.h.
pub(crate) fn symlink_header(path: &Path, original: &Path) {
let _ = try_symlink_header(path, original);
}
fn try_symlink_header(path: &Path, original: &Path) -> Result<()> {
+ #[cfg(unix)]
+ use os::unix::fs::symlink;
+ #[cfg(windows)]
+ use os::windows::fs::symlink_file as symlink;
+
let suffix = relative_to_parent_of_target_dir(original)?;
let ref dst = include_dir()?.join(suffix);
fs::create_dir_all(dst.parent().unwrap())?;
let _ = fs::remove_file(dst);
- #[cfg(unix)]
- os::unix::fs::symlink(path, dst)?;
- #[cfg(windows)]
- os::windows::fs::symlink_file(path, dst)?;
+ symlink(path, dst)?;
+
+ let mut file_name = dst.file_name().unwrap().to_os_string();
+ file_name.push(".h");
+ let dst2 = dst.with_file_name(file_name);
+ symlink(path, dst2)?;
Ok(())
}
diff --git a/tests/BUCK b/tests/BUCK
index b488c90..659223c 100644
--- a/tests/BUCK
+++ b/tests/BUCK
@@ -21,7 +21,7 @@
":gen-source",
],
headers = {
- "ffi/lib.rs": ":gen-header",
+ "ffi/lib.rs.h": ":gen-header",
"ffi/tests.h": "ffi/tests.h",
},
deps = ["//:core"],
diff --git a/tests/BUILD b/tests/BUILD
index ef6477f..65c5b41 100644
--- a/tests/BUILD
+++ b/tests/BUILD
@@ -31,7 +31,7 @@
genrule(
name = "gen-header",
srcs = ["ffi/lib.rs"],
- outs = ["lib.rs"],
+ outs = ["lib.rs.h"],
cmd = "$(location //:codegen) --header $< > $@",
tools = ["//:codegen"],
)
diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc
index 4f36f9b..184e8aa 100644
--- a/tests/ffi/tests.cc
+++ b/tests/ffi/tests.cc
@@ -1,5 +1,5 @@
#include "tests/ffi/tests.h"
-#include "tests/ffi/lib.rs"
+#include "tests/ffi/lib.rs.h"
#include <cstring>
#include <stdexcept>