diff --git a/.cargo/config.toml b/.cargo/config.toml index 9051a9f9f9..472a2df439 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,4 +2,4 @@ TARGET_DIR = { value = "target", relative = true } [alias] -xtask = "run --package xtask --" +xtask = "run --manifest-path xtask/Cargo.toml --package xtask --" diff --git a/Cargo.toml b/Cargo.toml index 05fbdb1e8e..e0402aa5e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,7 +115,6 @@ members = [ "crates/languages/bevy_mod_scripting_rhai", # "crates/languages/bevy_mod_scripting_rune", "crates/bevy_mod_scripting_functions", - "crates/xtask", "crates/testing_crates/test_utils", "crates/testing_crates/script_integration_test_harness", "crates/bevy_mod_scripting_derive", @@ -125,7 +124,7 @@ members = [ "crates/bevy_system_reflection", ] resolver = "2" -exclude = ["crates/bevy_api_gen", "crates/macro_tests"] +exclude = ["crates/bevy_api_gen", "crates/macro_tests", "xtask"] [profile.dev] debug = 1 diff --git a/check.ps1 b/check.ps1 index a13d9e24e2..d35ceac565 100644 --- a/check.ps1 +++ b/check.ps1 @@ -1,3 +1,16 @@ -#!/usr/bin/env pwsh -Set-Location -Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) -cargo xtask check --ide-mode \ No newline at end of file +#!/bin/bash +WORKSPACE_DIR="$PWD" + +cd "$(dirname "$0")" +# if the path is in /bevy_api_gen then we run the codegen check + +if [[ "$WORKSPACE_DIR" == *"/bevy_api_gen"* ]]; then + # save output to file as well as stdout and stderr + cargo xtask check --ide-mode --kind codegen +elif [[ "$WORKSPACE_DIR" == *"/xtask"* ]]; then + cd "$WORKSPACE_DIR" + cargo clippy --workspace --message-format=json --all-targets -- -D warnings +else + cd "$WORKSPACE_DIR" + cargo xtask check --ide-mode --kind main +fi \ No newline at end of file diff --git a/check.sh b/check.sh index 6f8685c45e..fe0c395440 100755 --- a/check.sh +++ b/check.sh @@ -1,3 +1,16 @@ #!/bin/bash +WORKSPACE_DIR="$PWD" + cd "$(dirname "$0")" -cargo xtask check --ide-mode +# if the path is in /bevy_api_gen then we run the codegen check + +if [[ "$WORKSPACE_DIR" == *"/bevy_api_gen"* ]]; then + # save output to file as well as stdout and stderr + cargo xtask check --ide-mode --kind codegen +elif [[ "$WORKSPACE_DIR" == *"/xtask"* ]]; then + cd "$WORKSPACE_DIR" + cargo check --quiet --workspace --message-format=json --all-targets +else + cd "$WORKSPACE_DIR" + cargo xtask check --ide-mode --kind main +fi \ No newline at end of file diff --git a/codegen_bevy_features.txt b/codegen_bevy_features.txt new file mode 100644 index 0000000000..a2c7467ad3 --- /dev/null +++ b/codegen_bevy_features.txt @@ -0,0 +1 @@ +bevy_asset,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded \ No newline at end of file diff --git a/crates/bevy_api_gen/src/passes/cache_traits.rs b/crates/bevy_api_gen/src/passes/cache_traits.rs index d912591165..1751f71400 100644 --- a/crates/bevy_api_gen/src/passes/cache_traits.rs +++ b/crates/bevy_api_gen/src/passes/cache_traits.rs @@ -8,7 +8,7 @@ use crate::{ DEF_PATHS_GET_TYPE_REGISTRATION, DEF_PATHS_REFLECT, STD_SOURCE_TRAITS, }; -fn dump_traits(tcx: &TyCtxt) -> String{ +fn dump_traits(tcx: &TyCtxt) -> String { let mut buffer = String::new(); for t in tcx.all_traits() { buffer.push_str(&tcx.def_path_str(t)); diff --git a/crates/xtask/Cargo.toml b/xtask/Cargo.toml similarity index 100% rename from crates/xtask/Cargo.toml rename to xtask/Cargo.toml diff --git a/crates/xtask/Dockerfile b/xtask/Dockerfile similarity index 100% rename from crates/xtask/Dockerfile rename to xtask/Dockerfile diff --git a/crates/xtask/chef.Dockerfile b/xtask/chef.Dockerfile similarity index 100% rename from crates/xtask/chef.Dockerfile rename to xtask/chef.Dockerfile diff --git a/crates/xtask/readme.md b/xtask/readme.md similarity index 100% rename from crates/xtask/readme.md rename to xtask/readme.md diff --git a/crates/xtask/src/main.rs b/xtask/src/main.rs similarity index 98% rename from crates/xtask/src/main.rs rename to xtask/src/main.rs index cfe7487c5b..36d2f76e66 100644 --- a/crates/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -598,6 +598,13 @@ struct CodegenTemplateArgs { self_is_bms_lua: bool, } +fn fetch_default_bevy_features() -> String { + let path = "codegen_bevy_features.txt"; + std::fs::read_to_string(path) + .with_context(|| format!("Failed to read default bevy features from {path}")) + .unwrap() +} + #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, clap::Subcommand, strum::AsRefStr)] #[clap( name = "xtask", @@ -677,7 +684,7 @@ enum Xtasks { #[clap( long, - default_value = "bevy_asset,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded", + default_value = fetch_default_bevy_features(), help = "The features to enable for the bevy crate" )] bevy_features: Vec, @@ -814,9 +821,10 @@ impl Xtasks { /// Reads the metadata from the main workspace fn main_workspace_cargo_metadata() -> Result { let cargo_manifest_path = std::env::var("MAIN_CARGO_MANIFEST_PATH").unwrap(); - + let path = PathBuf::from(cargo_manifest_path); + let parent_dir = path.parent().unwrap().parent().unwrap().join("Cargo.toml"); let mut cmd = cargo_metadata::MetadataCommand::new(); - cmd.manifest_path(cargo_manifest_path); + cmd.manifest_path(parent_dir.to_string_lossy().to_string()); let out = cmd.exec()?; Ok(out) } @@ -993,7 +1001,11 @@ impl Xtasks { if ide_mode { clippy_args.push("--message-format=json"); } - clippy_args.extend(vec!["--all-targets", "--", "-D", "warnings"]); + + let keep_going = std::env::var(XTASK_KEEP_GOING).is_ok(); + if !keep_going { + clippy_args.extend(vec!["--all-targets", "--", "-D", "warnings"]); + } Self::run_workspace_command( &app_settings, @@ -1035,7 +1047,11 @@ impl Xtasks { if ide_mode { clippy_args.push("--message-format=json"); } - clippy_args.extend(vec!["--all-targets", "--", "-D", "warnings"]); + + let keep_going = std::env::var(XTASK_KEEP_GOING).is_ok(); + if !keep_going { + clippy_args.extend(vec!["--all-targets", "--", "-D", "warnings"]); + } Self::run_workspace_command( &app_settings, @@ -1211,6 +1227,10 @@ impl Xtasks { } fn check(app_settings: GlobalArgs, ide_mode: bool, kind: CheckKind) -> Result<()> { + if ide_mode && kind == CheckKind::All { + bail!("Ide mode should not be used with 'all' check kind, each workspace needs to have each own individual check, for toolchains to be properly supported"); + } + match kind { CheckKind::All => { let err_main = Self::check_main_workspace(app_settings.clone(), ide_mode); @@ -2017,7 +2037,9 @@ fn try_main() -> Result<()> { pretty_env_logger::formatted_builder() .filter_level(LevelFilter::Info) .init(); + pop_cargo_env()?; + let args = App::try_parse()?; info!( "Default toolchain: {:?}", @@ -2033,6 +2055,8 @@ fn try_main() -> Result<()> { Ok(()) } +const XTASK_KEEP_GOING: &str = "XTASK_KEEP_GOING"; + fn main() { if let Err(e) = try_main() { eprintln!("{e:?}"); diff --git a/crates/xtask/templates/settings.json.tera b/xtask/templates/settings.json.tera similarity index 56% rename from crates/xtask/templates/settings.json.tera rename to xtask/templates/settings.json.tera index e7927a91e7..29f520a33e 100644 --- a/crates/xtask/templates/settings.json.tera +++ b/xtask/templates/settings.json.tera @@ -2,10 +2,15 @@ "rust-analyzer.rustc.source": "discover", "rust-analyzer.linkedProjects": [ "{{ dir }}/crates/bevy_api_gen/Cargo.toml", - "Cargo.toml" + "Cargo.toml", + "xtask/Cargo.toml" ], "rust-analyzer.check.invocationStrategy": "per_workspace", "rust-analyzer.check.overrideCommand": [ "{{ dir }}/check.sh" + ], + "rust-analyzer.cargo.buildScripts.invocationStrategy": "per_workspace", + "rust-analyzer.cargo.buildScripts.overrideCommand": [ + "{{ dir }}/check.sh" ] } \ No newline at end of file