Skip to content

Commit 8a60085

Browse files
committed
Encode patch-version in the prefix of cxx-generated symbols.
Fixes #1507
1 parent e81ef78 commit 8a60085

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

syntax/mangle.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@
7676
use crate::syntax::symbol::{self, Symbol};
7777
use crate::syntax::{ExternFn, Pair, Types};
7878

79-
const CXXBRIDGE: &str = "cxxbridge1";
79+
// Ignoring `CARGO_PKG_VERSION_MAJOR` and `...MINOR`, because they don't agree across
80+
// all the crates. For example `gen/lib/Cargo.toml` says `version = "0.7.xxx"`, but
81+
// `macro/Cargo.toml` says `version = "1.0.xxx"`.
82+
const CXXBRIDGE: &'static str = concat!("cxxbridge1_", env!("CARGO_PKG_VERSION_PATCH"));
8083

8184
macro_rules! join {
8285
($($segment:expr),+ $(,)?) => {

tests/cxx_gen.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn test_extern_c_function() {
1818
let output = str::from_utf8(&generated.implementation).unwrap();
1919
// To avoid continual breakage we won't test every byte.
2020
// Let's look for the major features.
21-
assert!(output.contains("void cxxbridge1$do_cpp_thing(::rust::Str foo)"));
21+
assert!(output.contains(&format!("void {CXXBRIDGE}$do_cpp_thing(::rust::Str foo)")));
2222
}
2323

2424
#[test]
@@ -28,9 +28,13 @@ fn test_impl_annotation() {
2828
let source = BRIDGE0.parse().unwrap();
2929
let generated = generate_header_and_cc(source, &opt).unwrap();
3030
let output = str::from_utf8(&generated.implementation).unwrap();
31-
assert!(output.contains("ANNOTATION void cxxbridge1$do_cpp_thing(::rust::Str foo)"));
31+
assert!(output.contains(&format!(
32+
"ANNOTATION void {CXXBRIDGE}$do_cpp_thing(::rust::Str foo)"
33+
)));
3234
}
3335

36+
const CXXBRIDGE: &'static str = concat!("cxxbridge1_", env!("CARGO_PKG_VERSION_PATCH"));
37+
3438
const BRIDGE1: &str = r#"
3539
#[cxx::bridge]
3640
mod ffi {
@@ -66,10 +70,13 @@ fn test_extern_rust_method_on_c_type() {
6670
assert!(!header.contains("rust_method_cpp_receiver"));
6771

6872
// Check that there is a generated C signature bridging to the Rust method.
69-
assert!(implementation
70-
.contains("void cxxbridge1$CppType$rust_method_cpp_receiver(::CppType &self) noexcept;"));
73+
assert!(implementation.contains(&format!(
74+
"void {CXXBRIDGE}$CppType$rust_method_cpp_receiver(::CppType &self) noexcept;"
75+
)));
7176

7277
// Check that there is an implementation on the C++ class calling the Rust method.
7378
assert!(implementation.contains("void CppType::rust_method_cpp_receiver() noexcept {"));
74-
assert!(implementation.contains("cxxbridge1$CppType$rust_method_cpp_receiver(*this);"));
79+
assert!(implementation.contains(&format!(
80+
"{CXXBRIDGE}$CppType$rust_method_cpp_receiver(*this);"
81+
)));
7582
}

0 commit comments

Comments
 (0)