From 1c15ac647af593bc83faf239ebe265095e9cf0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Thu, 2 May 2024 22:10:09 +0200 Subject: [PATCH] Example setup for tooling (#13088) # 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 --- Cargo.toml | 8 ++++++ examples/3d/meshlet.rs | 2 +- tools/example-showcase/src/main.rs | 46 +++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3e23ca0ee..340ab14a58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/examples/3d/meshlet.rs b/examples/3d/meshlet.rs index 722029feeb..ecd3201918 100644 --- a/examples/3d/meshlet.rs +++ b/examples/3d/meshlet.rs @@ -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() { diff --git a/tools/example-showcase/src/main.rs b/tools/example-showcase/src/main.rs index 3c5853b5eb..9bf9d72d74 100644 --- a/tools/example-showcase/src/main.rs +++ b/tools/example-showcase/src/main.rs @@ -276,6 +276,13 @@ fn main() { .map(|s| s.to_string()) .chain(required_features.iter().cloned()) .collect::>(); + + 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...}" @@ -726,18 +733,49 @@ fn parse_examples() -> Vec { .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, - name: String, - description: String, - category: String, - wasm: bool, + /// List of non default required features required_features: Vec, + + // 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, + /// List of commands to run before the example. Can be used for example to specify data to download + setup: Vec>, }