浏览代码

collapse mobile into desktop

Jonathan Kelley 1 天之前
父节点
当前提交
3b18fa314c

+ 4 - 4
.github/workflows/main.yml

@@ -82,7 +82,7 @@ jobs:
         with:
           cache-all-crates: "true"
       - uses: browser-actions/setup-firefox@latest
-      - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
+      - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop
 
   release-test:
     if: github.event.pull_request.draft == false
@@ -103,7 +103,7 @@ jobs:
         with:
           cache-all-crates: "true"
       - uses: browser-actions/setup-firefox@latest
-      - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile --profile release-unoptimized
+      - run: cargo test --lib --bins --tests --examples --workspace --exclude dioxus-desktop --profile release-unoptimized
 
   fmt:
     if: github.event.pull_request.draft == false
@@ -273,7 +273,7 @@ jobs:
               toolchain: "1.86.0",
               cross: false,
               command: "build",
-              args: "--package dioxus-mobile",
+              args: "--package dioxus-desktop",
               platform: "ios"
             }
           - {
@@ -300,7 +300,7 @@ jobs:
               toolchain: "1.86.0",
               cross: true,
               command: "build",
-              args: "--package dioxus-mobile",
+              args: "--package dioxus-desktop",
               platform: "android"
             }
 

+ 1 - 14
Cargo.lock

@@ -5016,7 +5016,6 @@ dependencies = [
  "dioxus-html",
  "dioxus-liveview",
  "dioxus-logger",
- "dioxus-mobile",
  "dioxus-native",
  "dioxus-router",
  "dioxus-server",
@@ -5359,6 +5358,7 @@ dependencies = [
  "objc",
  "objc_id",
  "open",
+ "openssl",
  "percent-encoding",
  "pollster",
  "rand 0.8.5",
@@ -5491,7 +5491,6 @@ dependencies = [
  "dioxus-interpreter-js",
  "dioxus-isrg",
  "dioxus-lib",
- "dioxus-mobile",
  "dioxus-router",
  "dioxus-server",
  "dioxus-web",
@@ -5699,18 +5698,6 @@ dependencies = [
  "tracing-wasm",
 ]
 
-[[package]]
-name = "dioxus-mobile"
-version = "0.7.0-alpha.2"
-dependencies = [
- "dioxus-cli-config",
- "dioxus-desktop",
- "dioxus-lib",
- "jni 0.21.1",
- "libc",
- "openssl",
-]
-
 [[package]]
 name = "dioxus-native"
 version = "0.7.0-alpha.2"

+ 0 - 3
Cargo.toml

@@ -19,7 +19,6 @@ members = [
     "packages/web",
     "packages/ssr",
     "packages/desktop",
-    "packages/mobile",
     "packages/interpreter",
     "packages/liveview",
     "packages/autofmt",
@@ -48,7 +47,6 @@ members = [
     "packages/interpreter",
     "packages/lazy-js-bundle",
     "packages/liveview",
-    "packages/mobile",
     "packages/router-macro",
     "packages/router",
     "packages/rsx-hotreload",
@@ -156,7 +154,6 @@ dioxus-web = { path = "packages/web", version = "0.7.0-alpha.2", default-feature
 dioxus-isrg = { path = "packages/isrg", version = "0.7.0-alpha.2" }
 dioxus-ssr = { path = "packages/ssr", version = "0.7.0-alpha.2", default-features = false }
 dioxus-desktop = { path = "packages/desktop", version = "0.7.0-alpha.2", default-features = false }
-dioxus-mobile = { path = "packages/mobile", version = "0.7.0-alpha.2" }
 dioxus-interpreter-js = { path = "packages/interpreter", version = "0.7.0-alpha.2" }
 dioxus-liveview = { path = "packages/liveview", version = "0.7.0-alpha.2" }
 dioxus-autofmt = { path = "packages/autofmt", version = "0.7.0-alpha.2" }

+ 1 - 1
notes/RELEASING.md

@@ -103,7 +103,7 @@ There are a number of crates that are part of the Dioxus ecosystem that we usual
 
 Verify everything works and is ready to go.
 - [ ] crates.io is up to date
-- [ ] docs.rs is up to date and has no failing builds for major crates (dioxus, dioxus-desktop, dioxus-mobile, etc)
+- [ ] docs.rs is up to date and has no failing builds for major crates (dioxus, dioxus-desktop, etc)
 - [ ] github release post is out
 - [ ] The relevant GitHub tag is created
 - [ ] Any fixes are backported to the relevant branches.

+ 1 - 1
packages/cli/src/cli/run.rs

@@ -124,7 +124,7 @@ impl RunArgs {
                             print!("{}", message);
                         }
                         BuilderUpdate::BuildFailed { err } => {
-                            tracing::error!("Build failed: {}", err);
+                            tracing::error!("Build failed: {}", err);
                             return Err(err);
                         }
                         BuilderUpdate::StdoutReceived { msg } => {

+ 7 - 1
packages/desktop/Cargo.toml

@@ -79,6 +79,11 @@ ndk = { version = "0.9.0" }
 ndk-sys = { version = "0.6.0" }
 ndk-context = { version = "0.1.1" }
 
+# The `openssl` dependency generally does not know how to cross-compile for Android. To make the lives
+# of our users easier, we automatically enable the `openssl` feature when building for Android.
+# Feature are additive, so users will need to "subtract" this feature if they do not want it.
+openssl = { version = "0.10", features = ["vendored"], optional = true }
+
 # use native tls on other platforms
 [target.'cfg(not(target_os = "android"))'.dependencies]
 tungstenite = { workspace = true, features = ["native-tls"] }
@@ -92,11 +97,12 @@ objc = "0.2.7"
 lazy-js-bundle = { workspace = true }
 
 [features]
-default = ["tokio_runtime", "transparent", "devtools"]
+default = ["tokio_runtime", "transparent", "devtools", "openssl-vendored-android"]
 tokio_runtime = ["dep:tokio"]
 fullscreen = ["wry/fullscreen"]
 devtools = ["wry/devtools", "dep:dioxus-devtools", "dioxus-signals"]
 transparent = ["wry/transparent"]
+openssl-vendored-android = ["openssl"]
 gnu = []
 
 [package.metadata.docs.rs]

+ 1 - 0
packages/desktop/src/lib.rs

@@ -18,6 +18,7 @@ mod file_upload;
 mod hooks;
 mod ipc;
 mod menubar;
+mod mobile;
 mod protocol;
 mod query;
 mod shortcut;

+ 65 - 0
packages/desktop/src/mobile.rs

@@ -0,0 +1,65 @@
+/// Expose the `Java_dev_dioxus_main_WryActivity_create` function to the JNI layer.
+/// We hardcode these to have a single trampoline for host Java code to call into.
+///
+/// This saves us from having to plumb the top-level package name all the way down into
+/// this file. This is better for modularity (ie just call dioxus' main to run the app) as
+/// well as cache thrashing since this crate doesn't rely on external env vars.
+///
+/// The CLI is expecting to find `dev.dioxus.main` in the final library. If you find a need to
+/// change this, you'll need to change the CLI as well.
+#[cfg(target_os = "android")]
+#[no_mangle]
+#[inline(never)]
+pub extern "C" fn start_app() {
+    use crate::Config;
+    use dioxus_core::{Element, VirtualDom};
+    use std::any::Any;
+
+    tao::android_binding!(dev_dioxus, main, WryActivity, wry::android_setup, root, tao);
+    wry::android_binding!(dev_dioxus, main, wry);
+
+    #[cfg(target_os = "android")]
+    fn root() {
+        fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
+            match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
+                Ok(t) => t,
+                Err(err) => {
+                    eprintln!("attempt to unwind out of `rust` with err: {:?}", err);
+                    std::process::abort()
+                }
+            }
+        }
+
+        stop_unwind(|| unsafe {
+            let mut main_fn_ptr = libc::dlsym(libc::RTLD_DEFAULT, b"main\0".as_ptr() as _);
+
+            if main_fn_ptr.is_null() {
+                main_fn_ptr = libc::dlsym(libc::RTLD_DEFAULT, b"_main\0".as_ptr() as _);
+            }
+
+            if main_fn_ptr.is_null() {
+                panic!("Failed to find main symbol");
+            }
+
+            // Set the env vars that rust code might expect, passed off to us by the android app
+            // Doing this before main emulates the behavior of a regular executable
+            if cfg!(target_os = "android") && cfg!(debug_assertions) {
+                // Load the env file from the session cache if we're in debug mode and on android
+                //
+                // This is a slightly hacky way of being able to use std::env::var code in android apps without
+                // going through their custom java-based system.
+                let env_file = dioxus_cli_config::android_session_cache_dir().join(".env");
+                if let Ok(env_file) = std::fs::read_to_string(&env_file) {
+                    for line in env_file.lines() {
+                        if let Some((key, value)) = line.trim().split_once('=') {
+                            std::env::set_var(key, value);
+                        }
+                    }
+                }
+            }
+
+            let main_fn: extern "C" fn() = std::mem::transmute(main_fn_ptr);
+            main_fn();
+        });
+    }
+}

+ 1 - 2
packages/dioxus/Cargo.toml

@@ -22,7 +22,6 @@ dioxus-hooks = { workspace = true, optional = true }
 dioxus-signals = { workspace = true, optional = true }
 dioxus-router = { workspace = true, optional = true }
 dioxus-web = { workspace = true, default-features = false, optional = true }
-dioxus-mobile = { workspace = true, optional = true }
 dioxus-desktop = { workspace = true, default-features = true, optional = true }
 dioxus-fullstack = { workspace = true, default-features = true, optional = true }
 dioxus-liveview = { workspace = true, optional = true }
@@ -80,7 +79,7 @@ router = ["dep:dioxus-router"]
 # Platforms
 fullstack = ["dep:dioxus-fullstack", "dioxus-config-macro/fullstack", "dep:serde"]
 desktop = ["dep:dioxus-desktop", "dioxus-fullstack?/desktop", "dioxus-config-macro/desktop"]
-mobile = ["dep:dioxus-mobile", "dep:dioxus-desktop", "dioxus-fullstack?/mobile", "dioxus-config-macro/mobile"]
+mobile = ["dep:dioxus-desktop", "dioxus-fullstack?/mobile", "dioxus-config-macro/mobile"]
 web = [
   "dep:dioxus-web",
   "dioxus-fullstack?/web",

+ 1 - 1
packages/dioxus/src/launch.rs

@@ -332,7 +332,7 @@ impl LaunchBuilder {
 
         #[cfg(feature = "mobile")]
         if matches!(platform, KnownPlatform::Mobile) {
-            return dioxus_mobile::launch_bindings::launch(app, contexts, configs);
+            return dioxus_desktop::launch::launch(app, contexts, configs);
         }
 
         #[cfg(feature = "desktop")]

+ 1 - 1
packages/dioxus/src/lib.rs

@@ -100,7 +100,7 @@ pub use dioxus_desktop as desktop;
 
 #[cfg(feature = "mobile")]
 #[cfg_attr(docsrs, doc(cfg(feature = "mobile")))]
-pub use dioxus_mobile as mobile;
+pub use dioxus_desktop as mobile;
 
 #[cfg(feature = "liveview")]
 #[cfg_attr(docsrs, doc(cfg(feature = "liveview")))]

+ 0 - 3
packages/fullstack/Cargo.toml

@@ -36,9 +36,6 @@ dioxus-interpreter-js = { workspace = true, optional = true }
 # Desktop Integration
 dioxus-desktop = { workspace = true, optional = true }
 
-# Mobile Integration
-dioxus-mobile = { workspace = true, optional = true }
-
 tracing = { workspace = true }
 tracing-futures = { workspace = true, optional = true }
 tokio-util = { workspace = true, features = ["rt"], optional = true }

+ 0 - 5
packages/mobile/.cargo/config.toml

@@ -1,5 +0,0 @@
-[build]
-target = [
-    "aarch64-apple-ios",
-    "aarch64-linux-android"
-]

+ 0 - 4
packages/mobile/.vscode/settings.json

@@ -1,4 +0,0 @@
-{
-    "rust-analyzer.inlayHints.enable": true,
-    "rust-analyzer.checkOnSave.allTargets": true,
-}

+ 0 - 43
packages/mobile/Cargo.toml

@@ -1,43 +0,0 @@
-[package]
-name = "dioxus-mobile"
-version = { workspace = true }
-authors = ["Jonathan Kelley"]
-edition = "2021"
-description = "Mobile-compatible renderer for Dioxus"
-repository = "https://github.com/DioxusLabs/dioxus/"
-homepage = "https://dioxuslabs.com/learn/0.6/getting_started"
-keywords = ["dom", "ui", "gui", "react"]
-license = "MIT OR Apache-2.0"
-rust-version = "1.71.1"
-
-[dependencies]
-dioxus-desktop = { workspace = true }
-dioxus-lib = { workspace = true }
-dioxus-cli-config = { workspace = true }
-libc = "0.2.170"
-
-[target.'cfg(target_os = "android")'.dependencies]
-jni = "0.21.1"
-
-# The `openssl` dependency generally does not know how to cross-compile for Android. To make the lives
-# of our users easier, we automatically enable the `openssl` feature when building for Android.
-# Feature are additive, so users will need to "subtract" this feature if they do not want it.
-openssl = { version = "0.10", features = ["vendored"], optional = true }
-
-[features]
-default = ["tokio_runtime", "devtools", "android-vendored-ssl"]
-android-vendored-ssl = ["openssl"]
-tokio_runtime = ["dioxus-desktop/tokio_runtime"]
-fullscreen = ["dioxus-desktop/fullscreen"]
-transparent = ["dioxus-desktop/transparent"]
-devtools = ["dioxus-desktop/devtools"]
-gnu = ["dioxus-desktop/gnu"]
-
-
-[lib]
-doctest = false
-# tests suspended until package ready
-test = false
-
-[package.metadata.docs.rs]
-cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

+ 0 - 7
packages/mobile/Makefile.toml

@@ -1,7 +0,0 @@
-[tasks.test]
-command = "cargo"
-args = [
-  "test",
-  "--no-run",
-]
-

+ 0 - 47
packages/mobile/README.md

@@ -1,47 +0,0 @@
-# Dioxus Mobile
-
-[![Crates.io][crates-badge]][crates-url]
-[![MIT licensed][mit-badge]][mit-url]
-[![Build Status][actions-badge]][actions-url]
-[![Discord chat][discord-badge]][discord-url]
-
-[crates-badge]: https://img.shields.io/crates/v/dioxus-mobile.svg
-[crates-url]: https://crates.io/crates/dioxus-mobile
-[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
-[mit-url]: https://github.com/dioxuslabs/dioxus/blob/main/LICENSE-MIT
-[actions-badge]: https://github.com/dioxuslabs/dioxus/actions/workflows/main.yml/badge.svg
-[actions-url]: https://github.com/dioxuslabs/dioxus/actions?query=workflow%3ACI+branch%3Amaster
-[discord-badge]: https://img.shields.io/discord/899851952891002890.svg?logo=discord&style=flat-square
-[discord-url]: https://discord.gg/XgGxMSkvUM
-
-[Website](https://dioxuslabs.com) |
-[Guides](https://dioxuslabs.com/learn/0.6/) |
-[API Docs](https://docs.rs/dioxus-mobile/latest/dioxus_mobile) |
-[Chat](https://discord.gg/XgGxMSkvUM)
-
-## Overview
-
-`dioxus-mobile` is a re-export of `dioxus-desktop` with some minor tweaks and documentation changes. As this crate evolves, it will provide some more unique features to mobile, but for now, it's very similar to the desktop crate.
-
-Dioxus Mobile supports both iOS and Android. However, Android support is still quite experimental and requires a lot of configuration. A good area to contribute here would be to improve the CLI tool to include bundling and mobile configuration.
-
-## Getting Set up
-
-Getting set up with mobile can but quite challenging. The tooling here isn't great (yet) and might take some hacking around to get things working. macOS M1 is broadly unexplored and might not work for you.
-
-You can read [our guide](https://dioxuslabs.com/learn/0.6/getting_started) on mobile development with Dioxus to get started.
-
-## Contributing
-
-- Report issues on our [issue tracker](https://github.com/dioxuslabs/dioxus/issues).
-- Join the discord and ask questions!
-
-## License
-
-This project is licensed under the [MIT license].
-
-[mit license]: https://github.com/dioxuslabs/dioxus/blob/main/LICENSE-MIT
-
-Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you shall be licensed as MIT without any additional
-terms or conditions.

+ 0 - 105
packages/mobile/src/lib.rs

@@ -1,105 +0,0 @@
-#![doc = include_str!("../README.md")]
-#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
-#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
-
-pub use dioxus_desktop::*;
-// intentionally shadow the launch module as it does not work on mobile.
-pub mod launch {}
-
-use dioxus_lib::prelude::*;
-use std::any::Any;
-
-pub mod launch_bindings {
-
-    use super::*;
-    pub fn launch(
-        root: fn() -> Element,
-        contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
-        platform_config: Vec<Box<dyn Any>>,
-    ) {
-        super::launch_cfg(root, contexts, platform_config);
-    }
-
-    pub fn launch_virtual_dom(_virtual_dom: VirtualDom, _desktop_config: Config) -> ! {
-        todo!()
-    }
-}
-
-/// Launch via the binding API
-pub fn launch(root: fn() -> Element) {
-    launch_cfg(root, vec![], vec![]);
-}
-
-pub fn launch_cfg(
-    root: fn() -> Element,
-    contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
-    platform_config: Vec<Box<dyn Any>>,
-) {
-    dioxus_desktop::launch::launch(root, contexts, platform_config);
-}
-
-#[doc(hidden)]
-pub fn root() {
-    fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
-        match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
-            Ok(t) => t,
-            Err(err) => {
-                eprintln!("attempt to unwind out of `rust` with err: {:?}", err);
-                std::process::abort()
-            }
-        }
-    }
-
-    stop_unwind(|| unsafe {
-        let mut main_fn_ptr = libc::dlsym(libc::RTLD_DEFAULT, b"main\0".as_ptr() as _);
-
-        if main_fn_ptr.is_null() {
-            main_fn_ptr = libc::dlsym(libc::RTLD_DEFAULT, b"_main\0".as_ptr() as _);
-        }
-
-        if main_fn_ptr.is_null() {
-            panic!("Failed to find main symbol");
-        }
-
-        // Set the env vars that rust code might expect, passed off to us by the android app
-        // Doing this before main emulates the behavior of a regular executable
-        if cfg!(target_os = "android") && cfg!(debug_assertions) {
-            load_env_file_from_session_cache();
-        }
-
-        let main_fn: extern "C" fn() = std::mem::transmute(main_fn_ptr);
-        main_fn();
-    });
-}
-
-/// Expose the `Java_dev_dioxus_main_WryActivity_create` function to the JNI layer.
-/// We hardcode these to have a single trampoline for host Java code to call into.
-///
-/// This saves us from having to plumb the top-level package name all the way down into
-/// this file. This is better for modularity (ie just call dioxus' main to run the app) as
-/// well as cache thrashing since this crate doesn't rely on external env vars.
-///
-/// The CLI is expecting to find `dev.dioxus.main` in the final library. If you find a need to
-/// change this, you'll need to change the CLI as well.
-#[cfg(target_os = "android")]
-#[no_mangle]
-#[inline(never)]
-pub extern "C" fn start_app() {
-    tao::android_binding!(dev_dioxus, main, WryActivity, wry::android_setup, root, tao);
-    wry::android_binding!(dev_dioxus, main, wry);
-}
-
-/// Load the env file from the session cache if we're in debug mode and on android
-///
-/// This is a slightly hacky way of being able to use std::env::var code in android apps without
-/// going through their custom java-based system.
-fn load_env_file_from_session_cache() {
-    let env_file = dioxus_cli_config::android_session_cache_dir().join(".env");
-    if let Ok(env_file) = std::fs::read_to_string(&env_file) {
-        for line in env_file.lines() {
-            if let Some((key, value)) = line.trim().split_once('=') {
-                std::env::set_var(key, value);
-            }
-        }
-    }
-}