Skip to content

Commit

Permalink
Bevy 0.15 Support (#139)
Browse files Browse the repository at this point in the history
* bump bevy to 0.15.0-rc.2

* migrate asset loaders

* Upgrade reflection API's

* bump codegen & codegen new files

* Fix errors + regen

* pin git again

* fix more errors

* bump macro tests

* clippy fixes to bevy api gen

* more bevy api gen clippy fixes

* Update game of life examples

* fix clippy

* fix more clippy

* fix more clippy

* bump versions to alpha
  • Loading branch information
makspll authored Nov 9, 2024
1 parent 99460d1 commit 5d7d7c9
Show file tree
Hide file tree
Showing 50 changed files with 7,903 additions and 4,293 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/bevy_api_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-05-20
toolchain: nightly-2024-11-05
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.3
Expand All @@ -52,7 +52,7 @@ jobs:
with:
profile: minimal
components: rustfmt
toolchain: nightly-2024-05-20
toolchain: nightly-2024-11-05
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.3
Expand All @@ -75,7 +75,7 @@ jobs:
rm -rf crates
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-05-20
toolchain: nightly-2024-11-05
components: clippy
override: true
- name: Rust Cache
Expand All @@ -98,7 +98,7 @@ jobs:
rm -rf crates
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-05-20
toolchain: nightly-2024-11-05
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.3
Expand All @@ -120,7 +120,7 @@ jobs:
rm -rf crates
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-05-20
toolchain: nightly-2024-11-05
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.3
Expand Down
55 changes: 28 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting"
version = "0.7.1"
version = "0.8.0-alpha.0"
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -63,16 +63,16 @@ rune = ["bevy_mod_scripting_rune"]
[dependencies]
bevy = { workspace = true }
bevy_mod_scripting_core = { workspace = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.7.1", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.7.1", optional = true }
bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.7.1", optional = true }
bevy_script_api = { path = "crates/bevy_script_api", version = "0.7.1", optional = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.8.0-alpha.0", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.8.0-alpha.0", optional = true }
bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.8.0-alpha.0", optional = true }
bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.0", optional = true }


[workspace.dependencies]
bevy = { version = "0.14.2", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.7.1" }
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.7.1" }
bevy = { version = "0.15.0-rc.2", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.8.0-alpha.0" }
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.8.0-alpha.0" }

[dev-dependencies]
bevy = { workspace = true, default-features = true }
Expand Down Expand Up @@ -111,25 +111,26 @@ codegen-units = 8
incremental = false
debug = false

[[example]]
name = "console_integration_lua"
path = "examples/lua/console_integration.rs"
required-features = [
"lua54",
"lua_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]

[[example]]
name = "console_integration_rhai"
path = "examples/rhai/console_integration.rs"
required-features = [
"rhai",
"rhai_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]
# TODO: bump once bevy is released and the lib is updated
# [[example]]
# name = "console_integration_lua"
# path = "examples/lua/console_integration.rs"
# required-features = [
# "lua54",
# "lua_script_api",
# "bevy/file_watcher",
# "bevy/multi_threaded",
# ]

# [[example]]
# name = "console_integration_rhai"
# path = "examples/rhai/console_integration.rs"
# required-features = [
# "rhai",
# "rhai_script_api",
# "bevy/file_watcher",
# "bevy/multi_threaded",
# ]

[[example]]
name = "complex_game_loop_lua"
Expand Down
2 changes: 1 addition & 1 deletion check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CURRENT_DIR=$(basename "$PWD")


if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then
cargo +nightly-2024-05-20 clippy --all-targets --message-format=json
cargo +nightly-2024-11-05 clippy --all-targets --message-format=json
else
cargo clippy --workspace --all-targets --message-format=json --features="lua54 lua_script_api rhai rhai_script_api teal rune bevy/file_watcher bevy/multi_threaded"
fi
5 changes: 2 additions & 3 deletions crates/bevy_api_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ source = "discover"
rustc_private = true

[rust-analyzer.check]
overrideCommand = ["cargo", "+nightly-2024-05-20", "a", "--message-format=json"]
overrideCommand = ["cargo", "+nightly-2024-11-05", "a", "--message-format=json"]


[dependencies]
log = "0.4"
env_logger = "0.11"
rustc_plugin = "=0.10.0-nightly-2024-05-20"
rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" }
indexmap = "2"
tempdir = "0.3"
cargo_metadata = "0.18"
rustc_data_structures = "0.0.1"
serde_json = "1"
serde = "1"
clap = { version = "4", features = ["derive", "string"] }
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_api_gen/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bevy_api_gen is a Cargo plugin that generates reflection-powered wrappers for Be
To install bevy_api_gen, use the following command:

```bash
cargo +nightly-2024-05-20 install bevy_api_gen
cargo +nightly-2024-11-05 install bevy_api_gen
```

# Usage
Expand All @@ -18,39 +18,39 @@ cargo +nightly-2024-05-20 install bevy_api_gen
To run the main codegen process, use the following command:

```bash
cargo +nightly-2024-05-20 bevy-api-gen generate
cargo +nightly-2024-11-05 bevy-api-gen generate
```

This will perform all parts of the process and generate meta as well as .rs files for each crate in your workspace in your `/target/plugin-nightly-2024-05-20/bevy_api_gen` directory
This will perform all parts of the process and generate meta as well as .rs files for each crate in your workspace in your `/target/plugin-nightly-2024-11-05/bevy_api_gen` directory

## Collect

After generating all the files, you can 'collect' them in a mod.rs file like so:

```bash
cargo +nightly-2024-05-20 bevy-api-gen collect
cargo +nightly-2024-11-05 bevy-api-gen collect
```

## List Types

To see a list of all `Reflect` implementing types in your workspace run:

```bash
cargo +nightly-2024-05-20 bevy-api-gen list-types > all_types.txt
cargo +nightly-2024-11-05 bevy-api-gen list-types > all_types.txt
```

## List Templates

To see the list of all templates which you can override use:

```bash
cargo +nightly-2024-05-20 bevy-api-gen list-templates
cargo +nightly-2024-11-05 bevy-api-gen list-templates
```

## Print Template

You can also print any of the templates to stdout:

```bash
cargo +nightly-2024-05-20 bevy-api-gen print item.tera
cargo +nightly-2024-11-05 bevy-api-gen print item.tera
```
2 changes: 1 addition & 1 deletion crates/bevy_api_gen/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
components = ["clippy", "rust-src", "rustc-dev", "llvm-tools"]
channel = "nightly-2024-05-20"
channel = "nightly-2024-11-05"
1 change: 1 addition & 0 deletions crates/bevy_api_gen/src/bin/driver.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(rustc_private)]
use bevy_api_gen::*;

fn main() {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_api_gen/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(rustc_private)]
use std::{
collections::HashMap,
env,
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_api_gen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ impl CachedTraits {
.all(|t| self.std_source_traits.contains_key(*t))
}

pub(crate) fn missing_std_source_traits(&self) -> Vec<String> {
STD_SOURCE_TRAITS
.iter()
.filter(|t| !self.std_source_traits.contains_key(**t))
.map(|s| (*s).to_owned())
.collect()
}
// pub(crate) fn missing_std_source_traits(&self) -> Vec<String> {
// STD_SOURCE_TRAITS
// .iter()
// .filter(|t| !self.std_source_traits.contains_key(**t))
// .map(|s| (*s).to_owned())
// .collect()
// }
}

#[derive(Clone, Debug)]
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_api_gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#![feature(rustc_private, let_chains)]
#![deny(rustc::internal)]

extern crate rustc_ast;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_hir;
extern crate rustc_hir_analysis;
extern crate rustc_infer;
extern crate rustc_interface;
extern crate rustc_lint;
extern crate rustc_middle;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_trait_selection;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_api_gen/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl MetaLoader {
let cache = self.cache.borrow();
if cache.contains_key(crate_name) {
trace!("Loading meta from cache for: {}", crate_name);
return cache.get(crate_name).cloned();
cache.get(crate_name).cloned()
} else {
trace!("Loading meta from filesystem for: {}", crate_name);
drop(cache);
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_api_gen/src/modifying_file_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::io;
use std::{
io,
sync::atomic::{AtomicBool, Ordering},
};

use log::trace;
use rustc_data_structures::sync::{AtomicBool, Lrc, Ordering};
use rustc_middle::ty::data_structures::Lrc;
// use rustc_data_structures::sync::{AtomicBool, Lrc};
use rustc_span::source_map::{FileLoader, RealFileLoader};

/// Injects extern statements into the first loaded file (crate root)
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_api_gen/src/passes/cache_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ pub(crate) fn cache_traits(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool {
.join(", ")
);

panic!(
"Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?",
ctxt.cached_traits.missing_std_source_traits().join(", "),
tcx.crate_name(LOCAL_CRATE)
)
// TODO: figure out why some crates are missing std::fmt::Display etc
// panic!(
// "Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?",
// ctxt.cached_traits.missing_std_source_traits().join(", "),
// tcx.crate_name(LOCAL_CRATE)
// )
}

true
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_api_gen/src/passes/find_methods_and_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use rustc_hir::{
Safety,
};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::ty::{AdtKind, AssocKind, FieldDef, FnSig, ParamEnv, Ty, TyCtxt, TyKind};
use rustc_middle::ty::{
AdtKind, AssocKind, FieldDef, FnSig, ParamEnv, Ty, TyCtxt, TyKind, TypingMode,
};
use rustc_span::Symbol;
use rustc_trait_selection::infer::InferCtxtExt;

Expand Down Expand Up @@ -86,7 +88,6 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) ->
let mut all_impls = ctxt
.tcx
.inherent_impls(def_id)
.unwrap()
.iter()
.chain(trait_impls_for_ty.iter().flatten())
.collect::<Vec<_>>();
Expand Down Expand Up @@ -390,7 +391,7 @@ fn type_is_supported_as_non_proxy_return_val<'tcx>(
) -> bool {
trace!("Checkign type is supported as non proxy return val: '{ty:?}' with param_env: '{param_env:?}'");
if let TyKind::Ref(region, _, _) = ty.kind() {
if !region.get_name().is_some_and(|rn| rn.as_str() == "'static") {
if region.get_name().is_none_or(|rn| rn.as_str() != "'static") {
return false;
}
}
Expand All @@ -410,7 +411,7 @@ pub(crate) fn impls_trait<'tcx>(
trait_did: DefId,
) -> bool {
tcx.infer_ctxt()
.build()
.build(TypingMode::non_body_analysis())
.type_implements_trait(trait_did, [ty], param_env)
.must_apply_modulo_regions()
}
4 changes: 2 additions & 2 deletions crates/bevy_api_gen/src/passes/find_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_infer::{
infer::{InferCtxt, TyCtxtInferExt},
traits::{Obligation, ObligationCause},
};
use rustc_middle::ty::Ty;
use rustc_middle::ty::{Ty, TypingMode};
use rustc_span::DUMMY_SP;
use rustc_trait_selection::traits::ObligationCtxt;

Expand Down Expand Up @@ -105,7 +105,7 @@ fn type_impl_of_trait(
//TODO: false negatives coming from this inference

let ty = tcx.type_of(reflect_ty_did).instantiate_identity();
let infcx = tcx.infer_ctxt().build();
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let result = impl_matches(&infcx, ty, impl_did);
log::trace!("Result: {:#?}", result);
if result {
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_api_gen/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ pub(crate) fn configure_tera_env(tera: &mut Tera, crate_name: &str) {

let file = syn::parse_file(&str)
.map_err(|e| tera::Error::msg(e.to_string()))
.map_err(|e| {
.inspect_err(|_| {
log::error!("prettyplease error on input: ```\n{}\n```", str);
e
})?;

let out = prettyplease::unparse(&file);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_event_priority/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_event_priority"
version = "0.7.1"
version = "0.8.0-alpha.0"
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_common"
version = "0.7.1"
version = "0.8.0-alpha.0"
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
Loading

0 comments on commit 5d7d7c9

Please sign in to comment.