Skip to content

Commit

Permalink
Example setup for tooling (#13088)
Browse files Browse the repository at this point in the history
# Objective

- #12755 introduced the need to download a file to run an example
- This means the example fails to run in CI without downloading that
file

## Solution

- Add a new metadata to examples "setup" that provides setup
instructions
- Replace the URL in the meshlet example to one that can actually be
downloaded
- example-showcase execute the setup before running an example
  • Loading branch information
mockersf authored May 2, 2024
1 parent 5ee1b40 commit 1c15ac6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,14 @@ name = "Meshlet"
description = "Meshlet rendering for dense high-poly scenes (experimental)"
category = "3D Rendering"
wasm = false
setup = [
[
"curl",
"-o",
"assets/models/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/bd869887bc5c9c6e74e353f657d342bef84bacd8/bunny.meshlet_mesh",
],
]

[[example]]
name = "lightmaps"
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/meshlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy::{
use camera_controller::{CameraController, CameraControllerPlugin};
use std::{f32::consts::PI, path::Path, process::ExitCode};

const ASSET_URL: &str = "https://github.com/JMS55/bevy_meshlet_asset/blob/bd869887bc5c9c6e74e353f657d342bef84bacd8/bunny.meshlet_mesh";
const ASSET_URL: &str = "https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/bd869887bc5c9c6e74e353f657d342bef84bacd8/bunny.meshlet_mesh";

fn main() -> ExitCode {
if !Path::new("./assets/models/bunny.meshlet_mesh").exists() {
Expand Down
40 changes: 39 additions & 1 deletion tools/example-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ fn main() {
.map(|s| s.to_string())
.chain(required_features.iter().cloned())
.collect::<Vec<_>>();

for command in &to_run.setup {
let exe = &command[0];
let args = &command[1..];
cmd!(sh, "{exe} {args...}").run().unwrap();
}

let _ = cmd!(
sh,
"cargo build --profile {profile} --example {example} {local_extra_parameters...}"
Expand Down Expand Up @@ -726,18 +733,49 @@ fn parse_examples() -> Vec<Example> {
.collect()
})
.unwrap_or_default(),
setup: metadata
.get("setup")
.map(|setup| {
setup
.as_array()
.unwrap()
.into_iter()
.map(|v| {
v.as_array()
.unwrap()
.into_iter()
.map(|v| v.as_str().unwrap().to_string())
.collect()
})
.collect()
})
.unwrap_or_default(),
})
})
.collect()
}

/// Data for this struct comes from both the entry for an example in the Cargo.toml file, and its associated metadata.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
struct Example {
// From the example entry
/// Name of the example, used to start it from the cargo CLI with `--example`
technical_name: String,
/// Path to the example file
path: String,
/// List of non default required features
required_features: Vec<String>,

// From the example metadata
/// Pretty name, used for display
name: String,
/// Description of the example, for discoverability
description: String,
/// Pretty category name, matching the folder containing the example
category: String,
/// Does this example work in wasm?
// TODO: be able to differentiate between WebGL2, WebGPU, both, or neither (for examples that could run on wasm without a renderer)
wasm: bool,
required_features: Vec<String>,
/// List of commands to run before the example. Can be used for example to specify data to download
setup: Vec<Vec<String>>,
}

0 comments on commit 1c15ac6

Please sign in to comment.