Skip to content

Commit

Permalink
feat: enable erlang for Windows (#4128)
Browse files Browse the repository at this point in the history
* feat: enable erlang for Windows

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
roele and autofix-ci[bot] authored Jan 16, 2025
1 parent a6f95d9 commit 33a6390
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
48 changes: 44 additions & 4 deletions src/plugins/core/erlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::path::PathBuf;
use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::config::SETTINGS;
use crate::file::{display_path, TarOptions};
use crate::file::display_path;
#[cfg(unix)]
use crate::file::TarOptions;
use crate::http::{HTTP, HTTP_FETCH};
use crate::install_context::InstallContext;
use crate::lock_file::LockFile;
Expand Down Expand Up @@ -67,6 +69,7 @@ impl ErlangPlugin {
Ok(())
}

#[cfg(not(windows))]
fn install_precompiled(
&self,
ctx: &InstallContext,
Expand Down Expand Up @@ -108,6 +111,40 @@ impl ErlangPlugin {
Ok(Some(tv))
}

#[cfg(windows)]
fn install_precompiled(
&self,
ctx: &InstallContext,
mut tv: ToolVersion,
) -> Result<Option<ToolVersion>> {
if SETTINGS.erlang.compile == Some(true) {
return Ok(None);
}
let release_tag = format!("OTP-{}", tv.version);
let gh_release = match github::get_release("erlang/otp", &release_tag) {
Ok(release) => release,
Err(e) => {
debug!("Failed to get release: {}", e);
return Ok(None);
}
};
let zip_name = format!("otp_{OS}_{version}.zip", version = tv.version);
let asset = match gh_release.assets.iter().find(|a| a.name == zip_name) {
Some(asset) => asset,
None => {
debug!("No asset found for {}", release_tag);
return Ok(None);
}
};
ctx.pr.set_message(format!("Downloading {}", zip_name));
let zip_path = tv.download_path().join(&zip_name);
HTTP.download_file(&asset.browser_download_url, &zip_path, Some(&ctx.pr))?;
self.verify_checksum(ctx, &mut tv, &zip_path)?;
ctx.pr.set_message(format!("Extracting {}", zip_name));
file::unzip(&zip_path, &tv.install_path())?;
Ok(Some(tv))
}

fn install_via_kerl(&self, _ctx: &InstallContext, tv: ToolVersion) -> Result<ToolVersion> {
self.update_kerl()?;

Expand Down Expand Up @@ -169,17 +206,20 @@ impl Backend for ErlangPlugin {
}
}

#[cfg(target_arch = "x86_64")]
#[cfg(all(target_arch = "x86_64", not(target_os = "windows")))]
pub const ARCH: &str = "x86_64";

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", not(target_os = "windows")))]
const ARCH: &str = "aarch64";

#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
const ARCH: &str = "unknown";

#[cfg(windows)]
const OS: &str = "win64";

#[cfg(macos)]
const OS: &str = "apple-darwin";

#[cfg(not(macos))]
#[cfg(not(any(windows, macos)))]
const OS: &str = "unknown";
17 changes: 0 additions & 17 deletions src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::toolset::ToolVersion;
mod bun;
mod deno;
mod elixir;
#[cfg(unix)]
mod erlang;
mod go;
mod java;
Expand All @@ -27,7 +26,6 @@ mod swift;
mod zig;

pub static CORE_PLUGINS: Lazy<BackendMap> = Lazy::new(|| {
#[cfg(unix)]
let plugins: Vec<Arc<dyn Backend>> = vec![
Arc::new(bun::BunPlugin::new()),
Arc::new(deno::DenoPlugin::new()),
Expand All @@ -42,21 +40,6 @@ pub static CORE_PLUGINS: Lazy<BackendMap> = Lazy::new(|| {
Arc::new(swift::SwiftPlugin::new()),
Arc::new(zig::ZigPlugin::new()),
];
#[cfg(windows)]
let plugins: Vec<Arc<dyn Backend>> = vec![
Arc::new(bun::BunPlugin::new()),
Arc::new(deno::DenoPlugin::new()),
Arc::new(elixir::ElixirPlugin::new()),
// Arc::new(erlang::ErlangPlugin::new()),
Arc::new(go::GoPlugin::new()),
Arc::new(java::JavaPlugin::new()),
Arc::new(node::NodePlugin::new()),
Arc::new(python::PythonPlugin::new()),
Arc::new(ruby::RubyPlugin::new()),
Arc::new(rust::RustPlugin::new()),
Arc::new(swift::SwiftPlugin::new()),
Arc::new(zig::ZigPlugin::new()),
];
plugins
.into_iter()
.map(|p| (p.id().to_string(), p))
Expand Down

0 comments on commit 33a6390

Please sign in to comment.