volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
10.96k stars 230 forks source link

`volta install` fetches x64 executable on arm64 #1486

Open fynnfluegge opened 1 year ago

fynnfluegge commented 1 year ago

When I fetch a node runtime with volta on a terminal session with arch arm64 it fetches node with x64 executable.

What I did Make sure that my terminal session is on arm64:

Screenshot 2023-04-07 at 22 33 54

Fetching node 18: Screenshot 2023-04-07 at 22 34 37

Check current node version: Screenshot 2023-04-07 at 22 35 44

Check arch of current node version: Screenshot 2023-04-07 at 22 36 34

What I expect node -e 'console.log(process.arch)' should return arm64

Current workaround I have to use nvm for arm64 node executables

Volta Vserion 1.1.1

charlespierce commented 1 year ago

Hi @fynnfluegge, that's very strange! Can you check the arch of the actual Volta executable? The version for Apple Silicon should try to fetch the ARM Node if it's available and only fall back to x64 if it can't find an appropriate ARM one (e.g. on older versions of Node that don't have an ARM build).

fynnfluegge commented 1 year ago

Hi @charlespierce thanks maybe that's the point! My terminal starts by default with Rosetta emulator with x64. I installed Volta then which gave me x64 executable I think.

matti commented 5 months ago

lol

ssukienn commented 1 month ago

@charlespierce I wonder if this is the correct behavior now with universal binary of volta@2 installed in native terminal (mac m1 arm64) where

$ file  /Users/ssukienn/.volta/bin/volta
/Users/ssukienn/.volta/bin/volta: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64]
/Users/ssukienn/.volta/bin/volta (for architecture x86_64):     Mach-O 64-bit executable x86_64
/Users/ssukienn/.volta/bin/volta (for architecture arm64):      Mach-O 64-bit executable arm64

$ file  /Users/ssukienn/.volta/bin/node 
/Users/ssukienn/.volta/bin/node: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64]
/Users/ssukienn/.volta/bin/node (for architecture x86_64):      Mach-O 64-bit executable x86_64
/Users/ssukienn/.volta/bin/node (for architecture arm64):       Mach-O 64-bit executable arm64

$ node -p process.arch                  
x64

I have some conditional logic that expects arm64 and node is run on native terminal (not rosetta) but arch in node process is x64, which I think is missleading.

For now I will need to fallback to volta <2. Wonder if this is volta problem or not?

charlespierce commented 1 month ago

Hi @ssukienn, the universal binary shouldn't change the behavior, so that's odd! What version of Node is that running? Can you also share the output of file $(volta which node)? That should resolve the info about the actually installed Node binary.

I can't reproduce locally—also on an ARM64 Mac—Using the native terminal and the universal binary, I get the expected arm64 when running node -p process.arch

Is it possible that when Node was installed, you were in a Rosetta terminal? In that case it may launch the x64 portion of the universal binary, which would then only download the x64 node.

Separately, I wonder if we could improve our inventory to also consider architecture as well as version—that would alleviate the problem of installing a specific version with the "wrong" architecture, because the next time Volta was run with a different one, it would see that the matching architecture wasn't available and would then fetch the appropriate one.

ssukienn commented 1 month ago

Hi, ye I just discovered I entered some workload which works in node14... So it was that as there are no official binaries for arm. Sorry for the fuss and thanks for the help!

charlespierce commented 1 month ago

Ah ha, yeah that would do it! No worries, I still think it might make sense at some point in the future to include the architecture in the inventory check.