Skip to content

Commit 1eb98b4

Browse files
committed
bring over bevy api gen work
1 parent 16f4652 commit 1eb98b4

40 files changed

+35200
-459
lines changed

crates/bevy_api_gen/Cargo.bootstrap.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66

77
[dependencies]
88
mlua = { version = "0.9.2", features = ["lua54", "vendored", "send", "macros"] }
9-
bevy_reflect = { version = "0.14", features = [
9+
bevy_reflect = { version = "0.15.0-rc.3", features = [
1010
"bevy",
1111
"glam",
1212
"petgraph",

crates/bevy_api_gen/Cargo.toml

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

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

4340
[dependencies]
44-
log = "0.4"
45-
env_logger = "0.11"
4641
rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" }
4742
indexmap = "2"
43+
log = "0.4"
44+
env_logger = "0.11"
4845
tempdir = "0.3"
4946
cargo_metadata = "0.18"
5047
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-11-05 install bevy_api_gen
11+
cargo +nightly-2024-01-24 install bevy_api_gen
1212
```
1313

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

2020
```bash
21-
cargo +nightly-2024-11-05 bevy-api-gen generate
21+
cargo +nightly-2024-01-24 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-11-05/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-01-24/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-11-05 bevy-api-gen collect
31+
cargo +nightly-2024-01-24 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-11-05 bevy-api-gen list-types > all_types.txt
39+
cargo +nightly-2024-01-24 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-11-05 bevy-api-gen list-templates
47+
cargo +nightly-2024-01-24 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-11-05 bevy-api-gen print item.tera
55+
cargo +nightly-2024-01-24 bevy-api-gen print item.tera
5656
```

crates/bevy_api_gen/src/args.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ pub enum Command {
189189

190190
/// The name of the API, this will be passed to the `collect.rs` template, which by default will be used as the APIProvider name and the
191191
/// title of the documentation.
192-
#[arg(short, long, value_name = "NAME", default_value = "LuaBevyAPIProvider")]
192+
#[arg(
193+
short,
194+
long,
195+
value_name = "NAME",
196+
default_value = "LuaBevyScriptingPlugin"
197+
)]
193198
api_name: String,
194199
},
195200
}

crates/bevy_api_gen/src/bin/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(rustc_private)]
2+
23
use std::{
34
collections::HashMap,
45
env,

crates/bevy_api_gen/src/callback.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl rustc_driver::Callbacks for BevyAnalyzerCallbacks {
8787
if !continue_ {
8888
break;
8989
}
90+
trace!("Finished pass, continuing");
9091
}
9192
});
9293
rustc_driver::Compilation::Continue

crates/bevy_api_gen/src/context.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ impl CachedTraits {
138138
.all(|t| self.std_source_traits.contains_key(*t))
139139
}
140140

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

150150
#[derive(Clone, Debug)]
151151
pub(crate) struct FunctionContext {
152152
pub(crate) def_id: DefId,
153153
pub(crate) has_self: bool,
154154
pub(crate) is_unsafe: bool,
155-
pub(crate) trait_did: Option<DefId>,
155+
pub(crate) trait_and_impl_did: Option<(DefId, DefId)>,
156156
/// strategies for input and output (last element is the output)
157157
pub(crate) reflection_strategies: Vec<ReflectionStrategy>,
158158
}

crates/bevy_api_gen/src/import_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl std::fmt::Debug for ImportPathElement {
2727
/// Because we do not need ALL the items in the crate, we start searching from the item itself and traverse up the tree.
2828
/// Caches results for already found items.
2929
pub(crate) struct ImportPathFinder<'tcx> {
30-
tcx: TyCtxt<'tcx>,
30+
pub(crate) tcx: TyCtxt<'tcx>,
3131
pub(crate) cache: IndexMap<DefId, Vec<Vec<ImportPathElement>>>,
3232
pub(crate) include_private_paths: bool,
3333
pub(crate) import_path_processor: Option<Box<dyn Fn(&str) -> String>>,

crates/bevy_api_gen/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#![feature(rustc_private, let_chains)]
22
#![deny(rustc::internal)]
3-
43
extern crate rustc_ast;
4+
extern crate rustc_const_eval;
55
extern crate rustc_driver;
66
extern crate rustc_errors;
77
extern crate rustc_hir;
8+
extern crate rustc_hir_analysis;
89
extern crate rustc_infer;
910
extern crate rustc_interface;
11+
extern crate rustc_lint;
1012
extern crate rustc_middle;
13+
extern crate rustc_session;
1114
extern crate rustc_span;
1215
extern crate rustc_trait_selection;
1316

crates/bevy_api_gen/src/meta.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ impl MetaLoader {
6666
self.meta_for_retry(crate_name, 3)
6767
}
6868

69+
/// Searches the given meta sources in order for the provided DefPathHash, once a meta file containing this hash is found
70+
/// the search stops and returns true, if no meta file is found containing the hash, false is returned
71+
///
72+
/// if a curr_source argument is provided, the search will skip this source as it is assumed that the current crate is still being compiled and not meta file for it exists yet
73+
pub fn one_of_meta_files_contains(
74+
&self,
75+
meta_sources: &[&str],
76+
curr_source: Option<&str>,
77+
target_def_path_hash: DefPathHash,
78+
) -> bool {
79+
let meta = match meta_sources
80+
.iter()
81+
.filter(|s| curr_source.is_none() || curr_source.is_some_and(|cs| cs == **s))
82+
.find_map(|s| self.meta_for(s))
83+
{
84+
Some(meta) => meta,
85+
None => return false, // TODO: is it possible we get false negatives here ? perhaps due to parallel compilation ? or possibly because of dependency order
86+
};
87+
88+
meta.contains_def_path_hash(target_def_path_hash)
89+
}
90+
6991
fn meta_for_retry(&self, crate_name: &str, _try_attempts: usize) -> Option<Meta> {
7092
let meta = self
7193
.meta_dirs
@@ -94,7 +116,7 @@ impl MetaLoader {
94116
let cache = self.cache.borrow();
95117
if cache.contains_key(crate_name) {
96118
trace!("Loading meta from cache for: {}", crate_name);
97-
cache.get(crate_name).cloned()
119+
return cache.get(crate_name).cloned();
98120
} else {
99121
trace!("Loading meta from filesystem for: {}", crate_name);
100122
drop(cache);

0 commit comments

Comments
 (0)