Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Default to cargo-zigbuild for ZED_BUILD_REMOTE_SERVER (#33391)

Cole Miller91c9281cea88
diff --git a/Cargo.lock b/Cargo.lock
index f0afdb02fea..979fc9441c5 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 6042e63fd98..5985bcae827 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 ffcf3b37834..e01f4cfb046 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",