digitalmars.D.learn - Interfacing with Rust
- Ruby The Roobster (4/4) Sep 29 2022 Is there any way one can interface with Rust, such as with a
- mw (5/9) Sep 29 2022 https://code.dlang.org/packages/rust_interop_d
- Ruby The Roobster (2/12) Sep 29 2022 This isn't the issue. I can't interface anything, period.
- Imperatorn (4/20) Sep 29 2022 Show an example of exactly what you're trying to do. Maybe it's
- Ruby The Roobster (51/72) Sep 30 2022 lib.rs:
- mw (7/7) Sep 30 2022 extern(C++)?
Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work.
Sep 29 2022
On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote:Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work.https://code.dlang.org/packages/rust_interop_d Read the notes on memory management: Only pass pointers as u64 as value type.
Sep 29 2022
On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote:On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote:This isn't the issue. I can't interface anything, period.Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work.https://code.dlang.org/packages/rust_interop_d Read the notes on memory management: Only pass pointers as u64 as value type.
Sep 29 2022
On Friday, 30 September 2022 at 00:18:42 UTC, Ruby The Roobster wrote:On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote:Show an example of exactly what you're trying to do. Maybe it's some detailOn Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote:This isn't the issue. I can't interface anything, period.Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work.https://code.dlang.org/packages/rust_interop_d Read the notes on memory management: Only pass pointers as u64 as value type.
Sep 29 2022
On Friday, 30 September 2022 at 06:25:33 UTC, Imperatorn wrote:On Friday, 30 September 2022 at 00:18:42 UTC, Ruby The Roobster wrote:lib.rs: ```rs struct Rectangle { width: u32, height: u32, } impl Rectangle { extern "cdecl" fn area(&self) -> u32 { self.width * self.height } extern "cdecl" fn can_hold(&self, other: &Rectangle) -> bool { self.width > other.width && self.height > other.height } } ``` main.d: ```d struct Rectangle { uint width; uint hight; extern(C++) uint area(); extern(C++) bool can_hold(Rectangle rhs) } void main() { auto rect1 = Rectangle(1,1); auto rect2 = Rectangle(0,0); assert(rect1.area == 1 && rect2.area == 0 && rect1.canHold(rect2)); } ``` lib.rs was built as a "staticlib" using rustc, and the command I used was: ldc2 -m64 main.d lib.lib The output: ``` main.obj : error LNK2019: unresolved external symbol "public: unsigned int __cdecl Rectangle::area(void)" (?area Rectangle QEAAIXZ) referenced in function _Dmain main.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Rectangle::can_hold(struct Rectangle)" (?can_hold Rectangle QEAA_NU1 Z) referenced in function _Dmain main.exe : fatal error LNK1120: 2 unresolved externals Error: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\link.exe failed with status: 1120 ``` Also, is it normal for the .lib file to be 11 megabytes?On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote:Show an example of exactly what you're trying to do. Maybe it's some detailOn Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote:This isn't the issue. I can't interface anything, period.Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work.https://code.dlang.org/packages/rust_interop_d Read the notes on memory management: Only pass pointers as u64 as value type.
Sep 30 2022
extern(C++)? Why do you think Rust export C++ linkage? And why do you think Rust export some kind of OO object model linkage? Do it in plain C style, you may make it work. As said, check how it's done in: https://code.dlang.org/packages/rust_interop_d
Sep 30 2022