framesurge / perseus

A state-driven web development framework for Rust with full support for server-side rendering and static generation.
https://framesurge.sh/perseus/en-US
MIT License
2.18k stars 89 forks source link

Fix Wasm target gates for engine-side Wasm operation #245

Closed arctic-hen7 closed 1 year ago

arctic-hen7 commented 1 year ago

This issue is reporting a bug in the code of Perseus. Details of the scope will be available in issue labels. The author described their issue as follows:

Right now, attempting to use engine-side Perseus in a Wasm environment will lead to errors that look something like the detonation of a nearby star. This should be trivially fixable by changing the existing #[cfg(target_arch = "wasm32")] and inverse target-gates to something that specifically recognizes only browser-side Wasm. Exactly what this is is another matter.

The steps to reproduce this issue are as follows:

Try to compile and run engine-side Perseus on something like a Cloudflare worker.

A minimum reproducible example is available at <>.

Tribble internal data dHJpYmJsZS1yZXBvcnRlZCxDLWJ1ZyxhdXRob3Itd2lsbGluZy10by1pbXBs
arctic-hen7 commented 1 year ago

Due to the lack of a #[cfg(target = "wasm32-unknown-unknown")]-style conditional compilation predicate (to my knowledge), this is very possibly going to become quite grotesque, and it is used a lot in the codebase. If anyone has a particularly elegant way of doing this, that would be greatly appreciated! (My attention is with the capsules right now.)

lukechu10 commented 1 year ago

Due to the lack of a #[cfg(target = "wasm32-unknown-unknown")]-style conditional compilation predicate (to my knowledge), this is very possibly going to become quite grotesque, and it is used a lot in the codebase. If anyone has a particularly elegant way of doing this, that would be greatly appreciated! (My attention is with the capsules right now.)

Even if that were possible, I don't think that would be a good solution. Instead, maybe have the perseus CLI set a custom cfg flag via the command line and use #[cfg(ssr)] which is nice and short.

arctic-hen7 commented 1 year ago

This is exactly what I was thinking, but perhaps a build script would be cleaner?

lukechu10 commented 1 year ago

This is exactly what I was thinking, but perhaps a build script would be cleaner?

The problem with build-scripts is that they only affect the current crate that is being compiled, whereas setting a flag from the CLI will affect all the crates being compiled. You probably want the latter because these feature gates would also be used in perseus and other dependencies.

arctic-hen7 commented 1 year ago

Ah I hadn't understood that. Thanks!

arctic-hen7 commented 1 year ago

This is fixed in the latest commit, but I haven't explicitly tested support for compiling the engine to Wasi or the like. Since this issue pertains to the target gates themselves, I'll close this.

arctic-hen7 commented 1 year ago

Pretty sure actually compiling Perseus to Wasi is blocked by https://github.com/rust-lang/socket2/issues/268.