summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-03-04 13:46:42 +0100
committerGitHub <noreply@github.com>2020-03-04 13:46:42 +0100
commit614fb7567c80c3b071394714c3809c005aaad397 (patch)
tree4548c2b1f9d46120e4b0bb6e83a127060e9954ba /lib
parent0809098971080674f723cb219722487e42011fd1 (diff)
downloadNim-614fb7567c80c3b071394714c3809c005aaad397.tar.gz
std/compilesettings implementation (#13584)
* Implement compileSetting() and compileSettingSeq()
* Change from magic to vmop
* better design for querySetting

Co-authored-by: genotrance <dev@genotrance.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/std/compilesettings.nim54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/std/compilesettings.nim b/lib/std/compilesettings.nim
new file mode 100644
index 000000000..12204658d
--- /dev/null
+++ b/lib/std/compilesettings.nim
@@ -0,0 +1,54 @@
+#
+#
+#           The Nim Compiler
+#        (c) Copyright 2020 Nim Contributors
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## This module allows querying the compiler about
+## diverse configuration settings.
+
+# Note: Only add new enum values at the end to ensure binary compatibility with
+# other Nim compiler versions!
+
+type
+  SingleValueSetting* {.pure.} = enum ## \
+                      ## settings resulting in a single string value
+    arguments,        ## experimental: the arguments passed after '-r'
+    outFile,          ## experimental: the output file
+    outDir,           ## the output directory
+    nimcacheDir,      ## the location of the 'nimcache' directory
+    projectName,      ## the project's name that is being compiled
+    projectPath,      ## experimental: some path to the project that is being compiled
+    projectFull,      ## the full path to the project that is being compiled
+    command,          ## experimental: the command (e.g. 'c', 'cpp', 'doc') passed to
+                      ## the Nim compiler
+    commandLine,      ## experimental: the command line passed to Nim
+    linkOptions,      ## additional options passed to the linker
+    compileOptions,   ## additional options passed to the C/C++ compiler
+    ccompilerPath     ## the path to the C/C++ compiler
+
+  MultipleValueSetting* {.pure.} = enum ## \
+                      ## settings resulting in a seq of string values
+    nimblePaths,      ## the nimble path(s)
+    searchPaths,      ## the search path for modules
+    lazyPaths,        ## experimental: even more paths
+    commandArgs,      ## the arguments passed to the Nim compiler
+    cincludes,        ## the #include paths passed to the C/C++ compiler
+    clibs             ## libraries passed to the C/C++ compiler
+
+proc querySetting*(setting: SingleValueSetting): string {.
+  compileTime, noSideEffect.} = discard
+  ## Can be used to get a string compile-time option. Example:
+  ##
+  ## .. code-block:: Nim
+  ##   const nimcache = querySetting(SingleValueSetting.nimcacheDir)
+
+proc querySettingSeq*(setting: MultipleValueSetting): seq[string] {.
+  compileTime, noSideEffect.} = discard
+  ## Can be used to get a multi-string compile-time option. Example:
+  ##
+  ## .. code-block:: Nim
+  ##   const nimblePaths = compileSettingSeq(MultipleValueSetting.nimblePaths)