Initial commit
This commit is contained in:
commit
920e8573ef
10 changed files with 136 additions and 0 deletions
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
*
|
||||
!/**/
|
||||
!*.*
|
||||
|
||||
nimcache/
|
||||
nimblecache/
|
||||
htmldocs/
|
||||
build
|
||||
|
||||
*.out
|
||||
.DS_Store
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -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.
|
||||
2
README.md
Normal file
2
README.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# nimterop-template
|
||||
Template for nimterop projects
|
||||
1
examples/nim.cfg
Normal file
1
examples/nim.cfg
Normal file
|
|
@ -0,0 +1 @@
|
|||
--path:"../src/"
|
||||
1
nim.cfg
Normal file
1
nim.cfg
Normal file
|
|
@ -0,0 +1 @@
|
|||
-d:Project_SetVer="M.M.V" -d:Project_DL -d:Project_Static
|
||||
13
project.nimble
Normal file
13
project.nimble
Normal file
|
|
@ -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"
|
||||
3
src/project.nim
Normal file
3
src/project.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import project/project
|
||||
|
||||
export project
|
||||
44
src/project/cleansymbols.nim
Normal file
44
src/project/cleansymbols.nim
Normal file
|
|
@ -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"
|
||||
39
src/project/project.nim
Normal file
39
src/project/project.nim
Normal file
|
|
@ -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__,_")
|
||||
1
tests/config.nims
Normal file
1
tests/config.nims
Normal file
|
|
@ -0,0 +1 @@
|
|||
switch("path", "$projectDir/../src")
|
||||
Loading…
Add table
Add a link
Reference in a new issue