-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Native C++ FFI in the same manner as D #5853
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Here's a resource describing the level to which D can interface with C++: |
It's worth taking a look at what the Julia community have been working on with C++ support via Clang.jl JuliaInterop/Clang.jl#20 |
Still very relevant |
just a bug, removing milestone/nomination. |
Visiting for triage. Nothing to add. |
Taking examples from D FFI doc, int foo(int i, int j, int k); can be expressed in Rust as extern "C++" {
fn foo(i: c_int, j: c_int, k: c_int) -> c_int;
} This is straightforward; I've locally tuned rustc with tiny proof-of-concept mangler and it worked successfully. However, if C++ code is in some namespace e.g. namespace A {
namespace B {
int foo(int i, int j, int k);
}
} then we need to specify namespace in Rust since mangled function name contains it (at least on linux). One way to achieve that is: #[namespace = "A::B"]
extern "C++" {
fn foo(i: c_int, j: c_int, k: c_int) -> c_int;
} I didn't tried to implement it, but it is still not hard; the only stuff I have to do is name mangling. Classes and methods are more challenging: we need discussion on syntax. Again from D example, class D {
public:
virtual int bar(int i, int j, int k);
}
D *getD(); How this can be expressed in Rust? I've initially thought: extern "C++" {
trait D {
fn bar(i: c_int, j: c_int, k: c_int) -> c_int;
}
} but |
For example: class S {
int x;
virtual void foo();
void bar();
}
class T : public S {
int y;
void baz();
}
void process(S* arg);
S* getS(); could be expressed as: extern "C++" {
#[class = "S"]
struct Simpl { x: int, }
#[class = "S"]
trait Stable {
fn foo(*self),
}
impl Simpl { fn bar(*self); }
impl Stable for Simpl { fn foo(*self); }
#[class = "T"]
struct Timpl { super_: Simpl, y: int, }
impl Stable for Timpl { fn foo(*self); }
impl Timpl { fn baz(*self); }
fn process<S:Stable>(arg: *S);
fn getS() -> *Simpl;
} (one could imagine rearranging the above a bit, pulling the |
On Maybe |
visiting for triage. Nothing to add here. |
I started to think we don't need language-level support for C++ FFI. For name mangling we can just use |
I would love to use Rust to write V8 extensions, and a direct C++ interface could make that a good experience. |
Nominating for P-high. I imagine this is going to be pretty important for driving adoption. |
I would jump balls in if this had native C++ support. Although, it might be difficult kissing Golang goodbye for some things. I am disappointed in Golang's C support however. Not much to be done given how concurrency is handled between the languages. |
Assigning P-low, not 1.0 milestone. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#602 |
Rustup r? @ghost changelog: none
@sanxiyn and @jdm have expressed interest in doing this, possibly in the 0.8 cycle.
http://www.reddit.com/r/rust/comments/1c3clf/c_ffi/c9codm1
The text was updated successfully, but these errors were encountered: