diff --git a/examples/nim.cfg b/examples/nim.cfg new file mode 100644 index 0000000..85bf6c4 --- /dev/null +++ b/examples/nim.cfg @@ -0,0 +1 @@ +--path:"../src/" diff --git a/nim.cfg b/nim.cfg new file mode 100644 index 0000000..efe65e3 --- /dev/null +++ b/nim.cfg @@ -0,0 +1 @@ +-d:NimteropTemplate_SetVer="M.M.V" -d:NimteropTemplate_DL -d:NimteropTemplate_Static diff --git a/nimterop_template.nimble b/nimterop_template.nimble new file mode 100644 index 0000000..fd0d4bd --- /dev/null +++ b/nimterop_template.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "Joey Yakimowich-Payne" +description = "Nimterop template" +license = "MIT" +srcDir = "src" + + + +# Dependencies + +requires "nim >= 1.0.6", "nimterop#head" diff --git a/src/nimterop_template.nim b/src/nimterop_template.nim new file mode 100644 index 0000000..7427ab1 --- /dev/null +++ b/src/nimterop_template.nim @@ -0,0 +1,3 @@ +import nimterop_template/nimterop_template + +export nimterop_template diff --git a/src/nimterop_template/cleansymbols.nim b/src/nimterop_template/cleansymbols.nim new file mode 100644 index 0000000..921b04d --- /dev/null +++ b/src/nimterop_template/cleansymbols.nim @@ -0,0 +1,44 @@ +import macros, nimterop / plugin +import strutils, regex +import sets + +proc firstLetterLower(m: RegexMatch, s: string): string = + if m.groupsCount > 0 and m.group(0).len > 0: + return s[m.group(0)[0]].toLowerAscii + +proc camelCase(m: RegexMatch, s: string): string = + if m.groupsCount > 0 and m.group(0).len > 0: + return s[m.group(0)[0]].toUpperAscii + +proc nothing(m: RegexMatch, s: string): string = + if m.groupsCount > 0 and m.group(0).len > 0: + return s[m.group(0)[0]] + +const replacements = [ + re"^PREFIX_(.)", +] + +const underscoreReg = re"_(.)" + +# Symbol renaming examples +proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} = + if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst: + if sym.name != "_": + sym.name = sym.name.strip(chars={'_'}).replace("__", "_") + + for rep in replacements: + if sym.kind == nskProc: + try: + sym.name = sym.name.replace(rep, firstLetterLower) + except: + discard + else: + try: + sym.name = sym.name.replace(rep, nothing) + except: + discard + + if sym.kind == nskField: + sym.name = sym.name.replace(underscoreReg, camelCase) + if sym.name == "type": + sym.name = "kind" diff --git a/src/nimterop_template/nimterop_template.nim b/src/nimterop_template/nimterop_template.nim new file mode 100644 index 0000000..e7b4ede --- /dev/null +++ b/src/nimterop_template/nimterop_template.nim @@ -0,0 +1,39 @@ +import os, strutils, strformat +import nimterop/[cimport, build] + +const + SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2") + baseDir = SDLCacheDir + srcDir = baseDir / "sdl2" + buildDir = srcDir / "buildcache" + symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" + +getHeader( + "template.h", + dlurl = "https://download.com/template-$1.tar.gz", + outdir = srcDir, + cmakeFlags = "-F flag", + conFlags = "-F flag" +) + +static: + discard + # gitPull("https://github.com/lib/project", outdir=srcDir, plist=""" +# src/*.h +# src/*.c +# """, checkout = "1f9c8864fc556a1be4d4bf1d6bfe20cde25734b4") + # cSkipSymbol @[] + # cDebug() + # cDisableCaching() + # let contents = readFile(srcDir/"src"/"dynapi"/"SDL_dynapi_procs.h") + # writeFile(srcDir/"src"/"dynapi"/"SDL_dynapi_procs.c", contents + +cOverride: + discard + +cPluginPath(symbolPluginPath) + +when defined(NimteropTemplate_Static): + cImport(NimteropTemplate_Path, recurse = true, flags = "-f=ast2 -E__,_ -F__,_") +else: + cImport(NimteropTemplate_Path, recurse = true, dynlib = "NimteropTemplate_LPath", flags = "-f=ast2 -E__,_ -F__,_") diff --git a/tests/config.nims b/tests/config.nims new file mode 100644 index 0000000..3bb69f8 --- /dev/null +++ b/tests/config.nims @@ -0,0 +1 @@ +switch("path", "$projectDir/../src") \ No newline at end of file