Skip to content

Commit c2c3bda

Browse files
makspllshanecelis
andauthored
Migrate to bevy 0.14 (#127)
* chore: First pass. * Pin bevy to 0.14.2 and migrate rhai asset loader future * roll back nightly version to try generating with it * typo * fix stack overflow and improve logging in bootstrapping, build bootstrap into nearest target * bump rust version for codegen * typo * fix issues with file loader * generate new providers * add uuid dependency * ignore TypeId as a proxy * re-generate bevy_reflect * fix missing GetTypeRegistration bounds (this is good to have anyway) * fix compilation errors in examples * add wsl exports * formatting * fix clippy warnings * more clippy fixes * fix macro tests * fix macro test --------- Co-authored-by: Shane Celis <shane.celis@gmail.com>
1 parent e1ff884 commit c2c3bda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+14252
-13202
lines changed

.github/workflows/bevy_api_gen.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions-rs/toolchain@v1
2828
with:
2929
profile: minimal
30-
toolchain: nightly-2024-01-24
30+
toolchain: nightly-2024-05-20
3131
override: true
3232
- name: Rust Cache
3333
uses: Swatinem/rust-cache@v2.7.3
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
profile: minimal
5656
components: rustfmt
57-
toolchain: nightly-2024-01-24
57+
toolchain: nightly-2024-05-20
5858
override: true
5959
- name: Rust Cache
6060
uses: Swatinem/rust-cache@v2.7.3
@@ -77,7 +77,7 @@ jobs:
7777
rm -rf crates
7878
- uses: actions-rs/toolchain@v1
7979
with:
80-
toolchain: nightly-2024-01-24
80+
toolchain: nightly-2024-05-20
8181
components: clippy
8282
override: true
8383
- name: Rust Cache
@@ -100,7 +100,7 @@ jobs:
100100
rm -rf crates
101101
- uses: actions-rs/toolchain@v1
102102
with:
103-
toolchain: nightly-2024-01-24
103+
toolchain: nightly-2024-05-20
104104
override: true
105105
- name: Rust Cache
106106
uses: Swatinem/rust-cache@v2.7.3
@@ -122,7 +122,7 @@ jobs:
122122
rm -rf crates
123123
- uses: actions-rs/toolchain@v1
124124
with:
125-
toolchain: nightly-2024-01-24
125+
toolchain: nightly-2024-05-20
126126
override: true
127127
- name: Rust Cache
128128
uses: Swatinem/rust-cache@v2.7.3

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ bevy_script_api = { path = "crates/bevy_script_api", version = "0.6.0", optional
7070

7171

7272
[workspace.dependencies]
73-
bevy = { version = "=0.13.1", default-features = false }
73+
bevy = { version = "0.14.2", default-features = false }
7474
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.6.0" }
7575
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.6.0" }
7676

7777
[dev-dependencies]
7878
bevy = { workspace = true, default-features = true }
7979
clap = { version = "4.1", features = ["derive"] }
8080
rand = "0.8.5"
81-
bevy_console = "0.11.1"
81+
bevy_console = "0.12"
8282
rhai-rand = "0.1"
8383

8484
[workspace]
@@ -118,7 +118,7 @@ required-features = [
118118
"lua54",
119119
"lua_script_api",
120120
"bevy/file_watcher",
121-
"bevy/multi-threaded",
121+
"bevy/multi_threaded",
122122
]
123123

124124
[[example]]
@@ -128,7 +128,7 @@ required-features = [
128128
"rhai",
129129
"rhai_script_api",
130130
"bevy/file_watcher",
131-
"bevy/multi-threaded",
131+
"bevy/multi_threaded",
132132
]
133133

134134
[[example]]
@@ -143,7 +143,7 @@ required-features = [
143143
"lua54",
144144
"lua_script_api",
145145
"bevy/file_watcher",
146-
"bevy/multi-threaded",
146+
"bevy/multi_threaded",
147147
]
148148

149149
[[example]]
@@ -153,7 +153,7 @@ required-features = [
153153
"rhai",
154154
"rhai_script_api",
155155
"bevy/file_watcher",
156-
"bevy/multi-threaded",
156+
"bevy/multi_threaded",
157157
]
158158

159159
[[example]]

check.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CURRENT_DIR=$(basename "$PWD")
44

55

66
if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then
7-
cargo clippy --all-targets --message-format=json
7+
cargo +nightly-2024-05-20 clippy --all-targets --message-format=json
88
else
9-
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"
10-
fi
9+
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"
10+
fi

crates/bevy_api_gen/Cargo.bootstrap.toml

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

77
[dependencies]
88
mlua = { version = "0.9.2", features = ["lua54", "vendored", "send", "macros"] }
9-
bevy_reflect = { version = "0.13.1", features = ["bevy", "bevy_math"] }
9+
bevy_reflect = { version = "0.14", features = [
10+
"bevy",
11+
"glam",
12+
"petgraph",
13+
"smallvec",
14+
"uuid",
15+
] }
1016

1117
[workspace]

crates/bevy_api_gen/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ source = "discover"
3737
rustc_private = true
3838

3939
[rust-analyzer.check]
40-
overrideCommand = ["cargo", "+nightly-2024-01-24", "a", "--message-format=json"]
40+
overrideCommand = ["cargo", "+nightly-2024-05-20", "a", "--message-format=json"]
4141

4242

4343
[dependencies]
4444
log = "0.4"
4545
env_logger = "0.11"
46-
rustc_plugin = "=0.9.0-nightly-2024-01-24"
46+
rustc_plugin = "=0.10.0-nightly-2024-05-20"
4747
indexmap = "2"
4848
tempdir = "0.3"
4949
cargo_metadata = "0.18"

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-05-20 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-05-20 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-05-20/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-05-20 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-05-20 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-05-20 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-05-20 bevy-api-gen print item.tera
5656
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
components = ["clippy", "rust-src", "rustc-dev", "llvm-tools"]
3-
channel = "nightly-2024-01-24"
3+
channel = "nightly-2024-05-20"

crates/bevy_api_gen/src/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl Verbosity {
104104

105105
fn default_ignored_types() -> String {
106106
[
107+
"std::any::TypeId",
107108
"bevy_reflect::DynamicArray",
108109
"bevy_reflect::DynamicList",
109110
"bevy_reflect::DynamicMap",

crates/bevy_api_gen/src/bin/main.rs

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use std::{
22
collections::HashMap,
33
env,
44
fs::{create_dir_all, File},
5-
io::Write,
6-
path::Path,
5+
io::{BufRead, Write},
6+
path::{Path, PathBuf},
77
process::{Command, Stdio},
88
};
99

1010
use bevy_api_gen::*;
1111
use cargo_metadata::camino::Utf8Path;
1212
use clap::Parser;
13-
use log::{debug, info};
13+
use log::{debug, error, info};
1414
use strum::VariantNames;
1515
use tera::Context;
1616

@@ -25,19 +25,34 @@ fn main() {
2525
}
2626
env_logger::init();
2727

28+
info!("Computing crate metadata");
2829
let metadata = cargo_metadata::MetadataCommand::new()
2930
.no_deps()
3031
.other_options(["--all-features".to_string(), "--offline".to_string()])
3132
.exec()
3233
.unwrap();
34+
3335
let crates = metadata
3436
.workspace_packages()
3537
.iter()
3638
.map(|p| p.name.to_owned())
3739
.collect::<Vec<_>>();
40+
41+
info!("Computing active features");
3842
let include_crates = match (&args.workspace_root, args.cmd.is_generate()) {
3943
(Some(root), true) => {
4044
let feature_graph = FeatureGraph::from_metadata(&metadata, root);
45+
info!(
46+
"Using workspace root: {}, found {} crates",
47+
feature_graph.workspace_root,
48+
feature_graph.crates.len()
49+
);
50+
51+
info!(
52+
"Computing all transitive dependencies for enabled top-level features: {}",
53+
args.features.join(",")
54+
);
55+
4156
let dependencies = feature_graph
4257
.dependencies_for_features(args.features.as_ref(), !args.no_default_features)
4358
.into_iter()
@@ -52,6 +67,8 @@ fn main() {
5267
let plugin_subdir = format!("plugin-{}", env!("RUSTC_CHANNEL"));
5368
let plugin_target_dir = metadata.target_directory.join(plugin_subdir);
5469

70+
info!("Computing wokrspace metadata");
71+
5572
// inform the deps about the workspace crates, this is going to be useful when working with meta files as we will be able to
5673
// know when to panic if a crate is not found
5774
// it's also useful to pass around the output directory for our Args default values to be able to compute them
@@ -132,14 +149,13 @@ fn main() {
132149
_ => {}
133150
}
134151

135-
let temp_dir = tempdir::TempDir::new("bevy_api_gen_bootstrap")
136-
.expect("Error occured when trying to acquire temp file");
152+
let temp_dir = find_bootstrap_dir();
137153

138-
debug!("Temporary directory: {}", &temp_dir.path().display());
154+
debug!("Bootstrap directory: {}", &temp_dir.as_path().display());
139155

140-
write_bootstrap_files(temp_dir.path());
156+
write_bootstrap_files(temp_dir.as_path());
141157

142-
let bootstrap_rlibs = build_bootstrap(temp_dir.path(), &plugin_target_dir.join("bootstrap"));
158+
let bootstrap_rlibs = build_bootstrap(temp_dir.as_path(), &plugin_target_dir.join("bootstrap"));
143159

144160
if bootstrap_rlibs.len() == BOOTSTRAP_DEPS.len() {
145161
let extern_args = bootstrap_rlibs
@@ -195,20 +211,50 @@ fn build_bootstrap(
195211
let mut cmd = Command::new("cargo")
196212
.current_dir(temp_dir)
197213
.stdout(Stdio::piped())
214+
.stderr(Stdio::piped())
198215
.args(["build", "--message-format=json"])
199216
.spawn()
200217
.unwrap();
201218

219+
info!(
220+
"cd {} && cargo build --message-format=json",
221+
temp_dir.display()
222+
);
223+
202224
let reader = std::io::BufReader::new(cmd.stdout.take().unwrap());
225+
let err_reader = std::io::BufReader::new(cmd.stderr.take().unwrap());
203226

204227
std::fs::create_dir_all(cache_dir).unwrap();
205228

206229
let mut bootstrap_rlibs = HashMap::with_capacity(BOOTSTRAP_DEPS.len());
207230
for msg in cargo_metadata::Message::parse_stream(reader) {
208-
if let cargo_metadata::Message::CompilerArtifact(artifact) = msg.unwrap() {
231+
let msg = msg.unwrap();
232+
if let cargo_metadata::Message::CompilerArtifact(artifact) = msg {
209233
for artifact in artifact.filenames.into_iter() {
210234
process_artifact(artifact, &mut bootstrap_rlibs);
211235
}
236+
} else {
237+
match msg {
238+
cargo_metadata::Message::BuildFinished(finished) => {
239+
if !finished.success {
240+
error!("Bootstrapping crate failed to build artifact");
241+
}
242+
}
243+
cargo_metadata::Message::TextLine(t) => {
244+
info!("{t}");
245+
}
246+
cargo_metadata::Message::CompilerMessage(msg) => {
247+
info!("{msg}");
248+
}
249+
_ => {}
250+
}
251+
}
252+
}
253+
for msg in err_reader.lines() {
254+
if let Ok(line) = msg {
255+
info!("{line}");
256+
} else {
257+
panic!("Failed to read cargo stderr");
212258
}
213259
}
214260

@@ -224,10 +270,17 @@ fn build_bootstrap(
224270
std::fs::copy(path, dest).unwrap();
225271
}
226272
}
273+
match cmd.wait() {
274+
Ok(status) => {
275+
if !status.success() {
276+
panic!("Building bootstrap crate returned a failure status code");
277+
}
278+
}
279+
Err(e) => {
280+
panic!("Failed to wait on cargo build process: {}", e);
281+
}
282+
}
227283

228-
if !cmd.wait().unwrap().success() {
229-
panic!("Building bootstrap crate returned a failure status code");
230-
};
231284
bootstrap_rlibs
232285
}
233286

@@ -248,6 +301,28 @@ fn process_artifact(
248301
}
249302
}
250303

304+
/// finds best location for bootstrapping crate
305+
/// this will be the nearest target/bevy_api_gen_bootstrap directory
306+
fn find_bootstrap_dir() -> PathBuf {
307+
let mut path = env::current_dir().unwrap();
308+
loop {
309+
if path.join("target").exists() {
310+
break;
311+
} else if let Some(parent) = path.parent() {
312+
path = parent.to_path_buf();
313+
} else {
314+
panic!("Could not find `target` directory");
315+
}
316+
}
317+
318+
path.push("target");
319+
path.push("bevy_api_gen_bootstrap");
320+
321+
// create all the directories
322+
create_dir_all(&path).unwrap();
323+
path
324+
}
325+
251326
/// Generate bootstrapping crate files
252327
fn write_bootstrap_files(path: &Path) {
253328
// write manifest file 'Cargo.toml'

0 commit comments

Comments
 (0)