wgpu-native icon indicating copy to clipboard operation
wgpu-native copied to clipboard

Link failure when using a meson wrap

Open mempler opened this issue 4 years ago • 4 comments

I've been trying getting wgpu-native running on a simple meson project on my Linux machine with no success so far. This feels like user error on my end but this might also be an bug in the given meson implementation or even rust compiler.

Attached some required information to debug the given situation below.

Reproduction

~$ meson build
~$ cd build
~$ ninja

Files

meson.build

project(
    'Test',
    'c', 'rust',
    version : '1.0',
    meson_version : '>= 0.59.0',
    default_options : [ 'warning_level=3', 'c_std=c17' ]
)

executable('test-app', 'main.c', dependencies : [ dependency('wgpu-native') ])

subprojects/wgpu-native.wrap

[wrap-git]
url = https://github.com/gfx-rs/wgpu-native.git
revision = a1f81dea3df1f367918e442d11ffdb9acc1d367a
clone-recursive = true

main.c

#include <webgpu-headers/webgpu.h>

int main() {
  WGPUInstanceDescriptor desc = {.nextInChain = NULL};
  WGPUInstance instance = wgpuCreateInstance(&desc);
  return 0;
}

Logs

ninja -C build/

[1/2] Compiling C object test-app.p/main.c.o
../main.c: In function ‘main’:
../main.c:7:16: warning: unused variable ‘instance’ [-Wunused-variable]
    7 |   WGPUInstance instance = wgpuCreateInstance(&desc);
      |                ^~~~~~~~
[2/2] Linking target test-app
FAILED: test-app 
cc  -o test-app test-app.p/main.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group subprojects/wgpu-native/libwgpu_native.a -Wl,--end-group
/usr/bin/ld: subprojects/wgpu-native/libwgpu_native.a: error adding symbols: archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

rustup show

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/mempler/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)

mempler avatar Oct 03 '21 07:10 mempler

Duplicate of #116, that is, wgpuCreateInstance() is currently not implemented.

sqaxomonophonen avatar Jan 02 '22 19:01 sqaxomonophonen

The question is, why is the other issue closed if wgpuCreateInstance still isn't implemented ?

mempler avatar Jan 05 '22 07:01 mempler

Good question. Having looked into it myself, it seems like a low priority problem that's hard to fix:

  • I haven't found any good reason to ever have more than one instance. It's a jumping off point to create surfaces and adapters, but since you can't configure the instance in any way, it might as well be a singleton. In fact, it corresponds somewhat to navigator.gpu in the browser, which you also only have one of.
  • and, it's not easy to fix/implement, at least not without changes to wgpu. The culprit is that wgpu-native doesn't return true pointers to resources (e.g. WGPUBuffer), but rather integer keys (which in turn come from wgpu), and these keys would not be unique across multiple instances.

My suggestion would be to implement wgpuCreateInstance(), but have it panic with a helpful message, or have it return NULL and throw a helpful warning. If only because it's natural to start your code with wgpuCreateInstance(). Or maybe even suggest to remove wgpuCreateInstance() from the standard on https://github.com/webgpu-native/webgpu-headers ? :-)

sqaxomonophonen avatar Jan 05 '22 19:01 sqaxomonophonen

The issue was closed because the subject isn't mentioning the missing method. We still do want to implement it, even if just as some dummy code. The goal of wgpu-native to be compatible with the standard headers (which we help develop). So by all means an open issue would be welcome, and PRs especially!

kvark avatar Jan 05 '22 20:01 kvark