dom96 / choosenim

Tool for easily installing and managing multiple versions of the Nim programming language.
BSD 3-Clause "New" or "Revised" License
679 stars 67 forks source link

choosenim breaks user code on M1 Mac #318

Open mode80 opened 1 year ago

mode80 commented 1 year ago

choosenim seems to break packages and user code when installing Nim on an M1 mac (Apple silicone, ARM64) .

The issue seems to be that choosenim compiles the nim compiler as an x86 executable. Checking this, I get:

$ file `which nim`
/Users/mode80/.nimble/bin/nim: Mach-O 64-bit executable x86_64

When packages and user code make use of code like when defined(arm64), it incorrectly reports false, and instead reports true for defined(amd64). The program usually crashes thereafter because whatever code path was needed for M1 doesn't run. (For example, the threading module using processor-specific assembly instructions based on this kind of check. )

When I install nim with homebrew, and test, I get

$ file `which nim`
/opt/homebrew/bin/nim: Mach-O 64-bit executable arm64

Then things work as expected.

quantimnot commented 1 year ago

I just wasted a lot of time on this myself.

Here is what I learned:

See Also

https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code