Skip to content
Merged
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
38 changes: 36 additions & 2 deletions crates/languages/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl RustLspAdapter {
#[cfg(target_os = "linux")]
impl RustLspAdapter {
const GITHUB_ASSET_KIND: AssetKind = AssetKind::Gz;
const ARCH_SERVER_NAME: &str = "unknown-linux-gnu";
const ARCH_SERVER_NAME: &str = "unknown-linux";
}

#[cfg(target_os = "freebsd")]
Expand All @@ -58,18 +58,52 @@ impl RustLspAdapter {
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("rust-analyzer");

impl RustLspAdapter {
#[cfg(target_os = "linux")]
fn build_arch_server_name_linux() -> String {
enum LibcType {
Gnu,
Musl,
}

let has_musl = std::fs::exists(&format!("/lib/ld-musl-{}.so.1", std::env::consts::ARCH))
.unwrap_or(false);
let has_gnu = std::fs::exists(&format!("/lib/ld-linux-{}.so.1", std::env::consts::ARCH))
.unwrap_or(false);

let libc_type = match (has_musl, has_gnu) {
(true, _) => LibcType::Musl,
(_, true) => LibcType::Gnu,
_ => {
// defaulting to gnu because nix doesn't have either of those files due to not following FHS
LibcType::Gnu
}
};

let libc = match libc_type {
LibcType::Musl => "musl",
LibcType::Gnu => "gnu",
};

format!("{}-{}", Self::ARCH_SERVER_NAME, libc)
}

fn build_asset_name() -> String {
let extension = match Self::GITHUB_ASSET_KIND {
AssetKind::TarGz => "tar.gz",
AssetKind::Gz => "gz",
AssetKind::Zip => "zip",
};

#[cfg(target_os = "linux")]
let arch_server_name = Self::build_arch_server_name_linux();
#[cfg(not(target_os = "linux"))]
let arch_server_name = Self::ARCH_SERVER_NAME.to_string();

format!(
"{}-{}-{}.{}",
SERVER_NAME,
std::env::consts::ARCH,
Self::ARCH_SERVER_NAME,
&arch_server_name,
extension
)
}
Expand Down
Loading