Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNative C++ FFI in the same manner as D #5853
Comments
This comment has been minimized.
This comment has been minimized.
|
Here's a resource describing the level to which D can interface with C++: |
This comment has been minimized.
This comment has been minimized.
asb
commented
Apr 19, 2013
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Still very relevant |
This comment has been minimized.
This comment has been minimized.
|
just a bug, removing milestone/nomination. |
This comment has been minimized.
This comment has been minimized.
|
Visiting for triage. Nothing to add. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
On Maybe |
This comment has been minimized.
This comment has been minimized.
|
visiting for triage. Nothing to add here. |
This comment has been minimized.
This comment has been minimized.
|
I started to think we don't need language-level support for C++ FFI. For name mangling we can just use |
This comment has been minimized.
This comment has been minimized.
nathansobo
commented
Jun 28, 2014
|
I would love to use Rust to write V8 extensions, and a direct C++ interface could make that a good experience. |
This comment has been minimized.
This comment has been minimized.
|
Nominating for P-high. I imagine this is going to be pretty important for driving adoption. |
cmr
added
the
I-nominated
label
Jun 28, 2014
This comment has been minimized.
This comment has been minimized.
jacobsantos
commented
Jun 30, 2014
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Assigning P-low, not 1.0 milestone. |
pnkfelix
added
P-low
and removed
I-nominated
labels
Jul 3, 2014
This comment has been minimized.
This comment has been minimized.
|
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 |
bstrie commentedApr 12, 2013
@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