Move all artifacts to nimcache
This commit is contained in:
parent
f2a0d4b0c9
commit
6db698ea7a
14 changed files with 80 additions and 54 deletions
|
|
@ -21,10 +21,13 @@ proc execCmd(cmd: string) =
|
||||||
exec cmd
|
exec cmd
|
||||||
|
|
||||||
proc execTest(test: string) =
|
proc execTest(test: string) =
|
||||||
execCmd "nim c -r " & test
|
execCmd "nim c -f -r " & test
|
||||||
execCmd "nim cpp -r " & test
|
execCmd "nim cpp -r " & test
|
||||||
|
|
||||||
task buildToast, "build toast":
|
task buildToast, "build toast":
|
||||||
|
execCmd("nim c -f -d:danger nimterop/toast.nim")
|
||||||
|
|
||||||
|
task bt, "build toast":
|
||||||
execCmd("nim c -d:danger nimterop/toast.nim")
|
execCmd("nim c -d:danger nimterop/toast.nim")
|
||||||
|
|
||||||
task docs, "Generate docs":
|
task docs, "Generate docs":
|
||||||
|
|
@ -34,7 +37,7 @@ task test, "Test":
|
||||||
buildToastTask()
|
buildToastTask()
|
||||||
|
|
||||||
execTest "tests/tnimterop_c.nim"
|
execTest "tests/tnimterop_c.nim"
|
||||||
execCmd "nim cpp -r tests/tnimterop_cpp.nim"
|
execCmd "nim cpp -f -r tests/tnimterop_cpp.nim"
|
||||||
execTest "tests/tpcre.nim"
|
execTest "tests/tpcre.nim"
|
||||||
|
|
||||||
# Platform specific tests
|
# Platform specific tests
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,45 @@ proc rmFile*(source: string, dir = false) =
|
||||||
|
|
||||||
discard execAction(&"{cmd} {source.sanitizePath}", retry = 2)
|
discard execAction(&"{cmd} {source.sanitizePath}", retry = 2)
|
||||||
|
|
||||||
proc rmDir*(source: string) =
|
proc rmDir*(dir: string) =
|
||||||
## Remove a directory or pattern at compile time
|
## Remove a directory or pattern at compile time
|
||||||
rmFile(source, dir = true)
|
rmFile(dir, dir = true)
|
||||||
|
|
||||||
|
proc getOsCacheDir(): string =
|
||||||
|
when defined(posix):
|
||||||
|
result = getEnv("XDG_CACHE_HOME", getHomeDir() / ".cache") / "nim"
|
||||||
|
else:
|
||||||
|
result = getHomeDir() / "nimcache"
|
||||||
|
|
||||||
|
proc getNimteropCacheDir(): string =
|
||||||
|
result = getOsCacheDir() / "nimterop"
|
||||||
|
|
||||||
|
proc getProjectCacheDir*(name: string, forceClean = true): string =
|
||||||
|
## Get a cache directory where all nimterop artifacts can be stored
|
||||||
|
##
|
||||||
|
## Projects can use this location to download source code and build binaries
|
||||||
|
## that can be then accessed by multiple apps. This is created under the
|
||||||
|
## per-user Nim cache directory.
|
||||||
|
##
|
||||||
|
## Use `name` to specify the subdirectory name for a project.
|
||||||
|
##
|
||||||
|
## `forceClean` is enabled by default and effectively deletes the folder
|
||||||
|
## if Nim is compiled with the `-f` or `--forceBuild` flag. This allows
|
||||||
|
## any project to start out with a clean cache dir on a forced build.
|
||||||
|
##
|
||||||
|
## NOTE: avoid calling `getProjectCacheDir()` multiple times on the same
|
||||||
|
## `name` when `forceClean = true` else checked out source might get deleted
|
||||||
|
## at the wrong time during build.
|
||||||
|
##
|
||||||
|
## E.g.
|
||||||
|
## `nimgit2` downloads `libgit2` source so `name = "libgit2"`
|
||||||
|
##
|
||||||
|
## `nimarchive` downloads `libarchive`, `bzlib`, `liblzma` and `zlib` so
|
||||||
|
## `name = "nimarchive" / "libarchive"` for `libarchive`, etc.
|
||||||
|
result = getNimteropCacheDir() / name
|
||||||
|
|
||||||
|
if forceClean and compileOption("forceBuild"):
|
||||||
|
rmDir(result)
|
||||||
|
|
||||||
proc extractZip*(zipfile, outdir: string) =
|
proc extractZip*(zipfile, outdir: string) =
|
||||||
## Extract a zip file using `powershell` on Windows and `unzip` on other
|
## Extract a zip file using `powershell` on Windows and `unzip` on other
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,12 @@ proc getNimCheckError(output: string): tuple[tmpFile, errors: string] =
|
||||||
let
|
let
|
||||||
hash = output.hash().abs()
|
hash = output.hash().abs()
|
||||||
|
|
||||||
result.tmpFile = getTempDir() / "nimterop_" & $hash & ".nim"
|
result.tmpFile = getProjectCacheDir("cPlugins", forceClean = false) / "nimterop_" & $hash & ".nim"
|
||||||
|
|
||||||
if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
|
if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
|
||||||
writeFile(result.tmpFile, output)
|
writeFile(result.tmpFile, output)
|
||||||
|
|
||||||
doAssert fileExists(result.tmpFile), "Bad codegen - unable to write to TEMP: " & result.tmpFile
|
doAssert fileExists(result.tmpFile), "Failed to write to cache dir: " & result.tmpFile
|
||||||
|
|
||||||
let
|
let
|
||||||
nim =
|
nim =
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import "."/build
|
||||||
|
|
||||||
|
const
|
||||||
|
cacheDir* = getProjectCacheDir("nimterop")
|
||||||
|
|
||||||
proc nimteropRoot*(): string =
|
proc nimteropRoot*(): string =
|
||||||
currentSourcePath.parentDir.parentDir
|
currentSourcePath.parentDir.parentDir
|
||||||
|
|
||||||
proc nimteropBuildDir*(): string =
|
|
||||||
## all nimterop generated files go under here (gitignored)
|
|
||||||
nimteropRoot() / "build"
|
|
||||||
|
|
||||||
proc nimteropSrcDir*(): string =
|
proc nimteropSrcDir*(): string =
|
||||||
nimteropRoot() / "nimterop"
|
nimteropRoot() / "nimterop"
|
||||||
|
|
||||||
proc toastExePath*(): string =
|
proc toastExePath*(): string =
|
||||||
nimteropSrcDir() / ("toast".addFileExt ExeExt)
|
nimteropSrcDir() / ("toast".addFileExt ExeExt)
|
||||||
|
|
||||||
proc incDir*(): string =
|
|
||||||
nimteropBuildDir() / "inc"
|
|
||||||
|
|
||||||
proc testsIncludeDir*(): string =
|
proc testsIncludeDir*(): string =
|
||||||
nimteropRoot() / "tests" / "include"
|
nimteropRoot() / "tests" / "include"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,24 @@ import os, strutils
|
||||||
import "."/[build, paths]
|
import "."/[build, paths]
|
||||||
|
|
||||||
proc treesitterSetup*() =
|
proc treesitterSetup*() =
|
||||||
gitPull("https://github.com/tree-sitter/tree-sitter", incDir() / "treesitter", """
|
gitPull("https://github.com/tree-sitter/tree-sitter", cacheDir / "treesitter", """
|
||||||
lib/include/*
|
lib/include/*
|
||||||
lib/src/*
|
lib/src/*
|
||||||
""", "0.15.5")
|
""", "0.15.5")
|
||||||
|
|
||||||
gitPull("https://github.com/JuliaStrings/utf8proc", incDir() / "utf8proc", """
|
gitPull("https://github.com/JuliaStrings/utf8proc", cacheDir / "utf8proc", """
|
||||||
*.c
|
*.c
|
||||||
*.h
|
*.h
|
||||||
""")
|
""")
|
||||||
|
|
||||||
let
|
let
|
||||||
tbase = incDir() / "treesitter/lib"
|
tbase = cacheDir / "treesitter" / "lib"
|
||||||
stack = tbase / "src/stack.c"
|
stack = tbase / "src" / "stack.c"
|
||||||
parser = tbase / "include/tree_sitter/parser.h"
|
parser = tbase / "include" / "tree_sitter" / "parser.h"
|
||||||
tparser = parser.replace("parser", "tparser")
|
tparser = parser.replace("parser", "tparser")
|
||||||
language = tbase / "src/language.h"
|
language = tbase / "src" / "language.h"
|
||||||
lexer = tbase / "src/lexer.h"
|
lexer = tbase / "src" / "lexer.h"
|
||||||
subtree = tbase / "src/subtree.h"
|
subtree = tbase / "src" / "subtree.h"
|
||||||
|
|
||||||
stack.writeFile(stack.readFile().replace("inline Stack", "Stack"))
|
stack.writeFile(stack.readFile().replace("inline Stack", "Stack"))
|
||||||
|
|
||||||
|
|
@ -31,31 +31,25 @@ lib/src/*
|
||||||
subtree.writeFile(subtree.readFile().replace("parser.h", "tparser.h"))
|
subtree.writeFile(subtree.readFile().replace("parser.h", "tparser.h"))
|
||||||
|
|
||||||
proc treesitterCSetup*() =
|
proc treesitterCSetup*() =
|
||||||
gitPull("https://github.com/tree-sitter/tree-sitter-c", incDir() / "treesitter_c", """
|
gitPull("https://github.com/tree-sitter/tree-sitter-c", cacheDir / "treesitter_c", """
|
||||||
src/*.h
|
src/*.h
|
||||||
src/*.c
|
src/*.c
|
||||||
src/*.cc
|
src/*.cc
|
||||||
src/tree_sitter/parser.h
|
src/tree_sitter/parser.h
|
||||||
""", "v0.15.0")
|
""", "v0.15.0")
|
||||||
|
|
||||||
let
|
writeFile(cacheDir / "treesitter_c" / "src" / "api.h", """
|
||||||
headerc = incDir() / "treesitter_c/src/api.h"
|
|
||||||
|
|
||||||
headerc.writeFile("""
|
|
||||||
const TSLanguage *tree_sitter_c();
|
const TSLanguage *tree_sitter_c();
|
||||||
""")
|
""")
|
||||||
|
|
||||||
proc treesitterCppSetup*() =
|
proc treesitterCppSetup*() =
|
||||||
gitPull("https://github.com/tree-sitter/tree-sitter-cpp", incDir() / "treesitter_cpp", """
|
gitPull("https://github.com/tree-sitter/tree-sitter-cpp", cacheDir / "treesitter_cpp", """
|
||||||
src/*.h
|
src/*.h
|
||||||
src/*.c
|
src/*.c
|
||||||
src/*.cc
|
src/*.cc
|
||||||
src/tree_sitter/parser.h
|
src/tree_sitter/parser.h
|
||||||
""", "v0.15.0")
|
""", "v0.15.0")
|
||||||
|
|
||||||
let
|
writeFile(cacheDir / "treesitter_cpp" / "src" / "api.h", """
|
||||||
headercpp = incDir() / "treesitter_cpp/src/api.h"
|
|
||||||
|
|
||||||
headercpp.writeFile("""
|
|
||||||
const TSLanguage *tree_sitter_cpp();
|
const TSLanguage *tree_sitter_cpp();
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import ".."/[setup, paths, types]
|
||||||
static:
|
static:
|
||||||
treesitterSetup()
|
treesitterSetup()
|
||||||
|
|
||||||
const sourcePath = incDir() / "treesitter" / "lib"
|
const sourcePath = cacheDir / "treesitter" / "lib"
|
||||||
|
|
||||||
when defined(Linux):
|
when defined(Linux):
|
||||||
{.passC: "-std=c11".}
|
{.passC: "-std=c11".}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import ".."/[setup, paths]
|
||||||
static:
|
static:
|
||||||
treesitterCSetup()
|
treesitterCSetup()
|
||||||
|
|
||||||
const srcDir = incDir() / "treesitter_c" / "src"
|
const srcDir = cacheDir / "treesitter_c" / "src"
|
||||||
|
|
||||||
import "."/api
|
import "."/api
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,20 @@
|
||||||
import strutils, os
|
import strutils, os
|
||||||
|
|
||||||
import ".."/[setup, paths]
|
import ".."/[build, setup, paths]
|
||||||
|
|
||||||
static:
|
static:
|
||||||
treesitterCppSetup()
|
treesitterCppSetup()
|
||||||
|
|
||||||
const srcDir = incDir() / "treesitter_cpp" / "src"
|
const srcDir = cacheDir / "treesitter_cpp" / "src"
|
||||||
|
|
||||||
{.passC: "-I$1" % srcDir.}
|
{.passC: "-I$1" % srcDir.}
|
||||||
|
|
||||||
import "."/api
|
import "."/api
|
||||||
|
|
||||||
when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
|
static:
|
||||||
const srcDirRel = "../../build/inc/treesitter_cpp/src"
|
cpFile(srcDir / "parser.c", srcDir / "parser_cpp.c")
|
||||||
else:
|
|
||||||
const srcDirRel = srcDir.relativePath(currentSourcePath.parentDir)
|
|
||||||
|
|
||||||
# pending https://github.com/nim-lang/Nim/issues/9370 we need srcDirRel instead
|
{.compile: srcDir / "parser_cpp.c".}
|
||||||
# of srcDir
|
|
||||||
{.compile: (srcDirRel / "parser.c", "nimtero_cpp_parser.c.o").}
|
|
||||||
{.compile: srcDir / "scanner.cc".}
|
{.compile: srcDir / "scanner.cc".}
|
||||||
|
|
||||||
proc treeSitterCpp*(): ptr TSLanguage {.importc: "tree_sitter_cpp", header: srcDir / "api.h".}
|
proc treeSitterCpp*(): ptr TSLanguage {.importc: "tree_sitter_cpp", header: srcDir / "api.h".}
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,4 @@ cPlugin:
|
||||||
static:
|
static:
|
||||||
cDebug()
|
cDebug()
|
||||||
|
|
||||||
cImport(incDir()/"treesitter/lib/include/tree_sitter/api.h")
|
cImport(cacheDir / "treesitter" /"lib" / "include" / "tree_sitter" / "api.h")
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
||||||
if delete:
|
|
||||||
rmDir("build/liblzma")
|
|
||||||
rmDir("build/zlib")
|
|
||||||
echo cmd
|
|
||||||
var
|
var
|
||||||
ccmd =
|
ccmd =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
"cmd /c " & cmd
|
"cmd /c " & cmd
|
||||||
else:
|
else:
|
||||||
cmd
|
cmd
|
||||||
|
|
||||||
|
if not delete:
|
||||||
|
ccmd = ccmd.replace(" -f ", " ")
|
||||||
|
|
||||||
|
var
|
||||||
(outp, exitC) = gorgeEx(ccmd)
|
(outp, exitC) = gorgeEx(ccmd)
|
||||||
echo outp
|
echo outp
|
||||||
doAssert exitC == exitCode, $exitC
|
doAssert exitC == exitCode, $exitC
|
||||||
|
|
@ -41,7 +42,6 @@ when defined(posix):
|
||||||
# git tag
|
# git tag
|
||||||
testCall(cmd & " -d:lzmaGit -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0)
|
testCall(cmd & " -d:lzmaGit -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0)
|
||||||
testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0, delete = false)
|
testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0, delete = false)
|
||||||
testCall("cd build/liblzma && git branch", "v5.2.0", 0, delete = false)
|
|
||||||
|
|
||||||
# git
|
# git
|
||||||
testCall(cmd & " -d:envTest" & zrcmd, zexp, 0)
|
testCall(cmd & " -d:envTest" & zrcmd, zexp, 0)
|
||||||
|
|
@ -50,7 +50,6 @@ testCall(cmd & " -d:envTestStatic" & zrcmd, zexp, 0, delete = false)
|
||||||
# git tag
|
# git tag
|
||||||
testCall(cmd & " -d:zlibGit -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0)
|
testCall(cmd & " -d:zlibGit -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0)
|
||||||
testCall(cmd & " -d:zlibGit -d:zlibStatic -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0, delete = false)
|
testCall(cmd & " -d:zlibGit -d:zlibStatic -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0, delete = false)
|
||||||
testCall("cd build/zlib && git branch", "v1.2.10", 0, delete = false)
|
|
||||||
|
|
||||||
# dl
|
# dl
|
||||||
testCall(cmd & " -d:lzmaDL" & lrcmd, "Need version", 1)
|
testCall(cmd & " -d:lzmaDL" & lrcmd, "Need version", 1)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os, strutils
|
||||||
import nimterop/[build, cimport]
|
import nimterop/[build, cimport]
|
||||||
|
|
||||||
const
|
const
|
||||||
baseDir = currentSourcePath.parentDir()/"build"/"liblzma"
|
baseDir = getProjectCacheDir("nimterop" / "tests" / "liblzma")
|
||||||
|
|
||||||
static:
|
static:
|
||||||
cDebug()
|
cDebug()
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os
|
||||||
import nimterop/[cimport, build, paths]
|
import nimterop/[cimport, build, paths]
|
||||||
|
|
||||||
const
|
const
|
||||||
baseDir = nimteropBuildDir()/"pcre"
|
baseDir = getProjectCacheDir("nimterop" / "tests" / "pcre")
|
||||||
pcreH = baseDir/"pcre.h.in"
|
pcreH = baseDir/"pcre.h.in"
|
||||||
|
|
||||||
static:
|
static:
|
||||||
|
|
@ -32,4 +32,4 @@ cPlugin:
|
||||||
|
|
||||||
cImport(pcreH, dynlib="dynpcre")
|
cImport(pcreH, dynlib="dynpcre")
|
||||||
|
|
||||||
echo version()
|
echo version()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import os, nimterop/[cimport, build, paths]
|
import os, nimterop/[cimport, build, paths]
|
||||||
|
|
||||||
const
|
const
|
||||||
baseDir = nimteropBuildDir()/"soloud"
|
baseDir = getProjectCacheDir("nimterop" / "tests" / "soloud")
|
||||||
incl = baseDir/"include"
|
incl = baseDir/"include"
|
||||||
src = baseDir/"src"
|
src = baseDir/"src"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os, strutils
|
||||||
import nimterop/[build, cimport]
|
import nimterop/[build, cimport]
|
||||||
|
|
||||||
const
|
const
|
||||||
baseDir = currentSourcePath.parentDir()/"build"/"zlib"
|
baseDir = getProjectCacheDir("nimterop" / "tests" / "zlib")
|
||||||
|
|
||||||
static:
|
static:
|
||||||
cDebug()
|
cDebug()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue