Jump to page: 1 2 3
Thread overview
ImportC rocks!
Mar 12, 2022
Ki Rill
Mar 12, 2022
IGotD-
Mar 12, 2022
Ki Rill
Mar 12, 2022
Ki Rill
Mar 12, 2022
bachmeier
Mar 13, 2022
Tejas
Mar 13, 2022
rikki cattermole
Mar 13, 2022
StarCanopy
Mar 13, 2022
rikki cattermole
Mar 13, 2022
bachmeier
Mar 12, 2022
zjh
Mar 12, 2022
bachmeier
Mar 14, 2022
Walter Bright
Mar 14, 2022
Andrea Fontana
Mar 14, 2022
H. S. Teoh
Mar 14, 2022
Andrea Fontana
Mar 14, 2022
jmh530
Mar 15, 2022
Elronnd
Mar 15, 2022
Andrea Fontana
Mar 18, 2022
Walter Bright
Mar 18, 2022
JN
March 12, 2022

I tried using Raylib with importC, and I thought I should share my recent experience using it... Works like a charm! Worked from the first (second really) try!

What I did step by step (in case someone needs directions):

raylib.c:

#include "raylib.h"

main.d:

void main() {
    import raylib;

    InitWindow(640, 640, "ImportC raylib test");
    // game loop
    CloseWindow();
}

Compiling:

gcc -E raylib.c > raylib.i
dmd main.d raylib.c -L=-lraylib
./main

I really like the fact that dmd automatically picks up a name for the executable.

It was a pleasant experience using D when it actually 'just' works. There is still much to improve on ImportC, but I like that we slowly get there... when it's easily usable.

March 12, 2022

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

Compiling:

gcc -E raylib.c > raylib.i
dmd main.d raylib.c -L=-lraylib
./main

You run the preprocessor in gcc then call the output raylib.i but where is that file later used?

March 12, 2022

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

[...]

Thank you Walter and everyone else for adding importC to D.

When I first looked at it, I didn't think it's something I would use (there are many bindings I could just dub add after all), but after trying it out... it feels like I've been freed... no need for bindings or wrappers that someone needs to maintain and that may get outdated.

March 12, 2022

On Saturday, 12 March 2022 at 09:59:45 UTC, IGotD- wrote:

>

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

Compiling:

gcc -E raylib.c > raylib.i
dmd main.d raylib.c -L=-lraylib
./main

You run the preprocessor in gcc then call the output raylib.i but where is that file later used?

That was a typo. Should've been:

gcc -E raylib.c > raylib.i
dmd main.d raylib.i -L=-lraylib
./main

D does not have a C preprocessor. So we need to preprocess the C file ourselves before D can compile it.

March 12, 2022

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

I tried using Raylib with importC, and I thought I should share

Maybe D can import Rust,why not?

March 12, 2022

On Saturday, 12 March 2022 at 13:53:29 UTC, zjh wrote:

>

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

I tried using Raylib with importC, and I thought I should share

Maybe D can import Rust,why not?

If it's a Rust library that can be called from C, then yes, D can call it by compiling the C header using ImportC. If you mean compiling Rust code, that would have a low benefit/cost ratio.

March 12, 2022

On Saturday, 12 March 2022 at 10:03:28 UTC, Ki Rill wrote:

>

On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:

>

[...]

Thank you Walter and everyone else for adding importC to D.

When I first looked at it, I didn't think it's something I would use (there are many bindings I could just dub add after all), but after trying it out... it feels like I've been freed... no need for bindings or wrappers that someone needs to maintain and that may get outdated.

While there's more work that needs to be done, it'll be nice to be able to do things like add an sqlite dependency without needing the end user to mess around with sqlite. You can already do that by compiling the header with ImportC and using a C compiler to compile the library. I'm looking forward to the day I can add sqlite as a Dub dependency and let D compile everything.

March 13, 2022

On Saturday, 12 March 2022 at 15:26:02 UTC, bachmeier wrote:

>

On Saturday, 12 March 2022 at 10:03:28 UTC, Ki Rill wrote:

>

[...]

While there's more work that needs to be done, it'll be nice to be able to do things like add an sqlite dependency without needing the end user to mess around with sqlite. You can already do that by compiling the header with ImportC and using a C compiler to compile the library. I'm looking forward to the day I can add sqlite as a Dub dependency and let D compile everything.

What is wrong with using etc.c.sqlite3?
https://dlang.org/phobos/etc_c_sqlite3.html

March 13, 2022
That gets you the binding, not the actual library itself.

What bachmeier is looking forward to is having libraries like sqlite, zlib, lua and sljit to be copiled with the D compiler rather than having to supply binaries or hope its installed in the user system.

This way it'll "just work" without needing to worry about external dependencies.
March 13, 2022
And thus, perhaps compiling druntime along with a libc? After all, I hear that statically linking with glibc is quite difficult.
« First   ‹ Prev
1 2 3