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

build arm64 even on rosetta ... improve #149 #292

Closed heinthanth closed 2 years ago

heinthanth commented 2 years ago

On M1 macs, since we don't have arm binaries for choosenim, we can use x86 choosenim to download and invoke compiler. By default choosenim under rosetta build x86 nim. But passing arch -arm64 will build arm64 nim binary. This add improvement to #149.

heinthanth commented 2 years ago

Hum ... quite interesting ... need to figure out ... ( It's like proxyexe causing it ... proxyexe need to be compiled as arm )

Screen Shot 2022-01-26 at 8 34 59 PM
heinthanth commented 2 years ago

Yes ... I compiled choosenim with ARM nim ( installed manually from source ) and this work!

Screen Shot 2022-01-26 at 10 29 45 PM
heinthanth commented 2 years ago

the problem here is embedded proxyexe is x86 binary. That's why binaries in ~/.nimble/bin are x86 although actually compiled toolchain in ~/.choosenim/toolchains/version/bin/ are arm64. So, we need to fetch cliparams.nim, common.nim, proxyexe.nim and re-compile proxyexe with recently built arm nim binary ( if first installed ).

So, instead, I'm try to cross-compile choosenim from intel to M1. Cross-compilation work. But analytics is not working.

heinthanth commented 2 years ago

Analytics not working on M1. Seems like segment fault from objc_msgSend. So, now, have to

Screen Shot 2022-01-27 at 11 05 16 AM

I've submitted an issue to puppy here https://github.com/treeform/puppy/issues/59.

heinthanth commented 2 years ago

Force pushed ... since I think I messed up. Everything is working file on both intel and m1 mac. I'll wait for Puppy https://github.com/treeform/puppy/pull/61 to be merged.

heinthanth commented 2 years ago

For now, I will close this PR. Since I'm not OK with travis ( ran out of credit - accidentally enable Consume paid credits for OSS ), I'll continue and reopen soon! Thanks @dom96 for your encouragement. Btw, can you fix travis first? it's seems broken.

This is a cool approach, thank you!

dom96 commented 2 years ago

the problem here is embedded proxyexe is x86 binary. That's why binaries in ~/.nimble/bin are x86 although actually compiled toolchain in ~/.choosenim/toolchains/version/bin/ are arm64.

Why is this a problem btw? all that matters is that the Nim binaries are arm64, no?

heinthanth commented 2 years ago

No ... proxyexe is x86 and if we run nim c something.nim, something also become x86.

dom96 commented 2 years ago

proxyexe just executes the arm64 Nim though, or am I missing something? why would proxyexe being arm64 matter in what nim c ... produces?

heinthanth commented 2 years ago

I've demo here:

I create a simple proxy which invoke my arm64 nim binary.

Screen Shot 2022-01-28 at 1 54 31 PM

Here, I have two nim binaries. I compiled proxy.nim with x86 nim.

Screen Shot 2022-01-28 at 1 54 46 PM

So, proxy binary become x86.

Screen Shot 2022-01-28 at 2 33 15 PM

Then, I tried to compile test.nim with proxy binary ( which, in turn, invoke arm64 nim binary ). But test binary become x86.

Screen Shot 2022-01-28 at 1 56 28 PM

I think, test.nim also become x86 since the parent process which invoke C compile is x86. Don't know much about nim internal stuffs ( how nim invoke c compiler ).

But when I compile test.nim with my nim arm64 binary, it become ARM.

Screen Shot 2022-01-28 at 1 57 09 PM

I think choosenim has two options:

If we want, we can discord too. We're friends on discord.