@@ -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" ;
@@ -117,11 +129,28 @@ impl Node {
117129 Node { version }
118130 }
119131
120- pub fn archive_basename ( version : & str ) -> String {
132+ #[ cfg( not( all( target_os = "macos" , target_arch = "aarch64" ) ) ) ]
133+ pub fn archive_basename ( version : & Version ) -> String {
121134 format ! ( "node-v{}-{}-{}" , version, NODE_DISTRO_OS , NODE_DISTRO_ARCH )
122135 }
123136
124- pub fn archive_filename ( version : & str ) -> String {
137+ #[ cfg( all( target_os = "macos" , target_arch = "aarch64" ) ) ]
138+ pub fn archive_basename ( version : & Version ) -> String {
139+ // Note: Node began shipping pre-built binaries for Apple Silicon with Major version 16
140+ // Prior to that, we need to fall back on the x64 binaries
141+ format ! (
142+ "node-v{}-{}-{}" ,
143+ version,
144+ NODE_DISTRO_OS ,
145+ if version. major >= 16 {
146+ NODE_DISTRO_ARCH
147+ } else {
148+ NODE_DISTRO_ARCH_FALLBACK
149+ }
150+ )
151+ }
152+
153+ pub fn archive_filename ( version : & Version ) -> String {
125154 format ! (
126155 "{}.{}" ,
127156 Node :: archive_basename( version) ,
@@ -230,15 +259,15 @@ mod tests {
230259 #[ test]
231260 fn test_node_archive_basename ( ) {
232261 assert_eq ! (
233- Node :: archive_basename( "1.2.3" ) ,
262+ Node :: archive_basename( & Version :: new ( 1 , 2 , 3 ) ) ,
234263 format!( "node-v1.2.3-{}-{}" , NODE_DISTRO_OS , NODE_DISTRO_ARCH )
235264 ) ;
236265 }
237266
238267 #[ test]
239268 fn test_node_archive_filename ( ) {
240269 assert_eq ! (
241- Node :: archive_filename( "1.2.3" ) ,
270+ Node :: archive_filename( & Version :: new ( 1 , 2 , 3 ) ) ,
242271 format!(
243272 "node-v1.2.3-{}-{}.{}" ,
244273 NODE_DISTRO_OS , NODE_DISTRO_ARCH , NODE_DISTRO_EXTENSION
0 commit comments