Fix hardcoded thunk names in tests (broken by recent RustC roll).
Today rust symbols depend on rustc version so even though
`SymbolManglingVersion::V0` (used in unit tests) guarantees ["consistent
results across
compilations"][]
it doesn't guarantee stable across different compiler versions :-(
The fix a bit hasty and haphazardous to make the CI green again:
- Maybe the unit tests should do _some_ verification instead of just
using `...` in `assert_cc_matches`?
- The `cc_bindings_from_rs.rs` changes just kick the can down the road.
The changes will be green for now but will likely get broken by the
next RustC roll. I am experimenting with regex-based checks in a
separate CL which needs a bit more time to complete.
PiperOrigin-RevId: 492333432
diff --git a/cc_bindings_from_rs/bindings.rs b/cc_bindings_from_rs/bindings.rs
index dd58d6d..492c7c1 100644
--- a/cc_bindings_from_rs/bindings.rs
+++ b/cc_bindings_from_rs/bindings.rs
@@ -1375,15 +1375,14 @@
// is translated into a `consteval` C++ function.
let result = result.expect("Test expects success here");
assert!(!result.cc.includes.is_empty());
- let thunk_name = quote!{ __crubit_thunk__RNvCsgl0yn9Ytt4z_8rust_out3foo };
assert_cc_matches!(
result.cc.snippet,
quote! {
namespace __crubit_internal {
- extern "C" std::int32_t #thunk_name( std::int32_t i);
+ extern "C" std::int32_t ...( std::int32_t i);
}
inline std::int32_t foo(std::int32_t i) {
- return __crubit_internal::#thunk_name(i);
+ return __crubit_internal::...(i);
}
}
);
@@ -1392,7 +1391,7 @@
quote! {
#[no_mangle]
extern "C"
- fn #thunk_name(i: i32) -> i32 {
+ fn ...(i: i32) -> i32 {
::rust_out::foo(i)
}
}
@@ -1658,15 +1657,14 @@
test_format_def(test_src, "add", |result| {
let result = result.expect("Test expects success here");
assert!(result.cc.includes.is_empty());
- let thunk_name = quote! { __crubit_thunk__RNvCsgl0yn9Ytt4z_8rust_out3add };
assert_cc_matches!(
result.cc.snippet,
quote! {
namespace __crubit_internal {
- extern "C" double #thunk_name(double x, double y);
+ extern "C" double ...(double x, double y);
}
inline double add(double x, double y) {
- return __crubit_internal::#thunk_name(x, y);
+ return __crubit_internal::...(x, y);
}
}
);
@@ -1675,7 +1673,7 @@
quote! {
#[no_mangle]
extern "C"
- fn #thunk_name(x: f64, y: f64) -> f64 {
+ fn ...(x: f64, y: f64) -> f64 {
::rust_out::add(x, y)
}
}
@@ -1706,15 +1704,14 @@
test_format_def(test_src, "add", |result| {
let result = result.expect("Test expects success here");
assert!(result.cc.includes.is_empty());
- let thunk_name = quote! { __crubit_thunk__RNvCsgl0yn9Ytt4z_8rust_out3add };
assert_cc_matches!(
result.cc.snippet,
quote! {
namespace __crubit_internal {
- extern "C" double #thunk_name(double x, double y);
+ extern "C" double ...(double x, double y);
}
inline double add(double x, double y) {
- return __crubit_internal::#thunk_name(x, y);
+ return __crubit_internal::...(x, y);
}
}
);
@@ -1723,7 +1720,7 @@
quote! {
#[no_mangle]
extern "C"
- fn #thunk_name(x: f64, y: f64) -> f64 {
+ fn ...(x: f64, y: f64) -> f64 {
::rust_out::add(x, y)
}
}
diff --git a/cc_bindings_from_rs/cc_bindings_from_rs.rs b/cc_bindings_from_rs/cc_bindings_from_rs.rs
index b878a34..ee60f3d 100644
--- a/cc_bindings_from_rs/cc_bindings_from_rs.rs
+++ b/cc_bindings_from_rs/cc_bindings_from_rs.rs
@@ -360,12 +360,11 @@
namespace test_crate {
namespace __crubit_internal {
-extern "C" void
-__crubit_thunk__RNvCslKXfKXPWofF_10test_crate15public_function();
+extern "C" void __crubit_thunk__RNvCsqz8GFuO9cP_10test_crate15public_function();
}
inline void public_function() {
return __crubit_internal::
- __crubit_thunk__RNvCslKXfKXPWofF_10test_crate15public_function();
+ __crubit_thunk__RNvCsqz8GFuO9cP_10test_crate15public_function();
}
} // namespace test_crate"#
);
@@ -380,7 +379,7 @@
#![allow(improper_ctypes_definitions)]
#[no_mangle]
-extern "C" fn __crubit_thunk__RNvCslKXfKXPWofF_10test_crate15public_function() -> () {
+extern "C" fn __crubit_thunk__RNvCsqz8GFuO9cP_10test_crate15public_function() -> () {
::test_crate::public_function()
}
"#