Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: device hot-reload, tools-relative adb, auto port bind #3586

Merged
merged 16 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions packages/cli-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,10 @@ macro_rules! read_env_config {
/// For reference, the devserver typically lives on `127.0.0.1:8080` and serves the devserver websocket
/// on `127.0.0.1:8080/_dioxus`.
pub fn devserver_raw_addr() -> Option<SocketAddr> {
// On android, 10.0.2.2 is the default loopback
if cfg!(target_os = "android") {
return Some("10.0.2.2:8080".parse().unwrap());
}

std::env::var(DEVSERVER_RAW_ADDR_ENV)
.map(|s| s.parse().ok())
.unwrap_or_else(|_| "127.0.0.1:8080".to_string())
.parse()
.ok()
.flatten()
}

/// Get the address of the devserver for use over a websocket
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ tauri-bundler = { workspace = true }
include_dir = "0.7.4"
flate2 = "1.0.35"
tar = "0.4.43"
local-ip-address = "0.6.3"
dircpy = "0.3.19"
plist = "1.7.0"

[build-dependencies]
built = { version = "=0.7.4", features = ["git2"] }
Expand Down
68 changes: 50 additions & 18 deletions packages/cli/assets/ios/ios.plist.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,59 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>{{ display_name }}</string>
<key>CFBundleDisplayName</key>
<string>{{ display_name }}</string>

<key>CFBundleExecutable</key>
<string>{{ executable_name }}</string>
<key>CFBundleExecutable</key>
<string>{{ executable_name }}</string>

<key>CFBundleIdentifier</key>
<string>{{ bundle_identifier }}</string>
<key>CFBundleIdentifier</key>
<string>{{ bundle_identifier }}</string>

<key>CFBundleName</key>
<string>{{ bundle_name }}</string>
<key>CFBundleName</key>
<string>{{ bundle_name }}</string>

<key>CFBundleVersion</key>
<string>0.1.0</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en_US</string>
<key>UILaunchStoryboardName</key>
<string></string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>CFBundleVersion</key>
<string>0.1.0</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en_US</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UISupportsTrueScreenSizeOnMac</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
<string>metal</string>
</array>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
<string>iPadOS</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion packages/cli/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl BuildArgs {
if self.platform == Some(Platform::Android) && self.target_args.arch.is_none() {
tracing::debug!("No android arch provided, attempting to auto detect.");

let arch = Arch::autodetect().await;
let arch = DioxusCrate::autodetect_android_arch().await;

// Some extra logs
let arch = match arch {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl ServeArgs {
}

pub(crate) fn is_interactive_tty(&self) -> bool {
use crossterm::tty::IsTty;
std::io::stdout().is_tty() && self.interactive.unwrap_or(true)
use std::io::IsTerminal;
std::io::stdout().is_terminal() && self.interactive.unwrap_or(true)
}

pub(crate) fn should_proxy_build(&self) -> bool {
Expand Down
44 changes: 0 additions & 44 deletions packages/cli/src/cli/target.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::*;
use once_cell::sync::OnceCell;
use std::path::Path;
use tokio::process::Command;

/// Information about the target to build
#[derive(Clone, Debug, Default, Deserialize, Parser)]
Expand Down Expand Up @@ -73,48 +71,6 @@ pub(crate) enum Arch {
}

impl Arch {
pub(crate) async fn autodetect() -> Option<Self> {
// Try auto detecting arch through adb.
static AUTO_ARCH: OnceCell<Option<Arch>> = OnceCell::new();

match AUTO_ARCH.get() {
Some(a) => *a,
None => {
// TODO: Wire this up with --device flag. (add `-s serial`` flag before `shell` arg)
let output = Command::new("adb")
.arg("shell")
.arg("uname")
.arg("-m")
.output()
.await;

let out = match output {
Ok(o) => o,
Err(e) => {
tracing::debug!("ADB command failed: {:?}", e);
return None;
}
};

// Parse ADB output
let Ok(out) = String::from_utf8(out.stdout) else {
tracing::debug!("ADB returned unexpected data.");
return None;
};
let trimmed = out.trim().to_string();
tracing::trace!("ADB Returned: `{trimmed:?}`");

// Set the cell
let arch = Arch::try_from(trimmed).ok();
AUTO_ARCH
.set(arch)
.expect("the cell should have been checked empty by the match condition");

arch
}
}
}

pub(crate) fn android_target_triplet(&self) -> &'static str {
match self {
Arch::Arm => "armv7-linux-androideabi",
Expand Down
26 changes: 4 additions & 22 deletions packages/cli/src/config/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,13 @@ use clap::Parser;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};

/// The arguments for the address the server will run on
#[derive(Clone, Debug, Parser)]
#[derive(Clone, Debug, Default, Parser)]
pub(crate) struct AddressArguments {
/// The port the server will run on
#[clap(long)]
#[clap(default_value_t = default_port())]
pub(crate) port: u16,
pub(crate) port: Option<u16>,

/// The address the server will run on
#[clap(long, default_value_t = default_address())]
pub(crate) addr: std::net::IpAddr,
}

impl Default for AddressArguments {
fn default() -> Self {
Self {
port: default_port(),
addr: default_address(),
}
}
}

fn default_port() -> u16 {
8080
}

fn default_address() -> IpAddr {
IpAddr::V4(std::net::Ipv4Addr::new(127, 0, 0, 1))
#[clap(long)]
pub(crate) addr: Option<std::net::IpAddr>,
}
Loading
Loading