henrybetts / swift-webgpu

Swift bindings for WebGPU
MIT License
89 stars 4 forks source link

libwebgpu_dawn.dylib needs to be added to .build folder #19

Open AryzenRS opened 1 week ago

AryzenRS commented 1 week ago

As per the title, after updating packages, not sure what caused this but my dylib now needs to be in my .build/arm64-apple-macosx/ folder in order to run. Possibly a mistake on my part but I don't recall needing to do this before.

henrybetts commented 1 week ago

Can you try running otool -D /usr/local/lib/libwebgpu_dawn.dylib - I suspect the output will probably contain something like @rpath/libwebgpu_dawn.dylib, which means it is expecting to be placed next to the executable.

You should be able to change the default install name of the dylib like so: sudo install_name_tool -id /usr/local/lib/libwebgpu_dawn.dylib /usr/local/lib/libwebgpu_dawn.dylib.

The whole installation process is a bit fiddly. I'll try rebuilding the latest dawn myself and add this step to the docs if needed.

henrybetts commented 1 week ago

Alternatively, you can add an rpath to the executable. In Swift package manager you can do this with something like linkerSettings: [.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "/usr/local/lib"])]. Or you should be able to pass these flags directly to the swift command.

Arguably this is the better solution as it gives the end executable control over where to locate the library.