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: static array is not a range
On Tuesday, 9 January 2024 at 21:30:06 UTC, Alexibu wrote: If each works, I can't see why map filter etc can't work consistently where they only need an input range. ```d auto line = arr.filter!(a > 0).map!(a => a.to!string).joiner("\t").text; ``` Should be fine because each result range is passed on the stack to the next algorithm, and then at the end the text (or array) algorithm doesn't return a range. Also this should be fine because the ranges are all used on the stack. [...] I wonder if the compiler could tell if you are only using the range as a temporary argument as opposed to assigning it to a variable ? You can do it like this: ```D import std; void main() @trusted { float[6] arr = [1, 2, 3, 4, 5, 6]; auto line = arr[].filter!(a => a > 0).map!(a => a.to!string).joiner("\t").text; writeln(line); } ``` The `arr[]` creates a temporary slice. This currently has to be run as `@trusted` and you also need to be sure that the temporary slice does not escape the scope.