TheBevyFlock / bevy_cli

A Bevy CLI tool and linter.
https://thebevyflock.github.io/bevy_cli/
Apache License 2.0
44 stars 7 forks source link

Rework binary detection #169

Open TimJentzsch opened 3 weeks ago

TimJentzsch commented 3 weeks ago

Objective

Rework the detection of binaries again, aligning it closer to how Cargo works and enabling several new features / fixing several bugs.

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.