this is a project to compile nim code to Actually Portable Executable with the help of cosmocc & cosmopolitan
the intention of creating this project is that the cosmonim repository https://github.com/rfesi/cosmonim uses cosmopolitan-amalgamation which in the newer versions of cosmopolitan don't exist Instead this uses cosmocc.
I really suck at writing so this time I have forced myself to write as clearly as possible without much edgecases
- Install Latest Version of Cosmocc
- you could do this by installing it from your package manager (for example , archlinux supports it , but then you would need to look where its located which is not recommended)
- (preferred) by going to https://cosmo.zip/pub/cosmocc/ and then downloading the latest version
-
Extract the zip file
-
Go to the folder where you extracted and get its path (by doing pwd for example)
-
Run this command and change /path/to/cosmo-folder to actual folder where its located (paste the path from step 3)
On Linux / Mac OS / BSD
export CC=/path/to/cosmo-folder/bin/cosmocc #change the path to actual folder
On Windows (I don't use windows but I searched on stackoverflow and it seems that this command should work though I am not sure)
[Environment]::SetEnvironmentVariable("CC", "C:\path\to\folder", "User")
-
Then create a nim file and nim.cfg (install nim if you haven't)
-
Update: though this works , After some help by Jart , It seems that if you really want threads then you can do the following (This github issue helped me fixing it nim-lang/Nim#22392)
then copy one of these into your nim.cfg also change the operating system tag in the config to the one you are using I suppose
If you want threads then paste the following (Threads solution)
--os:linux
--gc:orc # Not required, but ARC/ORC would obviously work much better for a target like Cosmopolitan
--threads:on # Nim 2 enables threads by default, disable them since I don't think they're needed?
--cc:env
-d:useMalloc
Non threads solution
--os:linux
--gc:orc # Not required, but ARC/ORC would obviously work much better for a target like Cosmopolitan
--threads:off # Nim 2 enables threads by default, disable them since I don't think they're needed?
--cc:env
- run nim c file_name.nim which should create a binary in the ape format.
this was created with the help of https://github.com/jart/ & https://github.com/ahgamut/
this couldn't have been made without their help
please go sponsor them if possible