summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJuan M Gómez <info@jmgomez.me>2023-06-24 07:13:15 +0100
committerGitHub <noreply@github.com>2023-06-24 08:13:15 +0200
commitbeaac609ab5756114a0938360a60eca0f605f4a1 (patch)
tree5113b6847b57f764028fe9dce1eb6caa52bb4490
parent88114948c41f38d7366dc8d80abc09f00c2492fa (diff)
downloadNim-beaac609ab5756114a0938360a60eca0f605f4a1.tar.gz
adds nimbasePattern compiler option (#22144)
adds optonal --nimbasepattern
-rw-r--r--compiler/cgen.nim4
-rw-r--r--compiler/commands.nim2
-rw-r--r--compiler/options.nim1
-rw-r--r--tests/options/tnimbasepattern.nim26
4 files changed, 32 insertions, 1 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index e79081dc6..0450625fc 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -935,7 +935,9 @@ proc cgsymValue(m: BModule, name: string): Rope =
     result.addActualSuffixForHCR(m.module, sym)
 
 proc generateHeaders(m: BModule) =
-  m.s[cfsHeaders].add("\L#include \"nimbase.h\"\L")
+  var nimbase = m.config.nimbasePattern
+  if nimbase == "": nimbase = "nimbase.h"
+  m.s[cfsHeaders].addf("\L#include \"$1\"\L", [nimbase])
 
   for it in m.headerFiles:
     if it[0] == '#':
diff --git a/compiler/commands.nim b/compiler/commands.nim
index cb9a12cbb..333a0f0d0 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -829,6 +829,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
   of "header":
     if conf != nil: conf.headerFile = arg
     incl(conf.globalOptions, optGenIndex)
+  of "nimbasepattern":
+    if conf != nil: conf.nimbasePattern = arg
   of "index":
     case arg.normalize
     of "", "on": conf.globalOptions.incl {optGenIndex}
diff --git a/compiler/options.nim b/compiler/options.nim
index 082caedf1..d3cf71d4f 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -333,6 +333,7 @@ type
 
     cppDefines*: HashSet[string] # (*)
     headerFile*: string
+    nimbasePattern*: string # pattern to find nimbase.h
     features*: set[Feature]
     legacyFeatures*: set[LegacyFeature]
     arguments*: string ## the arguments to be passed to the program that
diff --git a/tests/options/tnimbasepattern.nim b/tests/options/tnimbasepattern.nim
new file mode 100644
index 000000000..1237af5c5
--- /dev/null
+++ b/tests/options/tnimbasepattern.nim
@@ -0,0 +1,26 @@
+discard """
+  cmd: "nim cpp --nimbasepattern:test.h --cincludes:./tests/options $file "
+  output:'''
+(a: 1)
+'''
+"""
+const header = """
+#pragma once
+#include "nimbase.h"
+struct Foo {
+  int a;
+};
+"""
+
+import os
+static:
+  const dir = "./tests/options/"
+  createDir(dir)
+  writeFile(dir / "test.h", header)
+
+type 
+  Foo {.importc.} = object
+    a: int32 = 1
+  
+
+echo $Foo()
\ No newline at end of file