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

Automatically start execution on import. #1940

Closed
wants to merge 3 commits into from
Closed

Automatically start execution on import. #1940

wants to merge 3 commits into from

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Jan 3, 2020

This changes wasm-bindgen to start execution when importing the js file by default and adds a flag to disable this behaviour.

The no-modules part currently relies on #1938, I can change that if necessary.

Currently what this does is change init/wasm_bindgen from a function into a promise. The original function is now in an exported init or respectively in wasm_bindgen init.

Having worked on this PR a little, made me realize that there is some bigger design work necessary, I can't change this PR in a draft, but discussion is obviously in #1939.

I would like to get some feedback on the documentation/description of the added flag.

Fixes #1939.

@alexcrichton
Copy link
Contributor

Thanks for the PR here! I'm a bit wary to land this though because initialization can often require some form of configuration or tweaking, and I'm not sure we can reliable automatically start it on import all the time. It'd certainly be a nice goal to move towards though!

(this is what es6 module integration is all about fwiw)

@daxpedda
Copy link
Collaborator Author

daxpedda commented Jan 7, 2020

I'm a bit wary to land this though because initialization can often require some form of configuration or tweaking, and I'm not sure we can reliable automatically start it on import all the time.

What kind of configuration or tweaking do you mean?
The only thing that comes to my mind is:

  • sometimes its not desired to start automatically
    • doing some things in javascript first
    • website isn't build around wasm, and wasm might only be initialized in certain user interactions
  • wasm files have been renamed, so automatic start can't determine the correct wasm file name

Basically just user reasons that can be disabled with the flag, I can't figure out if there is something more technical, is there?

In any case this PR enables automatic start by default, I don't think we should merge this because its going to break most builds, at least until we get more feedback.

@alexcrichton
Copy link
Contributor

Yes primarily that hosting reasons mean that we don't actually know the structure of files 100% of the time, it may be tweaked from time to time. I believe contexts like web workers and such may also throw a wrench into the issue.

@daxpedda
Copy link
Collaborator Author

daxpedda commented Jan 9, 2020

What if we make a flag called --auto-start [file] and file is supposed to be the wasm file that's automatically started.
This way, nothing is going to change by default, and anybody who is actually interested in automatic start can pass this flag with a proper path, even if the structure is changed.

This would be an ad-hoc solution, I don't know how else we would solve this issue.

The alternative is of course to just wait for ES module integration of wasm.

If this suggestion is not acceptable, and we can't come up with better alternatives, maybe we should do exactly that: leave everything as it is and wait for ES module integration, e.g. close this PR.

@alexcrichton
Copy link
Contributor

I think I would personally prefer to wait for ES module integration to propagate more. The fact that you need to pass in a file is specific to the output type, and part of the output type is that simply you need to pass in a file of what to load.

@daxpedda
Copy link
Collaborator Author

Alright.

@daxpedda daxpedda closed this Jan 13, 2020
@daxpedda daxpedda deleted the start-on-import branch January 13, 2020 15:53
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.

Automatically start main on import.
2 participants