Re: How to use ImportC to import WebGPU header
On Friday, 12 January 2024 at 11:06:39 UTC, Bkoie wrote: On Thursday, 11 January 2024 at 15:18:08 UTC, Sergey wrote: On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote: I would like to use ImportC to automatically import a C header into my D project. It was already done. Use it https://code.dlang.org/packages/wgpu-d Don't reinvent the wheel :) or if you push a package atleast document the code or give example D is not like rust where you can just dive into a lib without docs or example Not my package, but I see it has several separate sub-repos for examples: This package provides sub packages which can be used individually: wgpu-d:enumerate - Enumerate GPU adapters example wgpu-d:headless - Headless (windowless) rendering example wgpu-d:triangle - Triangle (windowed) example wgpu-d:cube - Cube (windowed) example
Re: How to use ImportC to import WebGPU header
On Thursday, 11 January 2024 at 15:18:08 UTC, Sergey wrote: On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote: I would like to use ImportC to automatically import a C header into my D project. It was already done. Use it https://code.dlang.org/packages/wgpu-d Don't reinvent the wheel :) or if you push a package atleast document the code or give example D is not like rust where you can just dive into a lib without docs or example
Re: How to use ImportC to import WebGPU header
You need to use a .c file that include it --- webgpu.c ```c #include "webgpu.h" ``` --- app.d ```d import std.stdio; import webgpu; void main() { writeln(WGPUBlendFactor_Dst); } ``` result: ``` $ dmd -run app.d webgpu.c WGPUBlendFactor_Dst ```
Re: How to use ImportC to import WebGPU header
On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote: I would like to use ImportC to automatically import a C header into my D project. It was already done. Use it https://code.dlang.org/packages/wgpu-d Don't reinvent the wheel :)
How to use ImportC to import WebGPU header
I would like to use ImportC to automatically import a C header into my D project. I've been using Dstep so far which works ok, but requires some manual fixes to get the resulting D file to compare and it doesn't let me to just drop the C header file. I created a fresh dub project to try. I try to import this header https://github.com/webgpu-native/webgpu-headers/blob/main/webgpu.h . I put webgpu.h file next to app.d. My code is: ``` import std.stdio; import webgpu; void main() { } ``` it builds. Then I tried to output one of the enums to see if it works: ``` import std.stdio; import webgpu; void main() { writeln(WGPUBlendFactor_Dst); } ``` and it says: Starting Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. Building test_importd ~master: building configuration [application] source\app.d(6,10): Error: undefined identifier `WGPUBlendFactor_Dst` Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. I tried to do the other commandline but I get this error instead: C:\Users\haxx\Desktop\dev\test_importd\source>dmd -c webgpu.c -Hf=webgpu.di C:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h(134): fatal error C1034: sal.h: no include path set Error: C preprocess command C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe failed for file webgpu.c, exit status 2
Re: How to use ImportC?
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote: On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1. Thank you all. In v2.099.0 it works.
Re: How to use ImportC?
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo@leonardo-pc dimportc]$ ls ... /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ``` LDC works with DMD fronted the same version v2.098.1 LDC - the LLVM D compiler (1.28.1): based on DMD v2.098.1 and LLVM 13.0.1
Re: How to use ImportC?
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote: On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1. Just had a chance to try this. Works with the beta.
Re: How to use ImportC?
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1.
Re: How to use ImportC?
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo@leonardo-pc dimportc]$ ls foo.c program.d [leonardo@leonardo-pc dimportc]$ cat foo.c double twice(double x) { return 2.0*x; } [leonardo@leonardo-pc dimportc]$ cat program.d import foo; import std.stdio; void main() { writeln(twice(6.8)); } [leonardo@leonardo-pc dimportc]$ dmd program.d foo.c /usr/include/dlang/dmd/core/stdc/stdio.d(1256): Error: function `core.stdc.stdio.vfprintf` `pragma(printf)` functions must be `extern(C) int vfprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1259): Error: function `core.stdc.stdio.vfscanf` `pragma(scanf)` functions must be `extern(C) int vfscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1262): Error: function `core.stdc.stdio.vsprintf` `pragma(printf)` functions must be `extern(C) int vsprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1265): Error: function `core.stdc.stdio.vsscanf` `pragma(scanf)` functions must be `extern(C) int vsscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1268): Error: function `core.stdc.stdio.vprintf` `pragma(printf)` functions must be `extern(C) int vprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1271): Error: function `core.stdc.stdio.vscanf` `pragma(scanf)` functions must be `extern(C) int vscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ``` They must have introduced a bug. Works for me with DMD 2.098.0 and LDC 1.28.0. ImportC is under heavy development right now. Most of the 2.098.1 changelog was related to ImportC.
Re: How to use ImportC?
Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo@leonardo-pc dimportc]$ ls foo.c program.d [leonardo@leonardo-pc dimportc]$ cat foo.c double twice(double x) { return 2.0*x; } [leonardo@leonardo-pc dimportc]$ cat program.d import foo; import std.stdio; void main() { writeln(twice(6.8)); } [leonardo@leonardo-pc dimportc]$ dmd program.d foo.c /usr/include/dlang/dmd/core/stdc/stdio.d(1256): Error: function `core.stdc.stdio.vfprintf` `pragma(printf)` functions must be `extern(C) int vfprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1259): Error: function `core.stdc.stdio.vfscanf` `pragma(scanf)` functions must be `extern(C) int vfscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1262): Error: function `core.stdc.stdio.vsprintf` `pragma(printf)` functions must be `extern(C) int vsprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1265): Error: function `core.stdc.stdio.vsscanf` `pragma(scanf)` functions must be `extern(C) int vsscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1268): Error: function `core.stdc.stdio.vprintf` `pragma(printf)` functions must be `extern(C) int vprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1271): Error: function `core.stdc.stdio.vscanf` `pragma(scanf)` functions must be `extern(C) int vscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ```
Re: How to use ImportC?
On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote: I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC? You just add the C files like D files when you compile and import them in your D code as you would a D module. At least that is all I've been doing. Simple example: foo.c: ``` double twice(double x) { return 2.0*x; } ``` program.d: ``` import foo; import std.stdio; void main() { writeln(twice(6.8)); } ``` Compilation: ``` dmd program.d foo.c ```
Re: How to use ImportC?
On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote: I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC? I think you nailed it... with "incomplete".
How to use ImportC?
I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC?