From f91d063d6cf477a7787cda2033a08416216c87ba Mon Sep 17 00:00:00 2001 From: Joey Date: Sun, 26 Apr 2020 16:27:10 -0600 Subject: [PATCH] Initial commit --- .gitignore | 11 +++++++++ LICENSE | 21 +++++++++++++++++ README.md | 2 ++ examples/nim.cfg | 1 + nim.cfg | 1 + project.nimble | 13 +++++++++++ src/project.nim | 3 +++ src/project/cleansymbols.nim | 44 ++++++++++++++++++++++++++++++++++++ src/project/project.nim | 39 ++++++++++++++++++++++++++++++++ tests/config.nims | 1 + 10 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 examples/nim.cfg create mode 100644 nim.cfg create mode 100644 project.nimble create mode 100644 src/project.nim create mode 100644 src/project/cleansymbols.nim create mode 100644 src/project/project.nim create mode 100644 tests/config.nims diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e82015 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +* +!/**/ +!*.* + +nimcache/ +nimblecache/ +htmldocs/ +build + +*.out +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bb141a3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Joey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..285e142 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# nimterop-template +Template for nimterop projects 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..664de18 --- /dev/null +++ b/nim.cfg @@ -0,0 +1 @@ +-d:Project_SetVer="M.M.V" -d:Project_DL -d:Project_Static diff --git a/project.nimble b/project.nimble new file mode 100644 index 0000000..8141d30 --- /dev/null +++ b/project.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", "regex" diff --git a/src/project.nim b/src/project.nim new file mode 100644 index 0000000..9e04484 --- /dev/null +++ b/src/project.nim @@ -0,0 +1,3 @@ +import project/project + +export project diff --git a/src/project/cleansymbols.nim b/src/project/cleansymbols.nim new file mode 100644 index 0000000..921b04d --- /dev/null +++ b/src/project/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/project/project.nim b/src/project/project.nim new file mode 100644 index 0000000..1a06e4f --- /dev/null +++ b/src/project/project.nim @@ -0,0 +1,39 @@ +import os, strutils, strformat +import nimterop/[cimport, build] + +const + ProjectCacheDir* = 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(Project_Static): + cImport(Project_Path, recurse = true, flags = "-f=ast2 -E__,_ -F__,_") +else: + cImport(Project_Path, recurse = true, dynlib = "Project_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