Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,51 +151,51 @@ bevy_mod_scripting_world = { path = "crates/bevy_mod_scripting_world", version =
# bevy


bevy = { version = "0.18", default-features = false }
bevy_math = { version = "0.18", default-features = false, features = ["std"] }
bevy_transform = { version = "0.18", default-features = false }
bevy_reflect = { version = "0.18", default-features = false }
bevy_ecs = { version = "0.18", default-features = false }
bevy_asset = { version = "0.18", default-features = false }
bevy_app = { version = "0.18", default-features = false }
bevy_log = { version = "0.18", default-features = false }
bevy_internal = { version = "0.18", default-features = false }
bevy_diagnostic = { version = "0.18", default-features = false }
bevy_platform = { version = "0.18", default-features = false }
bevy_time = { version = "0.18", default-features = false }
bevy_input = { version = "0.18", default-features = false }
bevy_a11y = { version = "0.18", default-features = false, features = [
bevy = { version = "0.19", default-features = false }
bevy_math = { version = "0.19", default-features = false, features = ["std"] }
bevy_transform = { version = "0.19", default-features = false }
bevy_reflect = { version = "0.19", default-features = false }
bevy_ecs = { version = "0.19", default-features = false }
bevy_asset = { version = "0.19", default-features = false }
bevy_app = { version = "0.19", default-features = false }
bevy_log = { version = "0.19", default-features = false }
bevy_internal = { version = "0.19", default-features = false }
bevy_diagnostic = { version = "0.19", default-features = false }
bevy_platform = { version = "0.19", default-features = false }
bevy_time = { version = "0.19", default-features = false }
bevy_input = { version = "0.19", default-features = false }
bevy_a11y = { version = "0.19", default-features = false, features = [
"std",
"bevy_reflect",
] }
bevy_animation = { version = "0.18", default-features = false }
bevy_color = { version = "0.18", default-features = false, features = [
bevy_animation = { version = "0.19", default-features = false }
bevy_color = { version = "0.19", default-features = false, features = [
"std",
"bevy_reflect",
] }
bevy_core_pipeline = { version = "0.18", default-features = false }
bevy_gizmos = { version = "0.18", default-features = false }
bevy_gltf = { version = "0.18", default-features = false }
bevy_image = { version = "0.18", default-features = false, features = [
bevy_core_pipeline = { version = "0.19", default-features = false }
bevy_gizmos = { version = "0.19", default-features = false }
bevy_gltf = { version = "0.19", default-features = false }
bevy_image = { version = "0.19", default-features = false, features = [
"bevy_reflect",
] }
bevy_input_focus = { version = "0.18", default-features = false, features = [
bevy_input_focus = { version = "0.19", default-features = false, features = [
"std",
"bevy_reflect",
] }
bevy_mesh = { version = "0.18", default-features = false }
bevy_pbr = { version = "0.18", default-features = false }
bevy_picking = { version = "0.18", default-features = false }
bevy_render = { version = "0.18", default-features = false }
bevy_scene = { version = "0.18", default-features = false }
bevy_sprite = { version = "0.18", default-features = false }
bevy_text = { version = "0.18", default-features = false }
bevy_window = { version = "0.18", default-features = false, features = [
bevy_mesh = { version = "0.19", default-features = false }
bevy_pbr = { version = "0.19", default-features = false }
bevy_picking = { version = "0.19", default-features = false }
bevy_render = { version = "0.19", default-features = false }
bevy_scene = { version = "0.19", default-features = false }
bevy_sprite = { version = "0.19", default-features = false }
bevy_text = { version = "0.19", default-features = false }
bevy_window = { version = "0.19", default-features = false, features = [
"bevy_reflect",
"std",
] }
bevy_winit = { version = "0.18", default-features = false }
bevy_utils = { version = "0.18", default-features = false, features = ["std"] }
bevy_winit = { version = "0.19", default-features = false }
bevy_utils = { version = "0.19", default-features = false, features = ["std"] }

glam = { version = "0.30.10", default-features = false }
uuid = { version = "1.13", default-features = false }
Expand All @@ -216,7 +216,7 @@ parking_lot = { version = "0.12.1", default-features = false }
strum = { version = "0.26", default-features = false }
rhai = { version = "1.21", default-features = false }
mlua = { version = "0.11", default-features = false }
log = { version = "0.4", default-features = false }
log = { version = "0.4.33", default-features = false }
env_logger = { version = "0.11", default-features = false }
clap = { version = "4", default-features = false, features = ["std"] }
mdbook-preprocessor = { version = "0.5", default-features = false }
Expand All @@ -237,7 +237,7 @@ pretty_assertions = { version = "1.4", default-features = false, features = [
manifest-dir-macros = { version = "0.1.18", default-features = false }
assert_cmd = { version = "2.1", default-features = false }
tokio = { version = "1", default-features = false }
bevy_console = { version = "0.17.1", default-features = false }
bevy_console = { git="https://github.com/makspll/bevy-console", default-features = false }
tracing-tracy = { version = "0.11", default-features = false }
libtest-mimic = { version = "0.8", default-features = false }
criterion = { version = "0.5", default-features = false }
Expand Down
15 changes: 8 additions & 7 deletions assets/scripts/game_of_life.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LifeState = world.get_type_by_name("LifeState")
Settings = world.get_type_by_name("Settings")

info("Lua: The game_of_life.lua script just got loaded")
log_warn("Lua: The game_of_life.lua script just got loaded")
math.randomseed(os.time())

function fetch_life_state()
Expand All @@ -11,8 +11,8 @@ function fetch_life_state()
end

function on_script_loaded()
info("Lua: Hello! I am initiating the game of life simulation state with randomness!")
info("Lua: Click on the screen to set cells alive after running the `gol start` command")
log_warn("Lua: Hello! I am initiating the game of life simulation state with randomness!")
log_warn("Lua: Click on the screen to set cells alive after running the `gol start` command")

local life_state = fetch_life_state()

Expand All @@ -27,12 +27,10 @@ end

function on_click(x, y)
-- get the settings
info("Lua: Clicked at x: " .. x .. " y: " .. y)
log_warn("Lua: Clicked at x: " .. x .. " y: " .. y)
local life_state = fetch_life_state()
local cells = life_state.cells

local settings = world.get_resource(Settings)

local dimensions = settings.physical_grid_dimensions
local screen = settings.display_grid_dimensions

Expand All @@ -42,11 +40,14 @@ function on_click(x, y)
local screen_x = screen[1]
local screen_y = screen[2]


local cell_width = screen_x / dimension_x
local cell_height = screen_y / dimension_y

local cell_x = math.floor(x / cell_width)
local cell_y = math.floor(y / cell_height)
print(x, y)
print(screen_x, screen_y)

local index = (cell_y * dimension_x) + cell_x

Expand Down Expand Up @@ -110,7 +111,7 @@ function on_update()
end

function on_script_unloaded()
info("Lua: I am being unloaded, goodbye!")
log_warn("Lua: I am being unloaded, goodbye!")

-- set state to 0's
local life_state = fetch_life_state()
Expand Down
25 changes: 12 additions & 13 deletions check.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/bin/bash
WORKSPACE_DIR="$PWD"
$WORKSPACE_DIR = Get-Location

cd "$(dirname "$0")"
# if the path is in /bevy_api_gen then we run the codegen check
Set-Location $PSScriptRoot

if [[ "$WORKSPACE_DIR" == *"/bevy_api_gen"* ]]; then
# save output to file as well as stdout and stderr
if ($WORKSPACE_DIR -like "*\codegen*") {
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
}
elseif ($WORKSPACE_DIR -like "*\xtask*") {
Set-Location $WORKSPACE_DIR
cargo check --quiet --workspace --message-format=json --all-targets
}
else {
Set-Location $WORKSPACE_DIR
cargo xtask check --ide-mode --kind main
}
2 changes: 1 addition & 1 deletion codegen/Cargo.bootstrap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2024"

[dependencies]
bevy_mod_scripting_bindings = { path = "{{BMS_BINDINGS_PATH}}" }
bevy_reflect = { version = "0.18", features = [
bevy_reflect = { version = "0.19", features = [
"smol_str",
"glam",
"petgraph",
Expand Down
15 changes: 11 additions & 4 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ include = [
]

[workspace]
members = ["crates/crate_feature_graph"]
members = ["crates/bevy_mod_scripting_rustc_driver","crates/bevy_mod_scripting_rustc_utils","crates/crate_feature_graph", "crates/test_crates/rust_lib_tests"]
exclude = [
"crates/test_crates/workspace/root",
"crates/test_crates/workspace/crate_a",
"crates/test_crates/workspace/crate_b",
"crates/test_crates/**"
]

[[bin]]
Expand All @@ -44,12 +45,16 @@ rustc_private = true

[workspace.dependencies]
crate_feature_graph = { path = "crates/crate_feature_graph", version = "0.1" }
bevy_mod_scripting_rustc_utils = { path = "crates/bevy_mod_scripting_rustc_utils", version = "0.1" }
bevy_mod_scripting_rustc_driver = { path = "crates/bevy_mod_scripting_rustc_driver", version = "0.1" }

assert_cmd = { version = "2.1", default-features = false }
petgraph = { version = "0.8" }
log = "0.4"
env_logger = "0.11"
pretty_env_logger = "0.4"
indexmap = "2"
cargo_metadata = "0.18"
cargo_metadata = "0.23"
serde_json = "1"
serde = "1"
clap = { version = "4", features = ["derive", "string"] }
Expand All @@ -65,6 +70,9 @@ pretty_assertions = "1.3"

[dependencies]
crate_feature_graph = { workspace = true, features = ["dot_parser", "serde"] }
bevy_mod_scripting_rustc_driver = { workspace = true }
bevy_mod_scripting_rustc_utils = { workspace = true }

clap = { workspace = true }
tera = { workspace = true }
strum = { workspace = true }
Expand All @@ -82,5 +90,4 @@ prettyplease = { workspace = true }
convert_case = { workspace = true }
chrono = { workspace = true }

[build-dependencies]
toml = "0.8"

16 changes: 16 additions & 0 deletions codegen/crates/bevy_mod_scripting_rustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "bevy_mod_scripting_rustc_driver"
version = "0.1.0"
edition = "2024"

[package.metadata.rust-analyzer]
rustc_private = true

[dependencies]
cargo_metadata = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
log = { workspace = true }

[build-dependencies]
toml = "0.8"
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn target_libdir(rustc: &Path) -> PathBuf {

pub fn main() {
// Use to set RUSTC_CHANNEL so we can compute target dir from rustc_plugin
let toolchain_toml = include_str!("rust-toolchain.toml");
let toolchain_toml = include_str!("../../rust-toolchain.toml");
let toolchain_table = toolchain_toml.parse::<toml::Table>().unwrap();
let toolchain = toolchain_table["toolchain"].as_table().unwrap();
let channel = toolchain["channel"].as_str().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#![feature(rustc_private)]
#![deny(rustc::internal)]

//! The module dealing with how the CLI interacts with each instantiation of the
//! plugin across the workspace.

mod plugin;
extern crate rustc_session;
extern crate rustc_driver;
extern crate rustc_driver_impl;

use std::{
env,
ops::Deref,
path::{Path, PathBuf},
process::{Command, Stdio, exit},
process::{Command, ExitCode, Stdio, exit},
};

use cargo_metadata::{Metadata, camino::Utf8PathBuf};
Expand All @@ -17,6 +23,8 @@ use rustc_session::{EarlyDiagCtxt, config::ErrorOutputType};
pub const CRATES_TO_RUN_PLUGIN_ON_ENV: &str = "CRATES_TO_RUN_PLUGIN_ON";
pub const CARGO_VERBOSE: &str = "CARGO_VERBOSE";
pub const WORKSPACE_GRAPH_FILE_ENV: &str = "WORKSPACE_GRAPH_FILE";
/// The rustc toolchain this crate was built with and needs to work with
pub const CHANNEL: &str = env!("RUSTC_CHANNEL");

pub fn fetch_target_directory(metadata: &Metadata) -> Utf8PathBuf {
let plugin_subdir = format!("plugin-{}", crate::CHANNEL);
Expand Down Expand Up @@ -58,7 +66,7 @@ pub fn cli_main<T: RustcPlugin>(plugin: T, include_crates: Vec<String>, metadata

cmd.env(CRATES_TO_RUN_PLUGIN_ON_ENV, include_crates.join(","));

let args_str = serde_json::to_string(&args.args).unwrap();
let args_str = serde_json::to_string::<RustcPluginArgs<T::Args>>(&args).unwrap();
log::debug!("{PLUGIN_ARGS}={args_str}");
cmd.env(PLUGIN_ARGS, args_str);

Expand All @@ -69,6 +77,21 @@ pub fn cli_main<T: RustcPlugin>(plugin: T, include_crates: Vec<String>, metadata
exit(exit_status.code().unwrap_or(-1));
}


pub fn copy_command_without_args(
cmd: &std::process::Command,
arg_filter: &[&str],
) -> std::process::Command {
let mut new_cmd = std::process::Command::new(cmd.get_program());
new_cmd.args(
cmd.get_args()
.filter(|a| !arg_filter.iter().any(|f| f == a)),
);
new_cmd.envs(cmd.get_envs().filter_map(|(a, b)| b.map(|b| (a, b))));
new_cmd
}


// use std::{
// env,
// ops::Deref,
Expand Down Expand Up @@ -169,18 +192,18 @@ struct DefaultCallbacks;
impl rustc_driver::Callbacks for DefaultCallbacks {}

/// The top-level function that should be called by your internal driver binary.
pub fn driver_main<T: RustcPlugin>(plugin: T) {
pub fn driver_main<T: RustcPlugin>(plugin: T) -> ExitCode {
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
rustc_driver::init_rustc_env_logger(&early_dcx);

exit(rustc_driver::catch_with_exit_code(move || {
rustc_driver::catch_with_exit_code(move || {
let mut orig_args: Vec<String> = env::args().collect();

let (have_sys_root_arg, sys_root) = get_sysroot(&orig_args);

if orig_args.iter().any(|a| a == "--version" || a == "-V") {
println!("{}", plugin.version());
exit(0);
return ExitCode::SUCCESS;
}

// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
Expand Down Expand Up @@ -209,8 +232,11 @@ pub fn driver_main<T: RustcPlugin>(plugin: T) {
.as_ref()
.map(|s| s.to_string())
.unwrap_or_default();

let plugin_args: Result<RustcPluginArgs<T::Args>, _> =
serde_json::from_str(&env::var(PLUGIN_ARGS).unwrap_or_default());
let is_target_crate = env::var(CRATES_TO_RUN_PLUGIN_ON_ENV)
.is_ok_and(|crates| crates.split(',').any(|c| c == crate_being_built));
.is_ok_and(|crates| crates.split(',').any(|c| c == crate_being_built)) || plugin_args.as_ref().is_ok_and(|plugin_args| matches!(plugin_args.filter, CrateFilter::AllCrates));
let normal_rustc = arg_value(&args, "--print", |_| true).is_some();

let run_plugin = !normal_rustc && is_target_crate;
Expand All @@ -220,9 +246,7 @@ pub fn driver_main<T: RustcPlugin>(plugin: T) {
// args.extend([String::from("--cap-lints"), String::from("warn")]);
if run_plugin {
log::debug!("Running plugin on crate: {crate_being_built}");
let plugin_args: T::Args =
serde_json::from_str(&env::var(PLUGIN_ARGS).unwrap()).unwrap();
plugin.run(args, plugin_args);
plugin.run(args, plugin_args.unwrap());
} else {
log::debug!(
"Running normal Rust. Relevant variables:\
Expand All @@ -232,5 +256,6 @@ primary_package={primary_package}"
);
rustc_driver_impl::run_compiler(&args, &mut DefaultCallbacks);
}
}))
ExitCode::SUCCESS
})
}
Loading
Loading