-
Notifications
You must be signed in to change notification settings - Fork 365
Bug in cxxbridge-cmd? Generated incorrect namespace #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This looks like #416. Sorry, this was not intentional. :( For now you can work around it by writing #[cxx::bridge]
mod ffi {
extern "C++" {
type Person;
}
#[namespace = "rust_part"]
extern "C++" {
fn get_name(person: &Person) -> &CxxString;
}
} or like this: #[cxx::bridge]
mod ffi {
extern "C++" {
type Person;
#[namespace = "rust_part"]
fn get_name(person: &Person) -> &CxxString;
}
} |
Thanks for the reply! But this doesn't work: #[cxx::bridge]
mod ffi {
#[namespace = "rust_part"]
extern "Rust"{
fn hello();
}
}
fn hello() {
println!("hello");
} --> #pragma once
void hello() noexcept; I can only specify namespace on the function/type not the entire extern block, is that intended? |
Great! Thanks for the support! |
Published 0.5.8: $ cxxbridge --version
cxxbridge 0.5.8
$ echo '#[cxx::bridge] mod ffi { #[namespace = "rust_part"] extern "Rust" { fn hello(); } }' | cxxbridge --header -
#pragma once
namespace rust_part {
void hello() noexcept;
} // namespace rust_part |
How do you consider this case: #[cxx::bridge]
mod ffi {
#[namespace = "shared"]
struct Color {
r: u8,
g: u8,
b: u8
}
#[namespace = "rust_part"]
extern "Rust"{
fn is_white(self: &Color) -> bool;
}
} Note that the Color is in Probably it's better to just reject the code, but I haven't got a chance to look at the implementation. |
Looks like we currently generated something like the following, which does not compile. Good catch. namespace shared {
struct Color final {
uint8_t r;
uint8_t g;
uint8_t b;
bool is_white() const noexcept;
};
} // namespace shared
namespace rust_part {
bool Color::is_white() const noexcept {
...
}
} // namespace rust_part cxxbridge/sources/demo/src/main.rs.cc:25:6: error: ‘Color’ has not been declared
25 | bool Color::is_white() const noexcept {
| ^~~~~ I wouldn't be opposed to accepting that code and just making it put the member function in the struct's namespace all the time, regardless of namespace attribute on the member function. But if someone feels strongly this should be an error (with a better message), that would be reasonable too. |
I filed #460 to track the bug described in #441 (comment) of method with a different explicit namespace than the receiver type. |
Hi, I encountered this after upgrading the cxxbridge-cmd to 0.5.6:
Run cxxbridge:
And get the header:
and source:
I suppose the
Person
should not be inrust_part
namespace, in fact (at least) in 0.5.2 it yields the following code and compiles for me.Am I missing something? This also relates to the problem discussed #434
The text was updated successfully, but these errors were encountered: