cli json output, dx bundle fix, dx serve --platform android, race condition, drop ssg platform (#3186)

* clean up logging to avoid random extra trace

* fix race condition with updates

* properly wire up verbose

* fix bundling (macos) and logging

* Add structured output

* clean up clap names

* extract out wire format

* switch structured key to json

* fix random println, fallback to `dioxus/platform`

* clean up logging for run/build

* clean up logging around project

* remove manual exits

* fix tokio runtime for mobile

* rework dog app

* rip out ssg

* Switch dioxus/axum to dioxus/server

* add android template inline

* pre restructure for bundle prep

* add the whole res directory

* Better theme for the app

* remove mobile demo now that most apps work natively

* self-referential android

* only use deep linking for assets

* fix imports for android

* clippy, fixup ios and android

* I'm not boxing compiler message you can't make me

* fix clippy on unix
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-11-12 09:01:01 -05:00
1 parent 8a998e7d49
commit ac3e33af46
116 files changed
+2367 -6091

No files matched your search

+63 -54
View File
@@ -25,14 +25,15 @@ pub(crate) static PROFILE_SERVER: &str = "dioxus-server";
impl DioxusCrate {
pub(crate) fn new(target: &TargetArgs) -> Result<Self> {
let mut cmd = Cmd::new();
cmd.features(target.features.clone());
let krates = krates::Builder::new()
tracing::debug!("Loading crate");
let cmd = Cmd::new();
let builder = krates::Builder::new();
let krates = builder
.build(cmd, |_| {})
.context("Failed to run cargo metadata")?;
let package = find_main_package(&krates, target.package.clone())?;
tracing::debug!("Found package {package:?}");
let dioxus_config = DioxusConfig::load(&krates, package)?.unwrap_or_default();
@@ -173,6 +174,7 @@ impl DioxusCrate {
.get_enabled_features(krate.kid)?
.iter()
.flat_map(|feature| {
tracing::trace!("Autodetecting platform from feature {feature}");
Platform::autodetect_from_cargo_feature(feature).map(|f| (f, feature.to_string()))
})
.collect::<Vec<_>>();
@@ -230,8 +232,6 @@ impl DioxusCrate {
return possible_platforms.first().cloned();
}
tracing::warn!("Could not autodetect platform. Platform must be explicitly specified. Pass `--platform <platform>` or set a default platform using a cargo feature.");
None
}
@@ -246,13 +246,13 @@ impl DioxusCrate {
}
/// Get the features required to build for the given platform
pub(crate) fn feature_for_platform(&self, platform: Platform) -> Option<String> {
pub(crate) fn feature_for_platform(&self, platform: Platform) -> String {
let package = self.package();
// Try to find the feature that activates the dioxus feature for the given platform
let dioxus_feature = platform.feature_name();
package.features.iter().find_map(|(key, features)| {
let res = package.features.iter().find_map(|(key, features)| {
// if the feature is just the name of the platform, we use that
if key == dioxus_feature {
return Some(key.clone());
@@ -271,7 +271,16 @@ impl DioxusCrate {
}
}
}
None
});
res.unwrap_or_else(|| {
let fallback = format!("dioxus/{}", platform.feature_name()) ;
tracing::debug!(
"Could not find explicit feature for platform {platform}, passing `fallback` instead"
);
fallback
})
}
@@ -312,14 +321,13 @@ impl DioxusCrate {
if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_SERVER) {
let mut server = toml_edit::Table::new();
server.insert("inherits", Item::Value("dev".into()));
server.insert("opt-level", Item::Value(2.into()));
// server.insert("opt-level", Item::Value(2.into()));
entry.insert(Item::Table(server));
}
if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_ANDROID) {
let mut android = toml_edit::Table::new();
android.insert("inherits", Item::Value("dev".into()));
android.insert("opt-level", Item::Value(2.into()));
entry.insert(Item::Table(android));
}
}
@@ -561,59 +569,60 @@ impl std::fmt::Debug for DioxusCrate {
// Find the main package in the workspace
fn find_main_package(krates: &Krates, package: Option<String>) -> Result<NodeId> {
let kid = match package {
Some(package) => {
let mut workspace_members = krates.workspace_members();
let found = workspace_members.find_map(|node| {
if let krates::Node::Krate { id, krate, .. } = node {
if krate.name == package {
return Some(id);
}
}
None
});
if found.is_none() {
eprintln!("Could not find package {package} in the workspace. Did you forget to add it to the workspace?");
eprintln!("Packages in the workspace:");
for package in krates.workspace_members() {
if let krates::Node::Krate { krate, .. } = package {
eprintln!("{}", krate.name());
}
if let Some(package) = package {
let mut workspace_members = krates.workspace_members();
let found = workspace_members.find_map(|node| {
if let krates::Node::Krate { id, krate, .. } = node {
if krate.name == package {
return Some(id);
}
}
None
});
found.ok_or_else(|| anyhow::anyhow!("Failed to find package {package}"))?
if found.is_none() {
tracing::error!("Could not find package {package} in the workspace. Did you forget to add it to the workspace?");
tracing::error!("Packages in the workspace:");
for package in krates.workspace_members() {
if let krates::Node::Krate { krate, .. } = package {
tracing::error!("{}", krate.name());
}
}
}
None => {
// Otherwise find the package that is the closest parent of the current directory
let current_dir = std::env::current_dir()?;
let current_dir = current_dir.as_path();
// Go through each member and find the path that is a parent of the current directory
let mut closest_parent = None;
for member in krates.workspace_members() {
if let krates::Node::Krate { id, krate, .. } = member {
let member_path = krate.manifest_path.parent().unwrap();
if let Ok(path) = current_dir.strip_prefix(member_path.as_std_path()) {
let len = path.components().count();
match closest_parent {
Some((_, closest_parent_len)) => {
if len < closest_parent_len {
closest_parent = Some((id, len));
}
}
None => {
closest_parent = Some((id, len));
}
let kid = found.ok_or_else(|| anyhow::anyhow!("Failed to find package {package}"))?;
return Ok(krates.nid_for_kid(kid).unwrap());
};
// Otherwise find the package that is the closest parent of the current directory
let current_dir = std::env::current_dir()?;
let current_dir = current_dir.as_path();
// Go through each member and find the path that is a parent of the current directory
let mut closest_parent = None;
for member in krates.workspace_members() {
if let krates::Node::Krate { id, krate, .. } = member {
let member_path = krate.manifest_path.parent().unwrap();
if let Ok(path) = current_dir.strip_prefix(member_path.as_std_path()) {
let len = path.components().count();
match closest_parent {
Some((_, closest_parent_len)) => {
if len < closest_parent_len {
closest_parent = Some((id, len));
}
}
None => {
closest_parent = Some((id, len));
}
}
}
closest_parent
.map(|(id, _)| id)
.context("Failed to find current package")?
}
};
}
let kid = closest_parent
.map(|(id, _)| id)
.context("Failed to find current package")?;
let package = krates.nid_for_kid(kid).unwrap();
Ok(package)