nim.cfg 12 KB

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