Skip to content

Commit

Permalink
remote_server: Remove dependency on libssl and libcrypto (#15446)
Browse files Browse the repository at this point in the history
Fixes: #15599
Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Conrad <conrad@zed.dev>
  • Loading branch information
3 people committed Sep 18, 2024
1 parent 9016de5 commit 2c8a6ee
Show file tree
Hide file tree
Showing 41 changed files with 670 additions and 226 deletions.
176 changes: 145 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ members = [
"crates/indexed_docs",
"crates/inline_completion_button",
"crates/install_cli",
"crates/isahc_http_client",
"crates/journal",
"crates/language",
"crates/language_model",
Expand Down Expand Up @@ -173,6 +174,9 @@ members = [
default-members = ["crates/zed"]

[workspace.dependencies]



#
# Workspace member crates
#
Expand Down Expand Up @@ -212,6 +216,7 @@ file_icons = { path = "crates/file_icons" }
fs = { path = "crates/fs" }
fsevent = { path = "crates/fsevent" }
fuzzy = { path = "crates/fuzzy" }
isahc_http_client = { path = "crates/isahc_http_client" }
git = { path = "crates/git" }
git_hosting_providers = { path = "crates/git_hosting_providers" }
go_to_line = { path = "crates/go_to_line" }
Expand Down Expand Up @@ -394,6 +399,8 @@ runtimelib = { version = "0.15", default-features = false, features = [
] }
rustc-demangle = "0.1.23"
rust-embed = { version = "8.4", features = ["include-exclude"] }
rustls = "0.20.3"
rustls-native-certs = "0.8.0"
schemars = { version = "0.8", features = ["impl_json_schema"] }
semver = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
Expand Down
1 change: 0 additions & 1 deletion crates/auto_update/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ db.workspace = true
editor.workspace = true
gpui.workspace = true
http_client.workspace = true
isahc.workspace = true
log.workspace = true
markdown_preview.workspace = true
menu.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use gpui::{
actions, AppContext, AsyncAppContext, Context as _, Global, Model, ModelContext,
SemanticVersion, SharedString, Task, View, ViewContext, VisualContext, WindowContext,
};
use isahc::AsyncBody;

use markdown_preview::markdown_preview_view::{MarkdownPreviewMode, MarkdownPreviewView};
use schemars::JsonSchema;
Expand All @@ -20,7 +19,7 @@ use smol::{fs, io::AsyncReadExt};
use settings::{Settings, SettingsSources, SettingsStore};
use smol::{fs::File, process::Command};

use http_client::{HttpClient, HttpClientWithUrl};
use http_client::{AsyncBody, HttpClient, HttpClientWithUrl};
use release_channel::{AppCommitSha, AppVersion, ReleaseChannel};
use std::{
env::{
Expand Down
4 changes: 3 additions & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test-support = ["clock/test-support", "collections/test-support", "gpui/test-sup
[dependencies]
anyhow.workspace = true
async-recursion = "0.3"
async-tungstenite = { workspace = true, features = ["async-std", "async-native-tls"] }
async-tungstenite = { workspace = true, features = ["async-std", "async-tls"] }
chrono = { workspace = true, features = ["serde"] }
clock.workspace = true
collections.workspace = true
Expand All @@ -35,6 +35,8 @@ postage.workspace = true
rand.workspace = true
release_channel.workspace = true
rpc = { workspace = true, features = ["gpui"] }
rustls.workspace = true
rustls-native-certs.workspace = true
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
42 changes: 29 additions & 13 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ pub enum EstablishConnectionError {
#[error("{0}")]
Other(#[from] anyhow::Error),
#[error("{0}")]
Http(#[from] http_client::Error),
#[error("{0}")]
InvalidHeaderValue(#[from] async_tungstenite::tungstenite::http::header::InvalidHeaderValue),
#[error("{0}")]
Io(#[from] std::io::Error),
Expand Down Expand Up @@ -529,19 +527,13 @@ impl Client {
}

pub fn production(cx: &mut AppContext) -> Arc<Self> {
let user_agent = format!(
"Zed/{} ({}; {})",
AppVersion::global(cx),
std::env::consts::OS,
std::env::consts::ARCH
);
let clock = Arc::new(clock::RealSystemClock);
let http = Arc::new(HttpClientWithUrl::new(
let http = Arc::new(HttpClientWithUrl::new_uri(
cx.http_client(),
&ClientSettings::get_global(cx).server_url,
Some(user_agent),
ProxySettings::get_global(cx).proxy.clone(),
cx.http_client().proxy().cloned(),
));
Self::new(clock, http.clone(), cx)
Self::new(clock, http, cx)
}

pub fn id(&self) -> u64 {
Expand Down Expand Up @@ -1145,8 +1137,32 @@ impl Client {

match url_scheme {
Https => {
let client_config = {
let mut root_store = rustls::RootCertStore::empty();

let root_certs = rustls_native_certs::load_native_certs();
for error in root_certs.errors {
log::warn!("error loading native certs: {:?}", error);
}
root_store.add_parsable_certificates(
&root_certs
.certs
.into_iter()
.map(|cert| cert.as_ref().to_owned())
.collect::<Vec<_>>(),
);
rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth()
};
let (stream, _) =
async_tungstenite::async_std::client_async_tls(request, stream).await?;
async_tungstenite::async_tls::client_async_tls_with_connector(
request,
stream,
Some(client_config.into()),
)
.await?;
Ok(Connection::new(
stream
.map_err(|error| anyhow!(error))
Expand Down
1 change: 1 addition & 0 deletions crates/collab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ envy = "0.4.2"
futures.workspace = true
google_ai.workspace = true
hex.workspace = true
isahc_http_client.workspace = true
http_client.workspace = true
jsonwebtoken.workspace = true
live_kit_server.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/collab/src/llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use chrono::{DateTime, Duration, Utc};
use collections::HashMap;
use db::{usage_measure::UsageMeasure, ActiveUserCount, LlmDatabase};
use futures::{Stream, StreamExt as _};
use http_client::IsahcHttpClient;
use isahc_http_client::IsahcHttpClient;
use rpc::ListModelsResponse;
use rpc::{
proto::Plan, LanguageModelProvider, PerformCompletionParams, EXPIRED_LLM_TOKEN_HEADER_NAME,
Expand Down Expand Up @@ -72,6 +72,7 @@ impl LlmState {
let http_client = IsahcHttpClient::builder()
.default_header("User-Agent", user_agent)
.build()
.map(IsahcHttpClient::from)
.context("failed to construct http client")?;

let this = Self {
Expand Down
8 changes: 5 additions & 3 deletions crates/collab/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use chrono::Utc;
use collections::{HashMap, HashSet};
pub use connection_pool::{ConnectionPool, ZedVersion};
use core::fmt::{self, Debug, Formatter};
use http_client::HttpClient;
use isahc_http_client::IsahcHttpClient;
use open_ai::{OpenAiEmbeddingModel, OPEN_AI_API_URL};
use sha2::Digest;
use supermaven_api::{CreateExternalUserRequest, SupermavenAdminApi};
Expand All @@ -45,7 +47,6 @@ use futures::{
stream::FuturesUnordered,
FutureExt, SinkExt, StreamExt, TryStreamExt,
};
use http_client::IsahcHttpClient;
use prometheus::{register_int_gauge, IntGauge};
use rpc::{
proto::{
Expand Down Expand Up @@ -139,7 +140,7 @@ struct Session {
connection_pool: Arc<parking_lot::Mutex<ConnectionPool>>,
app_state: Arc<AppState>,
supermaven_client: Option<Arc<SupermavenAdminApi>>,
http_client: Arc<IsahcHttpClient>,
http_client: Arc<dyn HttpClient>,
/// The GeoIP country code for the user.
#[allow(unused)]
geoip_country_code: Option<String>,
Expand Down Expand Up @@ -955,9 +956,10 @@ impl Server {

tracing::info!("connection opened");


let user_agent = format!("Zed Server/{}", env!("CARGO_PKG_VERSION"));
let http_client = match IsahcHttpClient::builder().default_header("User-Agent", user_agent).build() {
Ok(http_client) => Arc::new(http_client),
Ok(http_client) => Arc::new(IsahcHttpClient::from(http_client)),
Err(error) => {
tracing::error!(?error, "failed to create HTTP client");
return;
Expand Down
1 change: 1 addition & 0 deletions crates/evals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ feature_flags.workspace = true
fs.workspace = true
git.workspace = true
gpui.workspace = true
isahc_http_client.workspace = true
language.workspace = true
languages.workspace = true
http_client.workspace = true
Expand Down
22 changes: 13 additions & 9 deletions crates/evals/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ fn main() -> Result<()> {

gpui::App::headless().run(move |cx| {
let executor = cx.background_executor().clone();

let client = isahc_http_client::IsahcHttpClient::new(None, None);
cx.set_http_client(client.clone());
match cli.command {
Commands::Fetch {} => {
executor
.clone()
.spawn(async move {
if let Err(err) = fetch_evaluation_resources(&executor).await {
if let Err(err) = fetch_evaluation_resources(client, &executor).await {
eprintln!("Error: {}", err);
exit(1);
}
Expand All @@ -127,10 +128,12 @@ fn main() -> Result<()> {
Ok(())
}

async fn fetch_evaluation_resources(executor: &BackgroundExecutor) -> Result<()> {
let http_client = http_client::HttpClientWithProxy::new(None, None);
fetch_code_search_net_resources(&http_client).await?;
fetch_eval_repos(executor, &http_client).await?;
async fn fetch_evaluation_resources(
http_client: Arc<dyn HttpClient>,
executor: &BackgroundExecutor,
) -> Result<()> {
fetch_code_search_net_resources(&*http_client).await?;
fetch_eval_repos(executor, &*http_client).await?;
Ok(())
}

Expand Down Expand Up @@ -239,6 +242,7 @@ async fn run_evaluation(
executor: &BackgroundExecutor,
cx: &mut AsyncAppContext,
) -> Result<()> {
let mut http_client = None;
cx.update(|cx| {
let mut store = SettingsStore::new(cx);
store
Expand All @@ -248,15 +252,15 @@ async fn run_evaluation(
client::init_settings(cx);
language::init(cx);
Project::init_settings(cx);
http_client = Some(cx.http_client());
cx.update_flags(false, vec![]);
})
.unwrap();

let http_client = http_client.unwrap();
let dataset_dir = Path::new(CODESEARCH_NET_DIR);
let evaluations_path = dataset_dir.join("evaluations.json");
let repos_dir = Path::new(EVAL_REPOS_DIR);
let db_path = Path::new(EVAL_DB_PATH);
let http_client = http_client::HttpClientWithProxy::new(None, None);
let api_key = std::env::var("OPENAI_API_KEY").unwrap();
let git_hosting_provider_registry = Arc::new(GitHostingProviderRegistry::new());
let fs = Arc::new(RealFs::new(git_hosting_provider_registry, None)) as Arc<dyn Fs>;
Expand All @@ -266,9 +270,9 @@ async fn run_evaluation(
Client::new(
clock,
Arc::new(http_client::HttpClientWithUrl::new(
http_client.clone(),
"https://zed.dev",
None,
None,
)),
cx,
)
Expand Down
1 change: 1 addition & 0 deletions crates/extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ task.workspace = true
serde_json_lenient.workspace = true

[dev-dependencies]
isahc_http_client.workspace = true
ctor.workspace = true
env_logger.workspace = true
parking_lot.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/extension/src/extension_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl ExtensionBuilder {
.args(scanner_path.exists().then_some(scanner_path))
.output()
.context("failed to run clang")?;

if !clang_output.status.success() {
bail!(
"failed to compile {} parser with clang: {}",
Expand Down Expand Up @@ -431,6 +432,7 @@ impl ExtensionBuilder {
let body = BufReader::new(response.body_mut());
let body = GzipDecoder::new(body);
let tar = Archive::new(body);

tar.unpack(&tar_out_dir)
.await
.context("failed to unpack wasi-sdk archive")?;
Expand Down
13 changes: 3 additions & 10 deletions crates/extension/src/extension_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub fn init(
None,
fs,
client.http_client().clone(),
client.http_client().clone(),
Some(client.telemetry().clone()),
node_runtime,
language_registry,
Expand Down Expand Up @@ -225,6 +226,7 @@ impl ExtensionStore {
build_dir: Option<PathBuf>,
fs: Arc<dyn Fs>,
http_client: Arc<HttpClientWithUrl>,
builder_client: Arc<dyn HttpClient>,
telemetry: Option<Arc<Telemetry>>,
node_runtime: Arc<dyn NodeRuntime>,
language_registry: Arc<LanguageRegistry>,
Expand All @@ -244,12 +246,7 @@ impl ExtensionStore {
extension_index: Default::default(),
installed_dir,
index_path,
builder: Arc::new(ExtensionBuilder::new(
// Construct a real HTTP client for the extension builder, as we
// don't want to use a fake one in the tests.
::http_client::client(None, http_client.proxy().cloned()),
build_dir,
)),
builder: Arc::new(ExtensionBuilder::new(builder_client, build_dir)),
outstanding_operations: Default::default(),
modified_extensions: Default::default(),
reload_complete_senders: Vec::new(),
Expand Down Expand Up @@ -830,7 +827,6 @@ impl ExtensionStore {
let mut extension_manifest =
ExtensionManifest::load(fs.clone(), &extension_source_path).await?;
let extension_id = extension_manifest.id.clone();

if !this.update(&mut cx, |this, cx| {
match this.outstanding_operations.entry(extension_id.clone()) {
btree_map::Entry::Occupied(_) => return false,
Expand All @@ -854,7 +850,6 @@ impl ExtensionStore {
.ok();
}
});

cx.background_executor()
.spawn({
let extension_source_path = extension_source_path.clone();
Expand Down Expand Up @@ -885,10 +880,8 @@ impl ExtensionStore {
bail!("extension {extension_id} is already installed");
}
}

fs.create_symlink(output_path, extension_source_path)
.await?;

this.update(&mut cx, |this, cx| this.reload(None, cx))?
.await;
Ok(())
Expand Down
Loading

0 comments on commit 2c8a6ee

Please sign in to comment.