LearnWebGPU-Code icon indicating copy to clipboard operation
LearnWebGPU-Code copied to clipboard

webassembly advice

Open manuel76413 opened this issue 5 months ago • 1 comments

Thanks for this repo.

After modifying some code, I can build on Windows and run successfully.

However, I cannot build on webassembly with the following command:

rd /s /q build_wasm emcmake cmake . -B build_wasm -G "Ninja" ninja -C build_wasm -j8

Please give me some advice, how to build this project and let it run on the web?

manuel76413 avatar Jul 17 '25 04:07 manuel76413

The compile log is :

ninja -C build_wasm -j 8 ninja: Entering directory build_wasm' [1/5] Building C object glfw3webgpu/CMakeFiles/glfw3webgpu.dir/glfw3webgpu.c.o FAILED: glfw3webgpu/CMakeFiles/glfw3webgpu.dir/glfw3webgpu.c.o C:\dev\emsdk\upstream\emscripten\emcc.bat -DWEBGPU_BACKEND_EMDAWNWEBGPU -IF:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/glfw3webgpu/. -IF:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/webgpu/emdawnwebgpu/include --use-port=F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/build_wasm/_deps/emdawnwebgpu-src/emdawnwebgpu.port.py -MD -MT glfw3webgpu/CMakeFiles/glfw3webgpu.dir/glfw3webgpu.c.o -MF glfw3webgpu\CMakeFiles\glfw3webgpu.dir\glfw3webgpu.c.o.d -o glfw3webgpu/CMakeFiles/glfw3webgpu.dir/glfw3webgpu.c.o -c F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/glfw3webgpu/glfw3webgpu.c F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/glfw3webgpu/glfw3webgpu.c:163:41: error: assigning to 'WGPUStringView' (aka 'struct WGPUStringView') from incompatible type 'char[7]' 163 | fromCanvasHTMLSelector.selector = "canvas"; | ^ ~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/glfw3webgpu/glfw3webgpu.c:167:33: error: assigning to 'WGPUStringView' (aka 'struct WGPUStringView') from incompatible type 'void ' 167 | surfaceDescriptor.label = NULL; | ^ ~~~~ 2 errors generated. [2/5] Building CXX object imgui/CMakeFiles/imgui.dir/backends/imgui_impl_wgpu.cpp.o FAILED: imgui/CMakeFiles/imgui.dir/backends/imgui_impl_wgpu.cpp.o C:\dev\emsdk\upstream\emscripten\em++.bat -DWEBGPU_BACKEND_EMDAWNWEBGPU -IF:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/. -IF:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/webgpu/emdawnwebgpu/include -std=c++17 --use-port=F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/build_wasm/_deps/emdawnwebgpu-src/emdawnwebgpu.port.py -MD -MT imgui/CMakeFiles/imgui.dir/backends/imgui_impl_wgpu.cpp.o -MF imgui\CMakeFiles\imgui.dir\backends\imgui_impl_wgpu.cpp.o.d -o imgui/CMakeFiles/imgui.dir/backends/imgui_impl_wgpu.cpp.o -c F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:257:8: error: unknown type name 'WGPUProgrammableStageDescriptor' 257 | static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const char wgsl_source) | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:267:29: error: use of undeclared identifier 'WGPUSType_ShaderModuleWGSLDescriptor' 267 | wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:268:20: error: no viable overloaded '=' 268 | wgsl_desc.code = wgsl_source; | ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ F:\cmo-dev\my_osgearth_web\LearnWebGPU-Code-step100-next2\build_wasm_deps\emdawnwebgpu-src\webgpu\include\webgpu/webgpu.h:107:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const char *' to 'const WGPUStringView' for 1st argument 107 | typedef struct WGPUStringView { | ^~~~~~~~~~~~~~ F:\cmo-dev\my_osgearth_web\LearnWebGPU-Code-step100-next2\build_wasm_deps\emdawnwebgpu-src\webgpu\include\webgpu/webgpu.h:107:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'const char *' to 'WGPUStringView' for 1st argument 107 | typedef struct WGPUStringView { | ^~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:274:5: error: unknown type name 'WGPUProgrammableStageDescriptor' 274 | WGPUProgrammableStageDescriptor stage_desc = {}; | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:566:24: error: no viable overloaded '=' 566 | tex_desc.label = "Dear ImGui Texture"; | ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~ F:\cmo-dev\my_osgearth_web\LearnWebGPU-Code-step100-next2\build_wasm_deps\emdawnwebgpu-src\webgpu\include\webgpu/webgpu.h:107:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const char[19]' to 'const WGPUStringView' for 1st argument 107 | typedef struct WGPUStringView { | ^~~~~~~~~~~~~~ F:\cmo-dev\my_osgearth_web\LearnWebGPU-Code-step100-next2\build_wasm_deps\emdawnwebgpu-src\webgpu\include\webgpu/webgpu.h:107:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'const char[19]' to 'WGPUStringView' for 1st argument 107 | typedef struct WGPUStringView { | ^~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:611:9: error: unknown type name 'WGPUImageCopyTexture' 611 | WGPUImageCopyTexture dst_view = {}; | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:620:9: error: unknown type name 'WGPUTextureDataLayout'; did you mean 'WGPUTextureBindingLayout'? 620 | WGPUTextureDataLayout layout = {}; | ^~~~~~~~~~~~~~~~~~~~~ | WGPUTextureBindingLayout F:\cmo-dev\my_osgearth_web\LearnWebGPU-Code-step100-next2\build_wasm_deps\emdawnwebgpu-src\webgpu\include\webgpu/webgpu.h:1731:3: note: 'WGPUTextureBindingLayout' declared here 1731 | } WGPUTextureBindingLayout WGPU_STRUCTURE_ATTRIBUTE; | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:622:16: error: no member named 'offset' in 'WGPUTextureBindingLayout' 622 | layout.offset = 0; | ~~~~~~ ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:623:16: error: no member named 'bytesPerRow' in 'WGPUTextureBindingLayout' 623 | layout.bytesPerRow = tex->Width * tex->BytesPerPixel; | ~~~~~~ ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:624:16: error: no member named 'rowsPerImage' in 'WGPUTextureBindingLayout' 624 | layout.rowsPerImage = upload_h; | ~~~~~~ ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:699:5: error: unknown type name 'WGPUProgrammableStageDescriptor' 699 | WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_vert_wgsl); | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:711:11: error: cannot initialize a member subobject of type 'WGPUChainedStruct *' with an rvalue of type 'WGPUVertexFormat' 711 | { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, pos), 0 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:711:39: error: cannot initialize a member subobject of type 'WGPUVertexFormat' with an rvalue of type 'uint64_t' (aka 'unsigned long long') 711 | { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, pos), 0 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:712:11: error: cannot initialize a member subobject of type 'WGPUChainedStruct *' with an rvalue of type 'WGPUVertexFormat' 712 | { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, uv), 1 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:712:39: error: cannot initialize a member subobject of type 'WGPUVertexFormat' with an rvalue of type 'uint64_t' (aka 'unsigned long long') 712 | { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, uv), 1 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:713:11: error: cannot initialize a member subobject of type 'WGPUChainedStruct *' with an rvalue of type 'WGPUVertexFormat' 713 | { WGPUVertexFormat_Unorm8x4, (uint64_t)offsetof(ImDrawVert, col), 2 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:713:39: error: cannot initialize a member subobject of type 'WGPUVertexFormat' with an rvalue of type 'uint64_t' (aka 'unsigned long long') 713 | { WGPUVertexFormat_Unorm8x4, (uint64_t)offsetof(ImDrawVert, col), 2 }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:727:5: error: unknown type name 'WGPUProgrammableStageDescriptor' 727 | WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_frag_wgsl); | ^ F:/cmo-dev/my_osgearth_web/LearnWebGPU-Code-step100-next2/imgui/backends/imgui_impl_wgpu.cpp:757:45: error: assigning to 'WGPUOptionalBool' from incompatible type 'bool' 757 | depth_stencil_state.depthWriteEnabled = false; | ^~~~~ 19 errors generated. ninja: build stopped: subcommand failed.`

manuel76413 avatar Jul 17 '25 04:07 manuel76413