Switch the function example to use non-extern-C functions.
Previously non-extern-C functions were not supported. Now they are! And even with namespaces!
PiperOrigin-RevId: 663493690
Change-Id: Icc49f137a20005b2399915bd749edefbcb27aa0c
diff --git a/examples/cpp/function/example.h b/examples/cpp/function/example.h
index 0421b4f..a37856c 100644
--- a/examples/cpp/function/example.h
+++ b/examples/cpp/function/example.h
@@ -7,11 +7,10 @@
#include <stdint.h>
-// Crubit only supports extern C functions right now. As a consequence, the
-// functions need a unique name. (Including the namespace name in the symbol,
-// e.g., `gshoe`, below, is one approach to this.)
-extern "C" {
-inline int32_t gshoe_add_two_integers(int32_t x, int32_t y) { return x + y; }
-}
+namespace ghoe {
+
+inline int32_t add_two_integers(int32_t x, int32_t y) { return x + y; }
+
+} // namespace ghoe
#endif // THIRD_PARTY_CRUBIT_EXAMPLES_CPP_FUNCTION_EXAMPLE_H_
diff --git a/examples/cpp/function/example_generated.rs b/examples/cpp/function/example_generated.rs
index 0f79193..46c7798 100644
--- a/examples/cpp/function/example_generated.rs
+++ b/examples/cpp/function/example_generated.rs
@@ -15,20 +15,20 @@
#![allow(dead_code)]
#![deny(warnings)]
-// Crubit only supports extern C functions right now. As a consequence, the
-// functions need a unique name. (Including the namespace name in the symbol,
-// e.g., `gshoe`, below, is one approach to this.)
-
-/// Generated from: examples/cpp/function/example.h;l=14
-#[inline(always)]
-pub fn gshoe_add_two_integers(x: i32, y: i32) -> i32 {
- unsafe { crate::detail::__rust_thunk__gshoe_add_two_integers(x, y) }
+pub mod ghoe {
+ /// Generated from: examples/cpp/function/example.h;l=12
+ #[inline(always)]
+ pub fn add_two_integers(x: i32, y: i32) -> i32 {
+ unsafe { crate::detail::__rust_thunk___ZN4ghoe16add_two_integersEii(x, y) }
+ }
}
+// namespace ghoe
+
mod detail {
#[allow(unused_imports)]
use super::*;
extern "C" {
- pub(crate) fn __rust_thunk__gshoe_add_two_integers(x: i32, y: i32) -> i32;
+ pub(crate) fn __rust_thunk___ZN4ghoe16add_two_integersEii(x: i32, y: i32) -> i32;
}
}
diff --git a/examples/cpp/function/main.rs b/examples/cpp/function/main.rs
index 9054109..d55c91c 100644
--- a/examples/cpp/function/main.rs
+++ b/examples/cpp/function/main.rs
@@ -3,6 +3,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
fn main() {
- let sum = example_lib::gshoe_add_two_integers(2, 2);
+ let sum = example_lib::ghoe::add_two_integers(2, 2);
println!("sum = {sum}");
}