Browse Source

feat: use arm for aarch64-darwin-node@16 platforms (#436)

remotes/origin/add-with-shims
Patrick Kilgore 4 years ago committed by GitHub
parent
commit
440c624263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      src/arch.rs
  2. 9
      src/commands/install.rs

25
src/arch.rs

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
#[derive(Clone, Debug)]
use crate::version::Version;
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Arch {
X86,
X64,
@ -10,26 +12,25 @@ pub enum Arch { @@ -10,26 +12,25 @@ pub enum Arch {
}
#[cfg(unix)]
/// Get a sane default architecture for the platform.
pub fn default_str() -> &'static str {
/// handle common case: Apple Silicon / Node < 16
pub fn get_safe_arch<'a>(arch: &'a Arch, version: &Version) -> &'a Arch {
use crate::system_info::{platform_arch, platform_name};
// TODO: Handle (arch, name, version) when Node v15+ supports darwin-arm64
match (platform_name(), platform_arch()) {
("darwin", "arm64") => "x64",
(_, arch) => arch,
}
return match (platform_name(), platform_arch(), version) {
("darwin", "arm64", Version::Semver(v)) if v.major < 16 => &Arch::X64,
_ => &arch,
};
}
#[cfg(windows)]
/// Get a sane default architecture for the platform.
pub fn default_str() -> &'static str {
return crate::system_info::platform_arch();
/// handle common case: Apple Silicon / Node < 16
pub fn get_safe_arch<'a>(arch: &'a Arch, _version: &Version) -> &'a Arch {
return &arch;
}
impl Default for Arch {
fn default() -> Arch {
match default_str().parse() {
match crate::system_info::platform_arch().parse() {
Ok(arch) => arch,
Err(e) => panic!("{}", e.details),
}

9
src/commands/install.rs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
use crate::alias::create_alias;
use crate::arch::get_safe_arch;
use crate::config::FnmConfig;
use crate::downloader::{install_node_dist, Error as DownloaderError};
use crate::lts::LtsType;
@ -91,13 +92,17 @@ impl super::command::Command for Install { @@ -91,13 +92,17 @@ impl super::command::Command for Install {
}
};
// Automatically swap Apple Silicon to x64 arch for appropriate versions.
let safe_arch = get_safe_arch(&config.arch, &version);
let version_str = format!("Node {}", &version);
outln!(config#Info, "Installing {}", version_str.cyan());
outln!(config#Info, "Installing {} ({})", version_str.cyan(), safe_arch.to_string());
match install_node_dist(
&version,
&config.node_dist_mirror,
config.installations_dir(),
&config.arch,
safe_arch,
) {
Err(err @ DownloaderError::VersionAlreadyInstalled { .. }) => {
outln!(config#Error, "{} {}", "warning:".bold().yellow(), err);

Loading…
Cancel
Save