diff --git a/Cargo.lock b/Cargo.lock index f0afdb02fea529096262d6d96928ef0b7ada318f..979fc9441c593bb2bdd945a2cbca92779aaafa65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13168,6 +13168,7 @@ dependencies = [ "thiserror 2.0.12", "urlencoding", "util", + "which 6.0.3", "workspace-hack", ] diff --git a/crates/remote/Cargo.toml b/crates/remote/Cargo.toml index 6042e63fd98b4354b719f30d1a3f3e2fc33cdeb1..5985bcae827c42f4ae535b1dd859e436167e3fe5 100644 --- a/crates/remote/Cargo.toml +++ b/crates/remote/Cargo.toml @@ -41,6 +41,7 @@ tempfile.workspace = true thiserror.workspace = true urlencoding.workspace = true util.workspace = true +which.workspace = true workspace-hack.workspace = true [dev-dependencies] diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index ffcf3b378340d145bcf253932aecc3bc2d35c557..e01f4cfb0462baef01656755ebdd1abdcdd56d2c 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -2030,27 +2030,7 @@ impl SshRemoteConnection { }; smol::fs::create_dir_all("target/remote_server").await?; - if build_remote_server.contains("zigbuild") { - delegate.set_status( - Some(&format!( - "Building remote binary from source for {triple} with Zig" - )), - cx, - ); - log::info!("building remote binary from source for {triple} with Zig"); - run_cmd(Command::new("cargo").args([ - "zigbuild", - "--package", - "remote_server", - "--features", - "debug-embed", - "--target-dir", - "target/remote_server", - "--target", - &triple, - ])) - .await?; - } else { + if build_remote_server.contains("cross") { delegate.set_status(Some("Installing cross.rs for cross-compilation"), cx); log::info!("installing cross"); run_cmd(Command::new("cargo").args([ @@ -2088,12 +2068,50 @@ impl SshRemoteConnection { ), ) .await?; - } + } else { + let which = cx + .background_spawn(async move { which::which("zig") }) + .await; + + if which.is_err() { + anyhow::bail!( + "zig not found on $PATH, install zig (see https://ziglang.org/learn/getting-started or use zigup) or pass ZED_BUILD_REMOTE_SERVER=cross to use cross" + ) + } + + delegate.set_status(Some("Adding rustup target for cross-compilation"), cx); + log::info!("adding rustup target"); + run_cmd(Command::new("rustup").args(["target", "add"]).arg(&triple)).await?; - delegate.set_status(Some("Compressing binary"), cx); + delegate.set_status(Some("Installing cargo-zigbuild for cross-compilation"), cx); + log::info!("installing cargo-zigbuild"); + run_cmd(Command::new("cargo").args(["install", "--locked", "cargo-zigbuild"])).await?; + + delegate.set_status( + Some(&format!( + "Building remote binary from source for {triple} with Zig" + )), + cx, + ); + log::info!("building remote binary from source for {triple} with Zig"); + run_cmd(Command::new("cargo").args([ + "zigbuild", + "--package", + "remote_server", + "--features", + "debug-embed", + "--target-dir", + "target/remote_server", + "--target", + &triple, + ])) + .await?; + }; let mut path = format!("target/remote_server/{triple}/debug/remote_server").into(); if !build_remote_server.contains("nocompress") { + delegate.set_status(Some("Compressing binary"), cx); + run_cmd(Command::new("gzip").args([ "-9", "-f",