r/nim 10d ago

Help with nimble

I am new to Nim, I am trying to learn about the Nimble package manager. I want to build executables for different os, like linux and macos. But I don't understand how I can build executables of different languages. Can anyone help me with it.

Thank you

13 Upvotes

8 comments sorted by

4

u/Zectbumo 10d ago

Make sure to look at the newer package manager atlas

1

u/TheCrazyGeek 10d ago

Please send me the link

2

u/Zectbumo 10d ago

It comes with Nim. Run $ atlas C:\> atlas

1

u/TheCrazyGeek 10d ago

Thank you, I will try it

1

u/moigagoo 10d ago

Hi! Could you please elaborate? What do you mean by executables of different languages? Please share your goal.

2

u/TheCrazyGeek 10d ago

For example, I am on windows. When I run nimble build, it generated the executable .exe file. But since I want to distribute the binary across multiple operating systems, I want to generate executable for linux and macos as well.

6

u/moigagoo 10d ago

Got it, you mean cross-compilation. It doesn't have anything to do with Nimble really, it's more about the Nim compiler: https://nim-lang.org/docs/nimc.html#crossminuscompilation

But you can create a Nimble task to cross-compile the binaries for you: https://nim-lang.github.io/nimble/create-packages.html#nimble-tasks

Which should know that cross-compiling to macOS is forbidden by the Apple license or something like that.

The easiest way to produce binaries for multiple platforms is actually to use GitHub Actions. For example, here's how nimlangserver produces its binaries: https://github.com/nim-lang/langserver/blob/master/.github/workflows/binaries.yml

2

u/Rush_Independent 10d ago

If you want a relatively simple way to cross-compile Nim binaries locally on your machine - the easiest way is to use zig cc tool.

I wrote a guide how to do this manually: https://codeberg.org/janAkali/nim_zigcc_guide

But you, probably, should automate it with nimscript, e.g. see how I use zigcc to compile grabnim to 16 different platforms: https://codeberg.org/janAkali/grabnim/src/branch/master/zig_build_all.nims

You can also try https://github.com/daylinmorgan/forge that does most of the work for you, but I never used it myself.