nim.cfg 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. # Configuration file for the Nim Compiler.
  2. # (c) 2017 Andreas Rumpf
  3. # Feel free to edit the default values as you need.
  4. # See https://nim-lang.org/docs/nimc.html
  5. # You may set environment variables with
  6. # @putenv "key" "val"
  7. # Environment variables can be accessed like so:
  8. # gcc.path %= "$CC_PATH"
  9. cc = gcc
  10. # additional options always passed to the compiler:
  11. --parallel_build: "0" # 0 to auto-detect number of processors
  12. #hint[XDeclaredButNotUsed]=off
  13. @if not nimHasNolineTooLong:
  14. hint[LineTooLong]=off
  15. @end
  16. threads:on
  17. # Examples of how to setup a cross-compiler:
  18. # Nim can target architectures and OSes different than the local host
  19. # Syntax: <arch>.<os>.gcc.exe = "<compiler executable>"
  20. # <arch>.<os>.gcc.linkerexe = "<linker executable>"
  21. # ARM e.g. Raspberry Pi 2: gcc-arm-linux-gnueabihf package on Debian/Ubuntu
  22. arm.linux.gcc.exe = "arm-linux-gnueabihf-gcc"
  23. arm.linux.gcc.linkerexe = "arm-linux-gnueabihf-gcc"
  24. # ARM64/aarch64 e.g. Raspberry Pi 3: gcc-aarch64-linux-gnu package on Debian/Ubuntu
  25. arm64.linux.gcc.exe = "aarch64-linux-gnu-gcc"
  26. arm64.linux.gcc.linkerexe = "aarch64-linux-gnu-gcc"
  27. # RISC-V: gcc-riscv64-linux-gnu package on Debian/Ubuntu
  28. riscv32.linux.gcc.exe = "riscv64-linux-gnu-gcc"
  29. riscv32.linux.gcc.linkerexe = "riscv64-linux-gnu-gcc"
  30. riscv64.linux.gcc.exe = "riscv64-linux-gnu-gcc"
  31. riscv64.linux.gcc.linkerexe = "riscv64-linux-gnu-gcc"
  32. # For OpenWRT, you will also need to adjust PATH to point to your toolchain.
  33. mips.linux.gcc.exe = "mips-openwrt-linux-gcc"
  34. mips.linux.gcc.linkerexe = "mips-openwrt-linux-gcc"
  35. path="$lib/deprecated/core"
  36. path="$lib/deprecated/pure"
  37. path="$lib/pure/collections"
  38. path="$lib/pure/concurrency"
  39. path="$lib/impure"
  40. path="$lib/wrappers"
  41. path="$lib/wrappers/linenoise"
  42. path="$lib/windows"
  43. path="$lib/posix"
  44. path="$lib/js"
  45. path="$lib/pure/unidecode"
  46. path="$lib/arch"
  47. path="$lib/core"
  48. path="$lib/pure"
  49. @if not windows:
  50. nimblepath="/opt/nimble/pkgs2/"
  51. nimblepath="/opt/nimble/pkgs/"
  52. @else:
  53. # TODO:
  54. @end
  55. nimblepath="$home/.nimble/pkgs2/"
  56. nimblepath="$home/.nimble/pkgs/"
  57. # Syncronize with compiler/commands.specialDefine
  58. @if danger or quick:
  59. obj_checks:off
  60. field_checks:off
  61. range_checks:off
  62. bound_checks:off
  63. overflow_checks:off
  64. assertions:off
  65. stacktrace:off
  66. linetrace:off
  67. debugger:off
  68. line_dir:off
  69. @end
  70. # Syncronize with compiler/commands.specialDefine
  71. @if release or danger:
  72. stacktrace:off
  73. excessiveStackTrace:off
  74. linetrace:off
  75. debugger:off
  76. line_dir:off
  77. opt:speed
  78. define:release
  79. @end
  80. @if false: # not danger: # this does not work yet.
  81. clang.options.always %= "${clang.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
  82. gcc.options.always %= "${gcc.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
  83. @end
  84. # Turn off threads support when compiling for bare-metal targets (--os:any)
  85. @if any:
  86. threads:off
  87. @end
  88. @if unix and mingw:
  89. # Cross compile for Windows from Linux/OSX using MinGW
  90. i386.windows.gcc.exe = "i686-w64-mingw32-gcc"
  91. i386.windows.gcc.linkerexe = "i686-w64-mingw32-gcc"
  92. i386.windows.gcc.cpp.exe = "i686-w64-mingw32-g++"
  93. i386.windows.gcc.cpp.linkerexe = "i686-w64-mingw32-g++"
  94. amd64.windows.gcc.exe = "x86_64-w64-mingw32-gcc"
  95. amd64.windows.gcc.linkerexe = "x86_64-w64-mingw32-gcc"
  96. amd64.windows.gcc.cpp.exe = "x86_64-w64-mingw32-g++"
  97. amd64.windows.gcc.cpp.linkerexe = "x86_64-w64-mingw32-g++"
  98. @if macosx:
  99. i386.windows.gcc.path = "/usr/local/bin"
  100. amd64.windows.gcc.path = "/usr/local/bin"
  101. @else:
  102. i386.windows.gcc.path = "/usr/bin"
  103. amd64.windows.gcc.path = "/usr/bin"
  104. @end
  105. os = windows
  106. gcc.options.linker = ""
  107. gcc.cpp.options.linker = ""
  108. @end
  109. @if unix:
  110. @if bsd:
  111. # BSD got posix_spawn only recently, so we deactivate it for osproc:
  112. define:useFork
  113. @elif haiku:
  114. gcc.options.linker = "-Wl,--as-needed -lnetwork"
  115. gcc.cpp.options.linker = "-Wl,--as-needed -lnetwork"
  116. clang.options.linker = "-Wl,--as-needed -lnetwork"
  117. clang.cpp.options.linker = "-Wl,--as-needed -lnetwork"
  118. tcc.options.linker = "-Wl,--as-needed -lnetwork"
  119. @elif not genode:
  120. # -fopenmp
  121. gcc.options.linker = "-ldl"
  122. gcc.cpp.options.linker = "-ldl"
  123. clang.options.linker = "-ldl"
  124. clang.cpp.options.linker = "-ldl"
  125. tcc.options.linker = "-ldl"
  126. @end
  127. @end
  128. @if android:
  129. cc = clang
  130. @if termux:
  131. gcc.options.linker = "-landroid-glob"
  132. gcc.cpp.options.linker = "-landroid-glob"
  133. clang.options.linker = "-landroid-glob"
  134. clang.cpp.options.linker = "-landroid-glob"
  135. tcc.options.linker = "-landroid-glob"
  136. @end
  137. @end
  138. @if nintendoswitch:
  139. cc = "switch_gcc"
  140. switch_gcc.options.linker = "-g -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE"
  141. switch_gcc.cpp.options.linker = "-g -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE"
  142. switch_gcc.options.always = "-g -Wall -O2 -ffunction-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -D__SWITCH__"
  143. switch_gcc.cpp.options.always = "-g -Wall -O2 -ffunction-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -D__SWITCH__ -fno-rtti -fno-exceptions -std=gnu++11"
  144. @end
  145. # Configuration for the Intel C/C++ compiler:
  146. @if windows:
  147. icl.options.speed = "/Ox /arch:SSE2"
  148. icl.options.always = "/nologo"
  149. @end
  150. # Configuration for the GNU C/C++ compiler:
  151. @if windows:
  152. #gcc.path = r"$nim\dist\mingw\bin"
  153. @if gcc:
  154. gcc.options.linker %= "-Wl,-Bstatic -lpthread"
  155. @end
  156. @if tcc:
  157. tlsEmulation:on
  158. @end
  159. @end
  160. gcc.maxerrorsimpl = "-fmax-errors=3"
  161. @if freebsd or netbsd:
  162. tlsEmulation:off
  163. @elif bsd:
  164. tlsEmulation:on
  165. @end
  166. @if macosx or freebsd or openbsd:
  167. cc = clang
  168. gcc.options.always %= "-w ${gcc.maxerrorsimpl}"
  169. gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive"
  170. @elif windows:
  171. gcc.options.always %= "-w ${gcc.maxerrorsimpl} -mno-ms-bitfields"
  172. gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive -mno-ms-bitfields"
  173. @else:
  174. gcc.options.always %= "-w ${gcc.maxerrorsimpl}"
  175. gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive"
  176. @end
  177. # Configuration for Objective-C compiler:
  178. #
  179. # Options for GNUStep. GNUStep configuration varies wildly, so you'll probably
  180. # have to add additional compiler and linker flags on a per-project basis.
  181. gcc.objc.options.linker = "-lobjc -lgnustep-base"
  182. llvm_gcc.objc.options.linker = "-lobjc -lgnustep-base"
  183. clang.objc.options.linker = "-lobjc -lgnustep-base"
  184. # Options for Mac OS X. Mac OS X uses its own Objective-C stack that is
  185. # totally different from GNUStep.
  186. @if macosx:
  187. gcc.objc.options.linker = "-framework Foundation"
  188. llvm_gcc.objc.options.linker = "-framework Foundation"
  189. clang.objc.options.linker = "-framework Foundation"
  190. @end
  191. # Options for FreeBSD, OpenBSD, NetBSD linker to add locations for searching
  192. # shared libraries.
  193. @if freebsd or openbsd or netbsd:
  194. gcc.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  195. gcc.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  196. llvm_gcc.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  197. llvm_gcc.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  198. clang.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  199. clang.cpp.options.linker = "-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
  200. cincludes: "/usr/local/include"
  201. clibdir: "/usr/local/lib"
  202. @end
  203. @if freebsd or openbsd:
  204. cincludes: "/usr/local/include"
  205. clibdir: "/usr/local/lib"
  206. @elif netbsd:
  207. cincludes: "/usr/pkg/include"
  208. clibdir: "/usr/pkg/lib"
  209. @end
  210. # Configuration for the VxWorks
  211. # This has been tested with VxWorks 6.9 only
  212. @if vxworks:
  213. # For now we only support compiling RTPs applications (i.e. no DKMs)
  214. gcc.options.always = "-mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall -Wno-write-strings"
  215. # The linker config must add the VxWorks common library for the selected
  216. # processor which is usually found in:
  217. # "$WIND_BASE/target/lib/usr/lib/PROCESSOR_FAMILY/PROCESSOR_TYPE/common",
  218. # where PROCESSOR_FAMILY and PROCESSOR_TYPE are those supported by the VxWorks
  219. # compiler (e.g. ppc/PPC32 or mips/MIPSI64, etc)
  220. # For now we only support the PowerPC CPU
  221. gcc.options.linker %= "-L $WIND_BASE/target/lib/usr/lib/ppc/PPC32/common -mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall -Wno-write-strings"
  222. @end
  223. # -fno-math-errno is default in OSX, iOS, BSD, Musl, Libm, LLVM, Clang, ICC.
  224. # See https://itnext.io/why-standard-c-math-functions-are-slow-d10d02554e33
  225. # and https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Optimize-Options.html#Optimize-Options
  226. gcc.options.speed = "-O3 -fno-strict-aliasing -fno-ident -fno-math-errno"
  227. gcc.options.size = "-Os -fno-ident"
  228. @if windows:
  229. gcc.options.debug = "-g3 -Og -gdwarf-3"
  230. @else:
  231. gcc.options.debug = "-g3 -Og"
  232. @end
  233. gcc.cpp.options.speed = "-O3 -fno-strict-aliasing -fno-ident -fno-math-errno"
  234. gcc.cpp.options.size = "-Os -fno-ident"
  235. gcc.cpp.options.debug = "-g3 -Og"
  236. #passl = "-pg"
  237. # Configuration for the LLVM GCC compiler:
  238. llvm_gcc.options.debug = "-g"
  239. llvm_gcc.options.always = "-w"
  240. llvm_gcc.options.speed = "-O2"
  241. llvm_gcc.options.size = "-Os"
  242. # Configuration for the LLVM CLang compiler:
  243. clang.options.debug = "-g"
  244. clang.cpp.options.debug = "-g"
  245. clang.options.always = "-w -ferror-limit=3"
  246. clang.options.speed = "-O3"
  247. clang.options.size = "-Os"
  248. @if windows:
  249. clang_cl.cpp.options.always %= "${clang_cl.options.always} /EHsc"
  250. @if not release and not safety and not danger:
  251. clang_cl.options.linker = "/Z7"
  252. clang_cl.cpp.options.linker = "/Z7"
  253. @end
  254. clang.options.debug = "-g -gcodeview"
  255. clang.cpp.options.debug = "-g -gcodeview"
  256. @if not release and not safety and not danger:
  257. clang.options.linker = "-g"
  258. clang.cpp.options.linker = "-g"
  259. @end
  260. @end
  261. # Configuration for the Visual C/C++ compiler:
  262. # VCCEXE is a tool that invokes the Visual Studio Developer Command Prompt
  263. # before calling the compiler.
  264. # Please make sure either Visual Studio or C++ Build SKU is installed when using the vcc compiler backend.
  265. vcc.exe = "vccexe.exe"
  266. vcc.cpp.exe = "vccexe.exe"
  267. vcc.linkerexe = "vccexe.exe"
  268. vcc.cpp.linkerexe = "vccexe.exe"
  269. vcc.options.always = "/nologo"
  270. vcc.cpp.options.always = "/nologo /EHsc"
  271. vcc.options.debug = "/Zi /FS /Od"
  272. vcc.cpp.options.debug = "/Zi /FS /Od"
  273. vcc.options.speed = "/O2"
  274. vcc.cpp.options.speed = "/O2"
  275. vcc.options.size = "/O1"
  276. vcc.cpp.options.size = "/O1"
  277. # Configuration for the Tiny C Compiler:
  278. tcc.options.always = "-w"
  279. @if arm or arm64:
  280. --define:nimEmulateOverflowChecks
  281. @end
  282. @if lto or lto_incremental:
  283. @if lto_incremental:
  284. vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
  285. vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL /Gw /Gy"
  286. vcc.options.linker %= "${vcc.options.linker} /link /LTCG:incremental"
  287. vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG:incremental"
  288. clang_cl.options.always%= "${clang_cl.options.always} -flto=thin"
  289. clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto=thin"
  290. clang.options.always%= "${clang.options.always} -flto=thin"
  291. clang.cpp.options.always%= "${clang.cpp.options.always} -flto=thin"
  292. clang.options.linker %= "${clang.options.linker} -flto=thin"
  293. clang.cpp.options.linker %= "${clang.cpp.options.linker} -flto=thin"
  294. @else:
  295. vcc.options.always%= "${vcc.options.always} /GL"
  296. vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL"
  297. vcc.options.linker %= "${vcc.options.linker} /link /LTCG"
  298. vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG"
  299. clang_cl.options.always%= "${clang_cl.options.always} -flto"
  300. clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto"
  301. clang.options.always%= "${clang.options.always} -flto"
  302. clang.cpp.options.always%= "${clang.cpp.options.always} -flto"
  303. clang.options.linker %= "${clang.options.linker} -flto"
  304. clang.cpp.options.linker %= "${clang.cpp.options.linker} -flto"
  305. @end
  306. icl.options.always %= "${icl.options.always} /Qipo"
  307. icl.cpp.options.always %= "${icl.cpp.options.always} /Qipo"
  308. gcc.options.always %= "${gcc.options.always} -flto=auto"
  309. gcc.cpp.options.always %= "${gcc.cpp.options.always} -flto=auto"
  310. gcc.options.linker %= "${gcc.options.linker} -flto=auto -Wno-stringop-overflow" # https://github.com/nim-lang/Nim/issues/21595
  311. gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -flto=auto"
  312. @end
  313. @if strip:
  314. gcc.options.linker %= "${gcc.options.linker} -s"
  315. gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -s"
  316. clang.options.linker %= "${clang.options.linker} -s"
  317. clang.cpp.options.linker %= "${clang.cpp.options.linker} -s"
  318. @end