Skip to content

Commit 22cda73

Browse files
committed
some improvements
1 parent a08db66 commit 22cda73

File tree

32 files changed

+283
-220
lines changed

32 files changed

+283
-220
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ bevy_utils = { version = "0.17", default-features = false, features = ["std"] }
198198
glam = { version = "0.30.7", default-features = false }
199199
uuid = { version = "1.13", default-features = false }
200200
smol_str = { version = "0.2.0", default-features = false }
201+
nonmax = { version = "0.5.5", default-features = false, features = ["std"] }
201202

202203
# other
203204
serde_json = { version = "1.0", default-features = false }

codegen/crates/crate_feature_graph/src/feature.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{
22
borrow::{Borrow, Cow},
33
collections::VecDeque,
44
fmt::Display,
5+
hash::Hash,
56
};
67

78
use cargo_metadata::{
@@ -222,6 +223,43 @@ impl Ord for CrateDependency {
222223
}
223224
}
224225

226+
/// A feature activation descriptor within a crate
227+
#[derive(Debug, Clone, Eq)]
228+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
229+
pub struct LocalActivatedFeature {
230+
pub feature: FeatureName,
231+
pub activated_via_other_crate: bool,
232+
}
233+
234+
impl PartialEq for LocalActivatedFeature {
235+
fn eq(&self, other: &Self) -> bool {
236+
self.feature == other.feature
237+
}
238+
}
239+
240+
impl Ord for LocalActivatedFeature {
241+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
242+
match self.feature.cmp(&other.feature) {
243+
core::cmp::Ordering::Equal => {}
244+
ord => return ord,
245+
}
246+
self.activated_via_other_crate
247+
.cmp(&other.activated_via_other_crate)
248+
}
249+
}
250+
251+
impl PartialOrd for LocalActivatedFeature {
252+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
253+
Some(self.cmp(other))
254+
}
255+
}
256+
257+
impl Hash for LocalActivatedFeature {
258+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
259+
self.feature.hash(state);
260+
}
261+
}
262+
225263
#[derive(Clone, Debug, PartialEq, Eq)]
226264
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
227265
pub struct Crate {
@@ -232,7 +270,7 @@ pub struct Crate {
232270
pub version: Version,
233271
pub in_workspace: Option<bool>,
234272
pub active_features: Option<IndexSet<FeatureName>>,
235-
pub active_dependency_features: Option<IndexMap<CrateName, Vec<(FeatureName, bool)>>>,
273+
pub active_dependency_features: Option<IndexMap<CrateName, Vec<LocalActivatedFeature>>>,
236274
pub is_enabled: Option<bool>,
237275
}
238276

codegen/crates/crate_feature_graph/src/graph.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indexmap::{IndexMap, IndexSet};
44
use log::error;
55
use petgraph::Directed;
66

7-
use crate::{CrateName, DependencyKind, Feature, FeatureName, Workspace};
7+
use crate::{CrateName, DependencyKind, Feature, FeatureName, LocalActivatedFeature, Workspace};
88

99
#[derive(Clone, Debug, PartialEq, Eq)]
1010
pub enum DependsOn {
@@ -328,16 +328,7 @@ impl WorkspaceGraph {
328328
.as_ref()
329329
.map(|m| {
330330
m.iter()
331-
.map(|(k, v)| {
332-
(
333-
k.to_string(),
334-
v.iter()
335-
.map(|(f, enabled_by_shared)| {
336-
(f.to_string(), enabled_by_shared)
337-
})
338-
.collect::<Vec<_>>(),
339-
)
340-
})
331+
.map(|(k, v)| (k.to_string(), v.iter().collect::<Vec<_>>()))
341332
.collect()
342333
})
343334
.unwrap_or_default(),
@@ -353,12 +344,10 @@ impl WorkspaceGraph {
353344
"{}: [{}]",
354345
k,
355346
v.iter()
356-
.map(|(f, enabled_by_shared)| format!(
347+
.map(|f| format!(
357348
"{}{}",
358-
f,
359-
enabled_by_shared
360-
.then_some(String::from(" (*shared)"))
361-
.unwrap_or_default()
349+
f.feature,
350+
if f.activated_via_other_crate { String::from(" (*shared)") } else { Default::default() }
362351
))
363352
.collect::<Vec<_>>()
364353
.join(", ")
@@ -437,6 +426,7 @@ impl WorkspaceGraph {
437426
f.sort()
438427
}
439428
if let Some(m) = krate.active_dependency_features.as_mut() {
429+
m.sort_keys();
440430
for v in m.values_mut() {
441431
v.sort();
442432
}
@@ -572,7 +562,7 @@ impl WorkspaceGraph {
572562
}
573563

574564
// then compute the active dependency features for each crate
575-
let mut active_dependency_features = HashMap::<_, Vec<(_, _)>>::new();
565+
let mut active_dependency_features = HashMap::<_, Vec<_>>::new();
576566
for krate in self
577567
.workspace
578568
.all_crates()
@@ -602,7 +592,10 @@ impl WorkspaceGraph {
602592
active_dependency_features
603593
.entry((krate.name.clone(), dependency.name.clone()))
604594
.or_default()
605-
.push((feature.clone(), false));
595+
.push(LocalActivatedFeature {
596+
feature: feature.clone(),
597+
activated_via_other_crate: false,
598+
});
606599
}
607600
}
608601
}
@@ -620,11 +613,11 @@ impl WorkspaceGraph {
620613
.filter(|f| !f.is_special_default_enabling_feature())
621614
{
622615
// meh
623-
let val = (feat.clone(), true);
624-
let false_val = (feat.clone(), false);
625-
if !entry.contains(&val) && !entry.contains(&false_val) {
626-
entry.push(val);
627-
}
616+
let val = LocalActivatedFeature {
617+
feature: feat.clone(),
618+
activated_via_other_crate: true,
619+
};
620+
entry.push(val);
628621
}
629622
}
630623
}
@@ -642,6 +635,16 @@ impl WorkspaceGraph {
642635
if let Some(krate) = self.workspace.find_crate_mut(&in_crate, || format!(
643636
"package from workspace manifest: `{in_crate}` was not found in the parsed workspace list. While setting active dependency features."
644637
)) {
638+
// remove duplicates, but keep the "lowest" activation level to show
639+
let mut feature_set = HashSet::<LocalActivatedFeature>::with_capacity(features.len());
640+
for mut feat in features.into_iter() {
641+
if let Some(existing) = feature_set.get(&feat) {
642+
feat.activated_via_other_crate = existing.activated_via_other_crate && feat.activated_via_other_crate;
643+
}
644+
feature_set.insert(feat);
645+
}
646+
let features = feature_set.into_iter().collect();
647+
645648
match krate.active_dependency_features.as_mut() {
646649
Some(map) => {
647650
map.insert(dependency, features);

codegen/src/passes/write_meta.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ pub(crate) fn write_meta(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool {
5151
k.to_string(),
5252
Dependency {
5353
version: d.version.to_string(),
54-
features: features
55-
.iter()
56-
.map(|(feat_name, _)| feat_name.to_string())
57-
.collect(),
54+
features: features.iter().map(|f| f.feature.to_string()).collect(),
5855
},
5956
),
6057
None => todo!(),

crates/bevy_mod_scripting_bindings/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ profiling = { workspace = true }
3232
bevy_asset = { workspace = true }
3333
variadics_please = { workspace = true }
3434
serde = { workspace = true }
35+
nonmax = { workspace = true }
3536

3637
[dev-dependencies]
3738
pretty_assertions = { workspace = true }

crates/bevy_mod_scripting_bindings/src/function/from.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
};
66
use bevy_platform::collections::{HashMap, HashSet};
77
use bevy_reflect::{FromReflect, Reflect};
8+
use nonmax::NonMaxU32;
89
use std::{
910
any::TypeId,
1011
ffi::OsString,
@@ -115,6 +116,28 @@ macro_rules! impl_from_stringlike {
115116

116117
impl_from_stringlike!(String, PathBuf, OsString);
117118

119+
impl FromScript for NonMaxU32 {
120+
type This<'w> = Self;
121+
122+
fn from_script(
123+
value: ScriptValue,
124+
_world: WorldGuard<'_>,
125+
) -> Result<Self::This<'_>, InteropError>
126+
where
127+
Self: Sized,
128+
{
129+
match value {
130+
ScriptValue::Integer(i) if i != 0 => Ok(unsafe { NonMaxU32::new_unchecked(i as u32) }),
131+
ScriptValue::Float(f) if f != 0.0 => Ok(unsafe { NonMaxU32::new_unchecked(f as u32) }),
132+
// ScriptValue::Reference(r) => r.downcast::<Self>(world),
133+
_ => Err(InteropError::value_mismatch(
134+
std::any::TypeId::of::<Self>(),
135+
value,
136+
)),
137+
}
138+
}
139+
}
140+
118141
#[profiling::all_functions]
119142
impl FromScript for char {
120143
type This<'w> = Self;

crates/bindings/bevy_a11y_bms_bindings/Cargo.toml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings/bevy_animation_bms_bindings/Cargo.toml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings/bevy_camera_bms_bindings/Cargo.toml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings/bevy_color_bms_bindings/Cargo.toml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)