godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
3.1k stars 197 forks source link

Error loading extension: res//DodgeTheCreeps.gdextension #208

Closed mareksubocz closed 1 year ago

mareksubocz commented 1 year ago

I've tried to run DodgeTheCreeps demo on M1 Macbook Pro. The project built and the game started, but nothing happened after clicking the "START" button inside the game and following errors appeared:

Can't open dynamic library: /Users/mareksubocz/it/gdext/examples/dodge-the-creeps/godot/../../../target/debug/libdodge_the_creeps.dylib, error: dlopen(/Applications/Godot.app/Contents/MacOS/../Frameworks/libdodge_the_creeps.dylib, 0x0002): tried: '/Applications/Godot.app/Contents/MacOS/../Frameworks/libdodge_the_creeps.dylib' (no such file).
  core/extension/gdextension.cpp:400 - GDExtension dynamic library not found: /Users/mareksubocz/it/gdext/examples/dodge-the-creeps/godot/../../../target/debug/libdodge_the_creeps.dylib
  Failed loading resource: res://DodgeTheCreeps.gdextension. Make sure resources have been imported by opening the project in the editor at least once.
  Can't open dynamic library: /Users/mareksubocz/it/gdext/examples/dodge-the-creeps/godot/../../../target/debug/libdodge_the_creeps.dylib, error: dlopen(/Applications/Godot.app/Contents/MacOS/../Frameworks/libdodge_the_creeps.dylib, 0x0002): tried: '/Applications/Godot.app/Contents/MacOS/../Frameworks/libdodge_the_creeps.dylib' (no such file).
  core/extension/gdextension.cpp:400 - GDExtension dynamic library not found: /Users/mareksubocz/it/gdext/examples/dodge-the-creeps/godot/../../../target/debug/libdodge_the_creeps.dylib
  Failed loading resource: res://DodgeTheCreeps.gdextension. Make sure resources have been imported by opening the project in the editor at least once.

The steps I took to set the project up were:

brew install godot
git clone https://github.com/godot-rust/gdext && cd gdext
export GODOT4_BIN=/Applications/Godot.app/Contents/MacOS/Godot
export LLVM_PATH=/Library/Developer/CommandLineTools/usr/bin
cargo build # successfully
cd examples/dodge-the-creeps
cargo build # successfully
godot # to run the game

Is there something I overlooked?

Bromeon commented 1 year ago

Could you check the contents of the directory gdext/examples/dodge-the-creeps/godot/../../../target/debug?

Also, try specifically cargo build -p dodge-the-creeps (although that shouldn't be necessary).

mareksubocz commented 1 year ago
image

Also, cargo build -p dodge-the-creeps didn't fix anything.

Bromeon commented 1 year ago

Is there only the dynamic library for godot_macros? Why not for godot?

mareksubocz commented 1 year ago

Sorry, I'm not sure what you mean

EDIT: I showed all of the contents of the debug folder if that's what you mean. Not sure why there are no libraries for godot itself.

lilizoey commented 1 year ago

try to cd into examples/dodge-the-creeps/rust before building

Bromeon commented 1 year ago

Can you do the following, and paste the full command line + output? Navigate to the gdext directory, then:

rm -rf target
cargo update
cargo build
ls -la target/debug
mareksubocz commented 1 year ago

try to cd into examples/dodge-the-creeps/rust before building

That didn't change anything.

Can you do the following, and paste the full command line + output? Navigate to the gdext directory, then:

rm -rf target
cargo update
cargo build
ls -la target/debug

➜ gdext git:(master) ✗ rm -rf target ➜ gdext git:(master) ✗ cargo update Updating crates.io index ➜ gdext git:(master) ✗ cargo build Compiling libc v0.2.140 Compiling proc-macro2 v1.0.54 Compiling quote v1.0.26 Compiling unicode-ident v1.0.8 Compiling nanoserde-derive v0.1.19 Compiling regex-syntax v0.6.29 Compiling glob v0.3.1 Compiling memchr v2.5.0 Compiling either v1.8.1 Compiling minimal-lexical v0.2.1 Compiling clang-sys v1.6.0 Compiling cfg-if v1.0.0 Compiling syn v1.0.109 Compiling heck v0.4.1 Compiling nanoserde v0.1.32 Compiling which v4.4.0 Compiling nom v7.1.3 Compiling libloading v0.7.4 Compiling bindgen v0.63.0 Compiling regex v1.7.3 Compiling godot-codegen v0.1.0 (/Users/mareksubocz/it/gdext/godot-codegen) Compiling cexpr v0.6.0 Compiling rustc-hash v1.1.0 Compiling lazycell v1.3.0 Compiling shlex v1.1.0 Compiling lazy_static v1.4.0 Compiling bitflags v1.3.2 Compiling peeking_take_while v0.1.2 Compiling paste v1.0.12 Compiling venial v0.5.0 Compiling once_cell v1.17.1 Compiling getrandom v0.2.8 Compiling glam v0.22.0 Compiling rand_core v0.6.4 Compiling ppv-lite86 v0.2.17 Compiling rand_chacha v0.3.1 Compiling itest v0.1.0 (/Users/mareksubocz/it/gdext/itest/rust) Compiling rand v0.8.5 Compiling godot-macros v0.1.0 (/Users/mareksubocz/it/gdext/godot-macros) Compiling godot-core v0.1.0 (/Users/mareksubocz/it/gdext/godot-core) Compiling godot-ffi v0.1.0 (/Users/mareksubocz/it/gdext/godot-ffi) Compiling godot v0.1.0 (/Users/mareksubocz/it/gdext/godot) Compiling dodge-the-creeps v0.1.0 (/Users/mareksubocz/it/gdext/examples/dodge-the-creeps/rust) Finished dev [unoptimized + debuginfo] target(s) in 44.07s ➜ gdext git:(master) ✗ ls -la target/debug total 3544 drwxr-xr-x 10 mareksubocz staff 320 Mar 28 14:35 . drwxr-xr-x@ 6 mareksubocz staff 192 Mar 28 14:35 .. -rw-r--r-- 1 mareksubocz staff 0 Mar 28 14:34 .cargo-lock drwxr-xr-x 52 mareksubocz staff 1664 Mar 28 14:34 .fingerprint drwxr-xr-x 21 mareksubocz staff 672 Mar 28 14:34 build drwxr-xr-x 239 mareksubocz staff 7648 Mar 28 14:34 deps drwxr-xr-x 2 mareksubocz staff 64 Mar 28 14:34 examples drwxr-xr-x 7 mareksubocz staff 224 Mar 28 14:34 incremental -rw-r--r-- 1 mareksubocz staff 408 Mar 28 14:35 libgodot_macros.d -rwxr-xr-x 1 mareksubocz staff 1808051 Mar 28 14:34 libgodot_macros.dylib

image
Bromeon commented 1 year ago

Thanks! This is very strange, it clearly compiles both godot and dodge-the-creeps crates, yet doesn't generate the cdylib files for them. For some reason, it does for macros though....

Do you get more information about cargo build output if you clean again, and then use the -v (verbose) flag? Please only list the godot-* and dodge-the-creeps crates, otherwise it's too much output 😅

mareksubocz commented 1 year ago
image

Compiling godot-macros v0.1.0 (/Users/mareksubocz/it/gdext/godot-macros) Running rustc --crate-name godot_macros --edition=2021 godot-macros/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=45969ee3b5d32581 -C extra-filename=-45969ee3b5d32581 --out-dir /Users/mareksubocz/it/gdext/target/debug/deps -C incremental=/Users/mareksubocz/it/gdext/target/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern proc_macro2=/Users/mareksubocz/it/gdext/target/debug/deps/libproc_macro2-ec7a94c44b825f70.rlib --extern quote=/Users/mareksubocz/it/gdext/target/debug/deps/libquote-e2d12cf1ee92377f.rlib --extern venial=/Users/mareksubocz/it/gdext/target/debug/deps/libvenial-a672150ec89edc86.rlib --extern proc_macro

Compiling godot-core v0.1.0 (/Users/mareksubocz/it/gdext/godot-core) Running rustc --crate-name build_script_build --edition=2021 godot-core/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="codegen-fmt"' --cfg 'feature="codegen-full"' --cfg 'feature="default"' -C metadata=f39c3073ea76eb08 -C extra-filename=-f39c3073ea76eb08 --out-dir /Users/mareksubocz/it/gdext/target/debug/build/godot-core-f39c3073ea76eb08 -C incremental=/Users/mareksubocz/it/gdext/target/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern godot_codegen=/Users/mareksubocz/it/gdext/target/debug/deps/libgodot_codegen-1842597e275d7f2b.rlib Running /Users/mareksubocz/it/gdext/target/debug/build/godot-core-f39c3073ea76eb08/build-script-build

Compiling godot-ffi v0.1.0 (/Users/mareksubocz/it/gdext/godot-ffi) Running rustc --crate-name build_script_build --edition=2021 godot-ffi/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="codegen-fmt"' -C metadata=01c37074376d1143 -C extra-filename=-01c37074376d1143 --out-dir /Users/mareksubocz/it/gdext/target/debug/build/godot-ffi-01c37074376d1143 -C incremental=/Users/mareksubocz/it/gdext/target/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern bindgen=/Users/mareksubocz/it/gdext/target/debug/deps/libbindgen-7f5a80cf3e50fa20.rlib --extern godot_codegen=/Users/mareksubocz/it/gdext/target/debug/deps/libgodot_codegen-1842597e275d7f2b.rlib Running /Users/mareksubocz/it/gdext/target/debug/build/godot-ffi-01c37074376d1143/build-script-build Running rustc --crate-name godot_ffi --edition=2021 godot-ffi/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="codegen-fmt"' -C metadata=67478647ed79e866 -C extra-filename=-67478647ed79e866 --out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps --target aarch64-apple-darwin -C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern paste=/Users/mareksubocz/it/gdext/target/debug/deps/libpaste-b6ef4f94fd2c453a.dylib Running rustc --crate-name godot_core --edition=2021 godot-core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="codegen-fmt"' --cfg 'feature="codegen-full"' --cfg 'feature="default"' -C metadata=bd3b1c83ac063d3c -C extra-filename=-bd3b1c83ac063d3c --out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps --target aarch64-apple-darwin -C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern glam=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libglam-77f28499c61910ab.rmeta --extern godot_ffi=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libgodot_ffi-67478647ed79e866.rmeta --extern once_cell=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libonce_cell-62a7ab7d2d5e1e17.rmeta

Compiling godot v0.1.0 (/Users/mareksubocz/it/gdext/godot) Running rustc --crate-name godot --edition=2021 godot/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="codegen-full"' --cfg 'feature="default"' --cfg 'feature="formatted"' -C metadata=ef54764a70294ad6 -C extra-filename=-ef54764a70294ad6 --out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps --target aarch64-apple-darwin -C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern godot_core=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libgodot_core-bd3b1c83ac063d3c.rmeta --extern godot_macros=/Users/mareksubocz/it/gdext/target/debug/deps/libgodot_macros-45969ee3b5d32581.dylib

Compiling dodge-the-creeps v0.1.0 (/Users/mareksubocz/it/gdext/examples/dodge-the-creeps/rust) Running rustc --crate-name dodge_the_creeps --edition=2021 examples/dodge-the-creeps/rust/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=1ae71296d085bc06 --out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps --target aarch64-apple-darwin -C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern godot=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libgodot-ef54764a70294ad6.rlib --extern rand=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/librand-8f912428da39b905.rlib Running rustc --crate-name itest --edition=2021 itest/rust/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="default"' -C metadata=4f2131549ed7936a --out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps --target aarch64-apple-darwin -C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental -L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps -L dependency=/Users/mareksubocz/it/gdext/target/debug/deps --extern godot=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libgodot-ef54764a70294ad6.rlib Finished dev [unoptimized + debuginfo] target(s) in 44.59s

That's it. Regardless if we will manage to resolve it, thank you for your amazing help :)

Bromeon commented 1 year ago
--out-dir /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps
-C incremental=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/incremental
-L dependency=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps
-L dependency=/Users/mareksubocz/it/gdext/target/debug/deps
--extern godot=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/libgodot-ef54764a70294ad6.rlib
--extern rand=/Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug/deps/librand-8f912428da39b905.rlib

Interesting... 🤔

Can you run a

ls -la /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin

and

ls -la /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug

?

mareksubocz commented 1 year ago
image

➜ gdext git:(master) ✗ ls -la /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin total 8 drwxr-xr-x@ 4 mareksubocz staff 128 Mar 28 14:48 . drwxr-xr-x@ 6 mareksubocz staff 192 Mar 28 14:49 .. -rw-r--r-- 1 mareksubocz staff 177 Mar 28 14:48 CACHEDIR.TAG drwxr-xr-x 20 mareksubocz staff 640 Mar 28 14:49 debug

➜ gdext git:(master) ✗ ls -la /Users/mareksubocz/it/gdext/target/aarch64-apple-darwin/debug total 530576 drwxr-xr-x 20 mareksubocz staff 640 Mar 28 14:49 . drwxr-xr-x@ 4 mareksubocz staff 128 Mar 28 14:48 .. -rw-r--r-- 1 mareksubocz staff 0 Mar 28 14:48 .cargo-lock drwxr-xr-x 32 mareksubocz staff 1024 Mar 28 14:48 .fingerprint drwxr-xr-x 8 mareksubocz staff 256 Mar 28 14:48 build drwxr-xr-x 372 mareksubocz staff 11904 Mar 28 14:49 deps drwxr-xr-x 2 mareksubocz staff 64 Mar 28 14:48 examples drwxr-xr-x 8 mareksubocz staff 256 Mar 28 14:49 incremental -rw-r--r-- 1 mareksubocz staff 75239 Mar 28 14:49 libdodge_the_creeps.d -rwxr-xr-x 1 mareksubocz staff 2349798 Mar 28 14:49 libdodge_the_creeps.dylib -rw-r--r-- 1 mareksubocz staff 74867 Mar 28 14:49 libgodot.d -rw-r--r-- 1 mareksubocz staff 21952 Mar 28 14:49 libgodot.rlib -rw-r--r-- 1 mareksubocz staff 750 Mar 28 14:49 libgodot_codegen.d -rw-r--r-- 1 mareksubocz staff 1179648 Mar 28 14:48 libgodot_codegen.rlib -rw-r--r-- 1 mareksubocz staff 74483 Mar 28 14:49 libgodot_core.d -rw-r--r-- 1 mareksubocz staff 257589648 Mar 28 14:49 libgodot_core.rlib -rw-r--r-- 1 mareksubocz staff 3798 Mar 28 14:49 libgodot_ffi.d -rw-r--r-- 1 mareksubocz staff 2979128 Mar 28 14:48 libgodot_ffi.rlib -rw-r--r-- 1 mareksubocz staff 76585 Mar 28 14:49 libitest.d -rwxr-xr-x 1 mareksubocz staff 7204363 Mar 28 14:49 libitest.dylib

Bromeon commented 1 year ago

Ah, there they are!

In your .gdextension file inside examples/dodge-the-creeps/godot, it looks like you need two extra lines:

macos.debug.aarch64 = "res://../../../target/aarch64-apple-darwin/debug/libdodge_the_creeps.dylib"
macos.release.aarch64 = "res://../../../target/aarch64-apple-darwin/release/libdodge_the_creeps.dylib"

(maybe remove the existing macos entries for now).

I'm actually 100% unsure about "aarch64" part. Might also be "arm64" or something else. Could you try a few things?

It would likely work without any prefix (just macos.debug = "..."), however that means that macOS on other architecture may break.

mareksubocz commented 1 year ago

Nice! That got rid of the problem, thank you so much!

I suspect however there is another thing to solve, the sprites don't display properly:

image

EDIT: FYI, the setting that works is macos.debug.arm64 and macos.release.arm64

Bromeon commented 1 year ago

Nice! That got rid of the problem, thank you so much!

Which architecture was it? How does your .gdextension file look now?

Btw, you should also be able to get the name through Engine::get_architecture_name.

I suspect however there is another thing to solve, the sprites don't display properly:

Can you open the editor once, save all scenes and see if anything changes? From the command line, you can navigate to the dodge-the-creeps/godot directory and run godot4 -e.

mareksubocz commented 1 year ago

architecture is arm64.

DodgeTheCreeps.gdextension:

[configuration]
entry_symbol = "gdext_rust_init"

[libraries]
linux.debug.x86_64 = "res://../../../target/debug/libdodge_the_creeps.so"
linux.release.x86_64 = "res://../../../target/release/libdodge_the_creeps.so"
macos.debug = "res://../../../target/debug/libdodge_the_creeps.dylib"
macos.release = "res://../../../target/release/libdodge_the_creeps.dylib"
windows.debug.x86_64 = "res://../../../target/debug/dodge_the_creeps.dll"
windows.release.x86_64 = "res://../../../target/release/dodge_the_creeps.dll"
macos.debug.arm64 = "res://../../../target/aarch64-apple-darwin/debug/libdodge_the_creeps.dylib"
macos.release.arm64 = "res://../../../target/aarch64-apple-darwin/release/libdodge_the_creeps.dylib"

saving the scenes triggers the same warnings. Do you want me to paste the outputs of godot4 -e? It doesn't fix the warnings.

mareksubocz commented 1 year ago

Let me know if you need it as text, as there is quite a lot of it :)

image image image image
Bromeon commented 1 year ago

Also changing the scenes slightly (in insignificant ways) + saving doesn't update the files? You should see changes in git diff for Mob.tscn and Player.tscn...

mareksubocz commented 1 year ago

It does update the files, but the warnings stil remain. I'm not sure if Player.tsch is updated, as it is not present in git diff.

image
Bromeon commented 1 year ago

From your commit hashes:

index 32c2394..1775a2f

What are those? Looks like none of the recent gdext commits has them.

Does it also happen with latest master (commit 08c65941ce544b2255d5b09168c7e9944a9dd454)?

mareksubocz commented 1 year ago

I am currently using the latest commit. I don't know what those hashes mean, but i reverted all changes and compiled everything again and, despite still seeing some warnings, everything worked and I was able to play the game! Thank you so much :D Love the support of this project! The issue is ready to close.

Bromeon commented 1 year ago

Happy to hear it worked 🙂 Also, if you encounter more questions in the future, feel free to join or Discord, can sometimes be a bit faster 😎

If you don't mind, I will keep this issue open until I added support for aarch64 architecture on macOS. Thanks a lot for reporting!