Skip to content

Conversation

@Bromeon
Copy link
Member

@Bromeon Bromeon commented Jan 5, 2026

@Bromeon Bromeon added the enhancement Ongoing improvements to readability, flow, etc. label Jan 5, 2026
Copy link

@SvizelPritula SvizelPritula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

"-C", "link-args=-pthread", # /!\ Read 'Thread support' below regarding this flag
"-C", "target-feature=+atomics", # /!\ Read 'Thread support' below regarding this flag
"-C", "link-args=-sSIDE_MODULE=2",
"-C", "-Zdefault-visibility=hidden",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant this?

Suggested change
"-C", "-Zdefault-visibility=hidden",
"-Z", "default-visibility=hidden",

RUSTFLAGS="-C link-args=-pthread \
-C target-feature=+atomics \
-C link-args=-sSIDE_MODULE=2 \
-C -Zdefault-visibility=hidden \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-C -Zdefault-visibility=hidden \
-Z default-visibility=hidden \

-C link-args=-pthread \
-C target-feature=+atomics \
-C link-args=-sSIDE_MODULE=2 \
-C default-visibility=hidden \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-C default-visibility=hidden \
-Z default-visibility=hidden \

A bit of background: The compiled Wasm binary is a _side module_ which is dynamically loaded by Godot's _main module_ at runtime.
This is very similar to how dynamic libraries and executables work.

The [`default-visibility=hidden` flag][rustc-visibility] ensures that symbols of each side module are private to that module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this affect user (non-gdext internal) code somehow? If this is the default, how can it be selectively turned off?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently don't see a use case where one wouldn't want that -- it would mean explicitly sharing symbols with other side modules (Godot or extensions) -- and there are better ways to communicate with them (GDExtension itself) 🤔

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can be selectively turned off right now, which is unfortunate. There is an RFC, though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that the toolchain's behaviour is buggy, I believe normally only #[unsafe(no_mangle)] should be exported like this. As I mentioned in my comment, on x86-64 Linux all non-mangled objects end up as LOCAL.


In addition, please note that **godot-rust 0.3 or later** is required to fix this error.

4. `LinkError: WebAssembly.instantiate(): Import #6 "env" "__cpp_exception": tag import requires a WebAssembly.Tag`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we could also mention something about this bug in this section, but I suppose it doesn't lead to one specific error, rather being undefined behavior / a race condition.

@Bromeon Bromeon force-pushed the feature/wasm-update branch from 679d349 to 735f53b Compare January 6, 2026 07:59
@Bromeon
Copy link
Member Author

Bromeon commented Jan 6, 2026

Thanks a lot @PgBiel!

The different formatting and order of -C and -Z totally confused me -- I made this consistent now.

Regarding "what if one forgets -Zdefault-visibility=hidden", I thought about this yesterday. An idea would be to install a canary in godot-rust, e.g. verifying on startup that a global variable is unpopulated, and crashing with a useful error otherwise.

@PgBiel
Copy link
Contributor

PgBiel commented Jan 6, 2026

An idea would be to install a canary in godot-rust, e.g. verifying on startup that a global variable is unpopulated, and crashing with a useful error otherwise.

Interesting. Would be nice indeed i possible.

More generally, though, I really wish we could just manage those flags for the user. Would be nice if we could figure out a way to set "defaults"...

I remember looking into some solution involving build.rs, but I don't remember how far that went. If possible, though, this could become part of some project template or similar.

@Bromeon Bromeon merged commit d02ebac into master Jan 7, 2026
4 checks passed
@Bromeon Bromeon deleted the feature/wasm-update branch January 7, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Ongoing improvements to readability, flow, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants