-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective Rework the detection of binaries again, aligning it closer to how Cargo works and enabling several new features / fixing several bugs. - Support multiple binaries in a single package - Support running examples (closes #69) - Fix detection of `target` folder location (closes #145) With this PR, we can now just run `bevy run --example breakout web` in the Bevy repo and it works without any additional configuration! # Solution The code previously made the wrong assumption that we want to run packages with a binary target. Instead, we want to run the binary targets itself. A package can even have multiple of them. Additionally, examples need to be considered as binary targets. The `--example` argument now needs to be factored into the detection algorithm and the different path for examples must be considered in the bundling step. ## Note for Reviewers The crux of the changes is contained in `run/mod.rs` in the `select_run_binary` function. This implements the new algorithm to select the correct binary to run. In `serve.rs`, the `index.html` file now needs to be generated dynamically, in order to pick the path to the correct binary. Because the `index.html` needs to be a _static_ string, it needs to be leaked to create a static reference.
- Loading branch information
1 parent
dbfb6fc
commit 4439e83
Showing
12 changed files
with
227 additions
and
125 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
use std::{path::Path, process::Command}; | ||
use std::process::Command; | ||
|
||
use crate::{external_cli::CommandHelpers, run::BinTarget}; | ||
|
||
use super::arg_builder::ArgBuilder; | ||
|
||
pub(crate) const PACKAGE: &str = "wasm-bindgen-cli"; | ||
pub(crate) const PROGRAM: &str = "wasm-bindgen"; | ||
|
||
/// Determine the path to the folder where the Wasm build artifacts are stored. | ||
pub(crate) fn get_target_folder(profile: &str) -> String { | ||
format!("target/wasm32-unknown-unknown/{profile}") | ||
} | ||
|
||
/// Bundle the Wasm build for the web. | ||
pub(crate) fn bundle(package_name: &str, profile: &str) -> anyhow::Result<()> { | ||
let target_folder = get_target_folder(profile); | ||
pub(crate) fn bundle(bin_target: &BinTarget) -> anyhow::Result<()> { | ||
let original_wasm = bin_target | ||
.artifact_directory | ||
.clone() | ||
.join(format!("{}.wasm", bin_target.bin_name)); | ||
|
||
let status = Command::new(PROGRAM) | ||
Command::new(PROGRAM) | ||
.args( | ||
ArgBuilder::new() | ||
.arg("--no-typescript") | ||
.add_with_value("--out-name", "bevy_app") | ||
.add_with_value("--out-dir", &target_folder) | ||
.add_with_value("--out-name", &bin_target.bin_name) | ||
.add_with_value("--out-dir", bin_target.artifact_directory.to_string_lossy()) | ||
.add_with_value("--target", "web") | ||
.arg(format!("{target_folder}/{package_name}.wasm")), | ||
.arg(original_wasm.to_string_lossy()), | ||
) | ||
.status()?; | ||
.ensure_status()?; | ||
|
||
anyhow::ensure!(status.success(), "Failed to bundle project for the web."); | ||
Ok(()) | ||
} | ||
|
||
/// Determine if a file path in the target folder is an artifact generated by wasm-bindgen. | ||
pub(crate) fn is_bindgen_artifact(path: &Path) -> bool { | ||
// The JS interface wrapping the WASM binary | ||
let js_path = Path::new("bevy_app.js"); | ||
// The WASM bindgen | ||
let wasm_path = Path::new("bevy_app_bg.wasm"); | ||
|
||
path == js_path || path == wasm_path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ | |
pub mod build; | ||
pub mod external_cli; | ||
pub mod lint; | ||
pub mod manifest; | ||
pub mod run; | ||
pub mod template; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.