Re: Interfacing with Rust

2022-09-30 Thread mw via Digitalmars-d-learn

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


Re: Interfacing with Rust

2022-09-30 Thread Ruby The Roobster via Digitalmars-d-learn

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:

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:
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.


This isn't the issue.  I can't interface anything, period.


Show an example of exactly what you're trying to do. Maybe it's 
some detail


lib.rs:

```rs
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}

impl Rectangle {
extern "cdecl" fn area() -> u32 {
self.width * self.height
}

extern "cdecl" fn can_hold(, other: ) -> 
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?


Re: Interfacing with Rust

2022-09-30 Thread Imperatorn via Digitalmars-d-learn
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:
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.


This isn't the issue.  I can't interface anything, period.


Show an example of exactly what you're trying to do. Maybe it's 
some detail


Re: Interfacing with Rust

2022-09-29 Thread Ruby The Roobster via Digitalmars-d-learn

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:
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.


This isn't the issue.  I can't interface anything, period.


Re: Interfacing with Rust

2022-09-29 Thread mw via Digitalmars-d-learn
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.




Interfacing with Rust

2022-09-29 Thread Ruby The Roobster via Digitalmars-d-learn
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.