diff --git a/examples/cxx_demo/build.rs b/examples/cxx_demo/build.rs index 5244e4d..596af43 100644 --- a/examples/cxx_demo/build.rs +++ b/examples/cxx_demo/build.rs @@ -14,13 +14,10 @@ fn main() { .with_rs_file(crate_dir.join("./src/generated.rs")) .generate(); - cc::Build::new() - .cpp(true) - .file("generated.cpp") - .compile("zngur_generated"); + let my_build = &mut cc::Build::new(); + let my_build = my_build.cpp(true).compiler("clang++"); + let my_build = || my_build.clone(); - cc::Build::new() - .cpp(true) - .file("blobstore.cpp") - .compile("blobstore"); + my_build().file("generated.cpp").compile("zngur_generated"); + my_build().file("blobstore.cpp").compile("blobstore"); } diff --git a/examples/osmium/generated.h b/examples/osmium/generated.h index 46bf912..2a2879a 100644 --- a/examples/osmium/generated.h +++ b/examples/osmium/generated.h @@ -47,20 +47,9 @@ namespace rust { template struct Ref; - template - uint8_t* __zngur_internal_data_ptr(::rust::Ref& t) { - return (uint8_t*)&t.data; - } - - template - void __zngur_internal_assume_init(::rust::Ref&) {} - template void zngur_pretty_print(T&) {} - template - void __zngur_internal_assume_deinit(::rust::Ref&) {} - template class Impl; @@ -103,8 +92,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -147,8 +135,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -191,8 +178,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -235,8 +221,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -279,8 +264,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -323,8 +307,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -367,8 +350,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; @@ -411,8 +393,7 @@ namespace rust { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref& t); }; } @@ -500,13 +481,30 @@ struct rust::Ref<::rust::Unit> { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr<::rust::Ref<::rust::Unit>>(::rust::Ref<::rust::Unit>& t); public: }; namespace rust { + +template<> +inline uint8_t* __zngur_internal_data_ptr>(Ref<::rust::Unit>& t) { + return (uint8_t*)&t.data; +} + +template<> +inline void __zngur_internal_assume_init>(Ref<::rust::Unit>&) { +} + +template<> +inline void __zngur_internal_check_init>(Ref<::rust::Unit>&) { +} + +template<> +inline void __zngur_internal_assume_deinit>(Ref<::rust::Unit>&) { +} + template<> inline size_t __zngur_internal_size_of>() { return 8; @@ -605,13 +603,30 @@ struct rust::Ref<::rust::crate::Reader> { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr<::rust::Ref<::rust::crate::Reader>>(::rust::Ref<::rust::crate::Reader>& t); public: }; namespace rust { + +template<> +inline uint8_t* __zngur_internal_data_ptr>(Ref<::rust::crate::Reader>& t) { + return (uint8_t*)&t.data; +} + +template<> +inline void __zngur_internal_assume_init>(Ref<::rust::crate::Reader>&) { +} + +template<> +inline void __zngur_internal_check_init>(Ref<::rust::crate::Reader>&) { +} + +template<> +inline void __zngur_internal_assume_deinit>(Ref<::rust::crate::Reader>&) { +} + template<> inline size_t __zngur_internal_size_of>() { return 8; @@ -712,14 +727,31 @@ struct rust::Ref<::rust::crate::Flags> { } private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr<::rust::Ref<::rust::crate::Flags>>(::rust::Ref<::rust::crate::Flags>& t); public: ::uint8_t bits(); }; namespace rust { + +template<> +inline uint8_t* __zngur_internal_data_ptr>(Ref<::rust::crate::Flags>& t) { + return (uint8_t*)&t.data; +} + +template<> +inline void __zngur_internal_assume_init>(Ref<::rust::crate::Flags>&) { +} + +template<> +inline void __zngur_internal_check_init>(Ref<::rust::crate::Flags>&) { +} + +template<> +inline void __zngur_internal_assume_deinit>(Ref<::rust::crate::Flags>&) { +} + template<> inline size_t __zngur_internal_size_of>() { return 8; diff --git a/examples/osmium/src/main.rs b/examples/osmium/src/main.rs index a19dcf9..928bd80 100644 --- a/examples/osmium/src/main.rs +++ b/examples/osmium/src/main.rs @@ -21,6 +21,6 @@ bitflags! { fn main() { let f = Flags::way | Flags::node; - let reader = generated::new_blob_store_client(f); + let _reader = generated::new_blob_store_client(f); println!("Hello, world! {}", f.bits()); } diff --git a/zngur-generator/src/cpp.rs b/zngur-generator/src/cpp.rs index 023ef07..22f2d78 100644 --- a/zngur-generator/src/cpp.rs +++ b/zngur-generator/src/cpp.rs @@ -371,8 +371,7 @@ struct rust::Ref<{ty}> {{ }} private: ::std::array data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr<::rust::Ref<{ty}>>(::rust::Ref<{ty}>& t); "#, ty = self.ty, )?; @@ -390,8 +389,7 @@ struct rust::Ref<{ty}> {{ }} private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr<::rust::Ref<{ty}>>(::rust::Ref<{ty}>& t); "#, ty = self.ty, )?; @@ -422,6 +420,24 @@ private: state, r#" namespace rust {{ + +template<> +inline uint8_t* __zngur_internal_data_ptr>(Ref<{ty}>& t) {{ + return (uint8_t*)&t.data; +}} + +template<> +inline void __zngur_internal_assume_init>(Ref<{ty}>&) {{ +}} + +template<> +inline void __zngur_internal_check_init>(Ref<{ty}>&) {{ +}} + +template<> +inline void __zngur_internal_assume_deinit>(Ref<{ty}>&) {{ +}} + template<> inline size_t __zngur_internal_size_of>() {{ return {size}; @@ -697,7 +713,7 @@ namespace rust {{ }} "#, size = self.size, - ); + )?; if self.is_copy { writeln!( state, @@ -749,7 +765,7 @@ namespace rust {{ }} }} "#, - ); + )?; } self.emit_ref_specialization(state) } @@ -941,20 +957,9 @@ namespace rust { template struct Ref; - template - uint8_t* __zngur_internal_data_ptr(::rust::Ref& t) { - return (uint8_t*)&t.data; - } - - template - void __zngur_internal_assume_init(::rust::Ref&) {} - template void zngur_pretty_print(T&) {} - template - void __zngur_internal_assume_deinit(::rust::Ref&) {} - template class Impl; "#; @@ -1004,8 +1009,7 @@ namespace rust { }} private: size_t data; - template - friend uint8_t* ::rust::__zngur_internal_data_ptr(::rust::Ref& t); + friend uint8_t* ::rust::__zngur_internal_data_ptr>(::rust::Ref<{ty}>& t); }}; "# )?;