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

Fix bug with empty Wasm file when using system binaryen for optimization #179

Merged
merged 6 commits into from
Feb 18, 2021

Conversation

cmichi
Copy link
Collaborator

@cmichi cmichi commented Feb 18, 2021

@ascjones The regression which you found is unfortunately a bug which was introduced when making the binaryen dependency opt-in.

I've added a number of asserts now and fixed it.

@cmichi cmichi requested a review from ascjones February 18, 2021 12:05

let mut optimized_wasm_file = File::create(optimized.as_os_str())?;
optimized_wasm_file.write_all(&optimized_wasm)?;
Copy link
Collaborator Author

@cmichi cmichi Feb 18, 2021

Choose a reason for hiding this comment

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

This was the bug: the optimized Wasm file was created here and the returned bytes from do_optimization written into it.

But:

  • This was only necessary for the do_optimization function enabled with feature = "binaryen-as-dependency".

  • For the do_optimization function enabled with not(feature = "binaryen-as-dependency") the wasm-opt cli was already invoked with -o optimized-wasm-file ‒ thus already creating the file.
    Consequently the returned bytes from the function were always empty. I first tried to fix this bug by having wasm-opt return a raw bytestream, but found a bug in wasm-opt which currently prevents this: wasm-opt fails when -o is omitted, instead of writing to stdout as fallback WebAssembly/binaryen#3579.

Copy link
Collaborator Author

@cmichi cmichi Feb 18, 2021

Choose a reason for hiding this comment

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

Maybe it would also make sense to invoke our tests with --features=binaryen-as-dependency as well as without.

@cmichi cmichi force-pushed the cmichi-fix-wasm-optimization branch from 337bec1 to ab7468f Compare February 18, 2021 12:23
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM. As you suggest we should add a CI test run with binaryen-as-dependency enabled.

src/cmd/build.rs Outdated Show resolved Hide resolved
@cmichi cmichi merged commit 7182b43 into master Feb 18, 2021
@cmichi cmichi deleted the cmichi-fix-wasm-optimization branch February 18, 2021 13:29
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