adds nimbasePattern compiler option (#22144)

adds optonal --nimbasepattern
This commit is contained in:
Juan M Gómez
2023-06-24 07:13:15 +01:00
committed by GitHub
parent 88114948c4
commit beaac609ab
4 changed files with 32 additions and 1 deletions

View File

@@ -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] == '#':

View File

@@ -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}

View File

@@ -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

View File

@@ -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()