Bundle linux deps (#11681)

Conrad Irwin created

Inlcude linux deps in the bundle

Release Notes:

- N/A

Change summary

Cargo.lock               | 25 ++++++++++++++++++++++++-
crates/client/Cargo.toml |  8 ++++++++
script/bundle-linux      | 14 +++++++++++++-
3 files changed, 45 insertions(+), 2 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -621,6 +621,18 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "async-native-tls"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9343dc5acf07e79ff82d0c37899f079db3534d99f189a1837c8e549c99405bec"
+dependencies = [
+ "futures-util",
+ "native-tls",
+ "thiserror",
+ "url",
+]
+
 [[package]]
 name = "async-net"
 version = "1.7.0"
@@ -815,7 +827,7 @@ version = "0.16.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5682ea0913e5c20780fe5785abacb85a411e7437bf52a1bedb93ddb3972cb8dd"
 dependencies = [
- "async-native-tls",
+ "async-native-tls 0.3.3",
  "async-std",
  "futures-io",
  "futures-util",
@@ -2185,6 +2197,7 @@ name = "client"
 version = "0.1.0"
 dependencies = [
  "anyhow",
+ "async-native-tls 0.5.0",
  "async-recursion 0.3.2",
  "async-tungstenite",
  "chrono",
@@ -6899,6 +6912,15 @@ version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 
+[[package]]
+name = "openssl-src"
+version = "300.2.3+3.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5cff92b6f71555b61bb9315f7c64da3ca43d87531622120fea0195fc761b4843"
+dependencies = [
+ "cc",
+]
+
 [[package]]
 name = "openssl-sys"
 version = "0.9.93"
@@ -6907,6 +6929,7 @@ checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d"
 dependencies = [
  "cc",
  "libc",
+ "openssl-src",
  "pkg-config",
  "vcpkg",
 ]

crates/client/Cargo.toml 🔗

@@ -19,6 +19,7 @@ test-support = ["clock/test-support", "collections/test-support", "gpui/test-sup
 anyhow.workspace = true
 async-recursion = "0.3"
 async-tungstenite = { version = "0.16", features = ["async-std", "async-native-tls"] }
+async-native-tls = { version = "0.5.0", features = ["vendored"] }
 chrono = { workspace = true, features = ["serde"] }
 clock.workspace = true
 collections.workspace = true
@@ -58,3 +59,10 @@ rpc = { workspace = true, features = ["test-support"] }
 settings = { workspace = true, features = ["test-support"] }
 util = { workspace = true, features = ["test-support"] }
 http = { workspace = true, features = ["test-support"] }
+
+[target.'cfg(target_os = "linux")'.dependencies]
+async-native-tls = {"version" = "0.5.0", features = ["vendored"]}
+# This is an indirect dependency of async-tungstenite that is included
+# here so we can vendor libssl with the feature flag.
+[package.metadata.cargo-machete]
+ignored = ["async-native-tls"]

script/bundle-linux 🔗

@@ -27,7 +27,7 @@ export ZED_BUNDLE=true
 
 channel=$(<crates/zed/RELEASE_CHANNEL)
 
-version="$(cargo metadata --no-deps --manifest-path crates/zed/Cargo.toml --offline --format-version=1 | jq -r '.packages | map(select(.name == "zed"))[0].version')"
+version="$(script/get-crate-version zed)"
 # Set RELEASE_VERSION so it's compiled into GPUI and it knows about the version.
 export RELEASE_VERSION="${version}"
 
@@ -38,6 +38,7 @@ host_line=$(echo "$version_info" | grep host)
 target_triple=${host_line#*: }
 
 # Build binary in release mode
+export RUSTFLAGS="-C link-args=-Wl,-rpath,\$ORIGIN/../lib"
 cargo build --release --target "${target_triple}" --package zed --package cli
 
 # Strip the binary of all debug symbols
@@ -60,6 +61,17 @@ mkdir -p "${zed_dir}/bin"
 cp "target/${target_triple}/release/Zed" "${zed_dir}/bin/zed"
 cp "target/${target_triple}/release/cli" "${zed_dir}/bin/cli"
 
+# Libs
+find_libs() {
+    ldd target/debug/Zed |\
+    cut -d' ' -f3 |\
+    grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\)'
+}
+
+mkdir -p "${zed_dir}/lib"
+rm -rf "${zed_dir}/lib/*"
+cp $(find_libs) "${zed_dir}/lib"
+
 # Icons
 mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
 cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"