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

Add build and run commands #24

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

TimJentzsch
Copy link
Collaborator

@TimJentzsch TimJentzsch commented Aug 31, 2024

Objective

Easily build and run your Bevy app.
Especially for the web, it can be complicated to get everything set up.

Solution

This code is ported from https://github.com/TimJentzsch/cargo-bavy, but cleaned up, with more docs, and sometimes adjusted to improve the functionality.

For the most part, bevy build and bevy run are wrappers around the cargo counterparts.

However, we add an additional --web flag, which simplifies the process of building and running web apps.

Currently it:

  • builds WASM targets
  • passes flags along to cargo
  • runs wasm-bindgen
  • starts a local server

Assets are served automatically from the assets folder.
Missing targets and CLI tools are installed automatically (if confirmed by the user).

TODO

  • Make code more robust to different repository setups (e.g. different cargo project structure, different asset folder location, etc).
  • Keep the bindgen in the target folder, so it's cleaned up properly and doesn't require an additional gitignore.
  • Serve a default index.html file if none is defined, making the web folder fully optional.
  • Provide an option to automatically open the browser when running the web build.
  • Figure out what to do with the web stuff in release mode.
  • Use a sub command instead of flag for the web option. This makes it more flexible to provide web-specific options and help text.
  • Support the feature flag and forward it to cargo (can be stacked).
  • Split the PR into smaller pieces to make it easier to review.

@BD103 BD103 self-requested a review August 31, 2024 19:43
@BD103 BD103 added A-CLI Related to the main CLI C-Enhancement A general improvement labels Aug 31, 2024
}

/// Determine the name of the cargo package.
pub(crate) fn package_name() -> anyhow::Result<String> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This can potentially be replaced by parsing the output of the cargo metadata command

@janhohenheim
Copy link
Member

janhohenheim commented Aug 31, 2024

Can this run another binary than cargo? On Windows, you need to run cargo-clif in order to use cranelift.

@TimJentzsch
Copy link
Collaborator Author

Can this run another binary than cargo? On Windows, you need to run cargo-clif in order to use cranelift.

That's not supported at the moment, I wasn't aware of that.

BD103 pushed a commit that referenced this pull request Sep 14, 2024
…ts (#72)

With the `bevy build` and `bevy run` commands, we need to work quite a
lot with external CLI tools.

We often need to pass flags or options conditionally or add arguments
with a value, which is a lot easier with these utilities.

See #24 for more context.
BD103 pushed a commit that referenced this pull request Sep 19, 2024
Further work towards #24 

`wasm_bindgen` is used to generate JS bindings for the WASM executable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Related to the main CLI C-Enhancement A general improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants