Skip to content

Commit f6f6b59

Browse files
committed
Add identifier fallback for Apple Silicon architecture
1 parent 5f39583 commit f6f6b59

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

crates/volta-core/src/tool/node/metadata.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::HashSet;
22

33
use super::NODE_DISTRO_IDENTIFIER;
4+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
5+
use super::NODE_DISTRO_IDENTIFIER_FALLBACK;
46
use crate::version::{option_version_serde, version_serde};
57
use semver::Version;
68
use serde::{Deserialize, Deserializer};
@@ -37,6 +39,7 @@ impl From<RawNodeIndex> for NodeIndex {
3739
.0
3840
.into_iter()
3941
.filter_map(|entry| {
42+
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
4043
if entry.npm.is_some() && entry.files.contains(NODE_DISTRO_IDENTIFIER) {
4144
Some(NodeEntry {
4245
version: entry.version,
@@ -45,6 +48,19 @@ impl From<RawNodeIndex> for NodeIndex {
4548
} else {
4649
None
4750
}
51+
52+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
53+
if entry.npm.is_some()
54+
&& (entry.files.contains(NODE_DISTRO_IDENTIFIER)
55+
|| entry.files.contains(NODE_DISTRO_IDENTIFIER_FALLBACK))
56+
{
57+
Some(NodeEntry {
58+
version: entry.version,
59+
lts: entry.lts,
60+
})
61+
} else {
62+
None
63+
}
4864
})
4965
.collect();
5066

crates/volta-core/src/tool/node/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ cfg_if! {
3939
pub const NODE_DISTRO_EXTENSION: &str = "zip";
4040
/// The file identifier in the Node index `files` array
4141
pub const NODE_DISTRO_IDENTIFIER: &str = "win-x64-zip";
42-
} else if #[cfg(all(target_os = "macos", any(target_arch = "x86_64", target_arch = "aarch64")))] {
43-
// NOTE: Currently, Node does not provide prebuilt binaries for Apple M1 machines, so we
44-
// fall back to using the x64 binaries through Rosetta 2. When Node starts shipping M1
45-
// binaries, then we will need to adjust our logic to search for those first and only fall
46-
// back if they aren't found
47-
42+
} else if #[cfg(all(target_os = "macos", target_arch = "x86_64"))] {
4843
/// The OS component of a Node distro filename
4944
pub const NODE_DISTRO_OS: &str = "darwin";
5045
/// The architecture component of a Node distro filename
@@ -53,6 +48,23 @@ cfg_if! {
5348
pub const NODE_DISTRO_EXTENSION: &str = "tar.gz";
5449
/// The file identifier in the Node index `files` array
5550
pub const NODE_DISTRO_IDENTIFIER: &str = "osx-x64-tar";
51+
} else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] {
52+
/// The OS component of a Node distro filename
53+
pub const NODE_DISTRO_OS: &str = "darwin";
54+
/// The architecture component of a Node distro filename
55+
pub const NODE_DISTRO_ARCH: &str = "arm64";
56+
/// The extension for Node distro files
57+
pub const NODE_DISTRO_EXTENSION: &str = "tar.gz";
58+
/// The file identifier in the Node index `files` array
59+
pub const NODE_DISTRO_IDENTIFIER: &str = "osx-arm64-tar";
60+
61+
// NOTE: Node support for pre-built Apple Silicon binaries was added in major version 16
62+
// For versions prior to that, we need to fall back on the x64 binaries via Rosetta 2
63+
64+
/// The fallback architecture component of a Node distro filename
65+
pub const NODE_DISTRO_ARCH_FALLBACK: &str = "x64";
66+
/// The fallback file identifier in the Node index `files` array
67+
pub const NODE_DISTRO_IDENTIFIER_FALLBACK: &str = "osx-x64-tar";
5668
} else if #[cfg(all(target_os = "linux", target_arch = "x86_64"))] {
5769
/// The OS component of a Node distro filename
5870
pub const NODE_DISTRO_OS: &str = "linux";

0 commit comments

Comments
 (0)