Skip to content

Commit 34164ed

Browse files
authored
Merge branch 'main' into feature/bevy-system-refactor
2 parents 48cc5b8 + efa4115 commit 34164ed

File tree

11 files changed

+73
-25
lines changed

11 files changed

+73
-25
lines changed

crates/bevy_api_gen/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ source = "discover"
3636
[package.metadata.rust-analyzer]
3737
rustc_private = true
3838

39-
4039
[dependencies]
41-
rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" }
42-
indexmap = "2"
4340
log = "0.4"
4441
env_logger = "0.11"
42+
rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" }
43+
indexmap = "2"
4544
tempdir = "0.3"
4645
cargo_metadata = "0.18"
4746
serde_json = "1"

crates/bevy_api_gen/readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bevy_api_gen is a Cargo plugin that generates reflection-powered wrappers for Be
88
To install bevy_api_gen, use the following command:
99

1010
```bash
11-
cargo +nightly-2024-01-24 install bevy_api_gen
11+
cargo +nightly-2024-11-05 install bevy_api_gen
1212
```
1313

1414
# Usage
@@ -18,39 +18,39 @@ cargo +nightly-2024-01-24 install bevy_api_gen
1818
To run the main codegen process, use the following command:
1919

2020
```bash
21-
cargo +nightly-2024-01-24 bevy-api-gen generate
21+
cargo +nightly-2024-11-05 bevy-api-gen generate
2222
```
2323

24-
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-01-24/bevy_api_gen` directory
24+
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
2525

2626
## Collect
2727

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

3030
```bash
31-
cargo +nightly-2024-01-24 bevy-api-gen collect
31+
cargo +nightly-2024-11-05 bevy-api-gen collect
3232
```
3333

3434
## List Types
3535

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

3838
```bash
39-
cargo +nightly-2024-01-24 bevy-api-gen list-types > all_types.txt
39+
cargo +nightly-2024-11-05 bevy-api-gen list-types > all_types.txt
4040
```
4141

4242
## List Templates
4343

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

4646
```bash
47-
cargo +nightly-2024-01-24 bevy-api-gen list-templates
47+
cargo +nightly-2024-11-05 bevy-api-gen list-templates
4848
```
4949

5050
## Print Template
5151

5252
You can also print any of the templates to stdout:
5353

5454
```bash
55-
cargo +nightly-2024-01-24 bevy-api-gen print item.tera
55+
cargo +nightly-2024-11-05 bevy-api-gen print item.tera
5656
```

crates/bevy_api_gen/src/bin/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(rustc_private)]
2-
32
use std::{
43
collections::HashMap,
54
env,

crates/bevy_api_gen/src/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ impl CachedTraits {
139139
.all(|t| self.std_source_traits.contains_key(*t))
140140
}
141141

142-
pub(crate) fn missing_std_source_traits(&self) -> Vec<String> {
143-
STD_SOURCE_TRAITS
144-
.iter()
145-
.filter(|t| !self.std_source_traits.contains_key(**t))
146-
.map(|s| (*s).to_owned())
147-
.collect()
148-
}
142+
// pub(crate) fn missing_std_source_traits(&self) -> Vec<String> {
143+
// STD_SOURCE_TRAITS
144+
// .iter()
145+
// .filter(|t| !self.std_source_traits.contains_key(**t))
146+
// .map(|s| (*s).to_owned())
147+
// .collect()
148+
// }
149149
}
150150

151151
#[derive(Clone, Debug)]

crates/bevy_api_gen/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#![feature(rustc_private, let_chains)]
22
#![deny(rustc::internal)]
3+
34
extern crate rustc_ast;
45
extern crate rustc_const_eval;
56
extern crate rustc_driver;
67
extern crate rustc_errors;
78
extern crate rustc_hir;
8-
extern crate rustc_hir_analysis;
99
extern crate rustc_infer;
1010
extern crate rustc_interface;
11-
extern crate rustc_lint;
1211
extern crate rustc_middle;
13-
extern crate rustc_session;
1412
extern crate rustc_span;
1513
extern crate rustc_trait_selection;
1614

crates/bevy_api_gen/src/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl MetaLoader {
116116
let cache = self.cache.borrow();
117117
if cache.contains_key(crate_name) {
118118
trace!("Loading meta from cache for: {}", crate_name);
119-
return cache.get(crate_name).cloned();
119+
cache.get(crate_name).cloned()
120120
} else {
121121
trace!("Loading meta from filesystem for: {}", crate_name);
122122
drop(cache);

crates/bevy_api_gen/src/passes/find_methods_and_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ fn type_is_supported_as_non_proxy_return_val<'tcx>(
386386
) -> bool {
387387
trace!("Checkign type is supported as non proxy return val: '{ty:?}' with param_env: '{param_env:?}'");
388388
if let TyKind::Ref(region, _, _) = ty.kind() {
389-
if !region.get_name().is_some_and(|rn| rn.as_str() == "'static") {
389+
if region.get_name().is_none_or(|rn| rn.as_str() != "'static") {
390390
return false;
391391
}
392392
}

crates/bevy_api_gen/src/template.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ pub(crate) fn configure_tera_env(tera: &mut Tera, crate_name: &str) {
199199

200200
let file = syn::parse_file(&str)
201201
.map_err(|e| tera::Error::msg(e.to_string()))
202-
.map_err(|e| {
202+
.inspect_err(|_| {
203203
log::error!("prettyplease error on input: ```\n{}\n```", str);
204-
e
205204
})?;
206205

207206
let out = prettyplease::unparse(&file);

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mlua_impls = ["mlua"]
2525
[dependencies]
2626
mlua = { version = "0.9", optional = true }
2727
bevy = { workspace = true, default-features = false, features = ["bevy_asset"] }
28+
2829
thiserror = "1.0.31"
2930
paste = "1.0.7"
3031
parking_lot = "0.12.1"

crates/languages/bevy_mod_scripting_lua/src/assets.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// utils::BoxedFuture,
55
// };
66

7+
78
// use anyhow::Error;
89

910
// #[derive(Asset, TypePath, Debug)]
@@ -145,6 +146,7 @@
145146
// Ok(LuaFile { bytes })
146147
// }
147148

149+
148150
// #[cfg(feature = "teal")]
149151
// fn extensions(&self) -> &[&str] {
150152
// &["lua", "tl"]

crates/languages/bevy_mod_scripting_lua/src/docs.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,24 @@ impl DocumentationFragment for LuaDocumentationFragment {
9797
// fixes bug in tealr which causes syntax errors in teal due to duplicate fields (from having both getters and setters)
9898
tw.given_types.iter_mut().for_each(|tg| {
9999
if let TypeGenerator::Record(rg) = tg {
100+
rg.fields
101+
.sort_by(|f1, f2| f1.name.deref().cmp(f2.name.deref()));
100102
rg.fields.dedup_by(|a, b| a.name == b.name);
103+
rg.static_fields
104+
.sort_by(|f1, f2| f1.name.deref().cmp(f2.name.deref()));
105+
rg.static_fields.dedup_by(|a, b| a.name == b.name);
106+
for field in rg.fields.iter_mut().chain(rg.static_fields.iter_mut()) {
107+
escape_name(&mut field.name);
108+
}
109+
for func in rg
110+
.functions
111+
.iter_mut()
112+
.chain(rg.mut_functions.iter_mut())
113+
.chain(rg.methods.iter_mut())
114+
.chain(rg.mut_methods.iter_mut())
115+
{
116+
escape_name(&mut func.name);
117+
}
101118
}
102119
});
103120

@@ -148,3 +165,36 @@ impl DocumentationFragment for LuaDocumentationFragment {
148165
Ok(())
149166
}
150167
}
168+
169+
/// Escapes a name of a table field, if that table field is a reserved keyword.
170+
///
171+
/// ## Background
172+
///
173+
/// String keys in a Lua table are allowed to be anything, even reserved
174+
/// keywords. By default when tealr generates the type definition for a table
175+
/// field, the string it generates is `{name} : {type}`. This causes a syntax
176+
/// error when writing a bare keyword, since `nil : {type}` is considered trying
177+
/// to add a type to the *value* nil (which is invalid).
178+
///
179+
/// To get around this tealr allows us to escape table fields using the
180+
/// `["{name}"] : {value}` syntax. This function detects if a name is one of the
181+
/// Lua reserved words and fixes it if so.
182+
fn escape_name(raw: &mut NameContainer) {
183+
// List of Lua reserved keywords
184+
const KEYWORD_FIELDS: &[&str] = &[
185+
"false", "true", "nil", // Values
186+
"and", "not", "or", // Operators
187+
"if", "then", "else", "elseif", "end", // If-Else
188+
"for", "in", "break", "do", "repeat", "until", "while", // Loops
189+
"function", "return", // Funcs
190+
"local", // Declarations
191+
"record", // Teal extra
192+
];
193+
let Ok(name) = str::from_utf8(raw) else {
194+
return;
195+
};
196+
if KEYWORD_FIELDS.contains(&name) {
197+
let mapped = format!("[\"{name}\"]");
198+
*raw = NameContainer::from(Cow::Owned(mapped));
199+
}
200+
}

0 commit comments

Comments
 (0)