Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: Fallback to instantiate with improper MIME type #2561

Merged
merged 1 commit into from
Jan 16, 2021

Conversation

Herschel
Copy link
Member

@Herschel Herschel commented Jan 15, 2021

Use --target web in wasm-bindgen and file-loader for WASM files,
allowing wasm-bindgen's built-in fallback from
WebAssembly.instantiateStreaming to instantiate to function.

file-loader spits out the WASM file directly in the output folder,
and imports will resolve to the URL, so that we can load the file
directly, avoiding webpack's built-in wasm loaders.

This allows Ruffle to function on web servers even if they serve
WASM files with the incorrect MIME type, fixing one of our biggest
support problems (#400, #1458). There is some performance impact
on loading with the fallback, but it seems minimal to me and is preferable
to not working at all.

Perhaps someone with more webpack/JS experience can look this over and verify that everything makes sense.

@Herschel Herschel force-pushed the wasm-instantiate-fallback branch from 26ce083 to 9f825e1 Compare January 15, 2021 22:35
@Toad06
Copy link
Member

Toad06 commented Jan 15, 2021

The selfhosted build works great but the extensions (.xpi and .zip) are broken, at least on my end: it misses the dist/ directory, so actually all major files.

@Herschel
Copy link
Member Author

The selfhosted build works great but the extensions (.xpi and .zip) are broken, at least on my end: it misses the dist/ directory, so actually all major files.

Having trouble reproing here, I get the dist folder--could you try:

npx lerna clean
npm run bootstrap
npm run build

@Herschel
Copy link
Member Author

Herschel commented Jan 16, 2021

BTW, I use the npm http-server to test the fallback, as it doesn't serve with the WASM MIME type.

@Toad06
Copy link
Member

Toad06 commented Jan 16, 2021

The directory / files are still missing, unfortunately. Weird. I'll give it another try tomorrow.

@Toad06
Copy link
Member

Toad06 commented Jan 16, 2021

I've tried again and the issue still happened. I've no issue compiling on the current master branch.

FWIW, reverting the changes in load-ruffle.ts creates the dist/ directory with almost all of its files but the .wasm. I still don't understand why this only happens on my end though. :/

@Herschel
Copy link
Member Author

Herschel commented Jan 16, 2021

Okay, I was able to repro the issue on my side. Looking into it now.

Use --target web in wasm-bindgen and file-loader for WASM files,
allowing wasm-bindgen's built-in fallback from
WebAssembly.instantiateStreaming to instantiate.

file-loader spits out the WASM file directly in the output folder,
and imports will resolve to the URL, so that we can load the file
directly, avoiding webpack's built-in wasm loaders.

This allows Ruffle to function on web servers even if they serve
WASM files with the incorrect MIME type, fixing one of our biggest
support requests (ruffle-rs#400, ruffle-rs#1458). There is some performance impact
on loading with the fallback, but this is preferable to not
working at all.
@Herschel Herschel force-pushed the wasm-instantiate-fallback branch from 9f825e1 to cc81927 Compare January 16, 2021 22:04
@Herschel
Copy link
Member Author

Forgot to remove syncWebAssembly setting from extension's webpack config, could you try again now?

@Toad06
Copy link
Member

Toad06 commented Jan 16, 2021

I confirm this is working now. 👍

@Toad06
Copy link
Member

Toad06 commented Jan 16, 2021

There's just a surprising thing, in the JS file there's a path to the folder where Ruffle has been compiled:

async function init(input) {
    if (typeof input === 'undefined') {
        input = "file:///C:/Users/toad/Desktop/Ruffle/ruffle-wasm-instantiate-fallback/web/packages/core/pkg/ruffle_web.js".replace(/\.js$/, '_bg.wasm');
    }

This is not really important though, as input is never undefined.

@Herschel
Copy link
Member Author

That code is from wasm-bindgen, which originally does import.meta.url, but webpack tries to be smart and mangles that into the file URL. Not sure of an easy way to fix it, but seems relatively harmless for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants