move tinyc to a separate repo and allow installing external dependencency (eg tinyc) from koch / library code (#13850)
* remove tinyc * installDeps * update tinyc paths
This commit is contained in:
parent
6b9ffc7fad
commit
93cd98dd14
390 changed files with 80 additions and 99388 deletions
|
|
@ -8,12 +8,20 @@
|
|||
#
|
||||
|
||||
import
|
||||
os, strutils, options, msgs, tinyc
|
||||
os, strutils, options, msgs, tinyc, lineinfos, sequtils
|
||||
|
||||
{.compile: "../tinyc/libtcc.c".}
|
||||
const tinyPrefix = "dist/nim-tinyc-archive".unixToNativePath
|
||||
const nimRoot = currentSourcePath.parentDir.parentDir
|
||||
const tinycRoot = nimRoot / tinyPrefix
|
||||
when not dirExists(tinycRoot):
|
||||
static: doAssert false, $(tinycRoot, "requires: ./koch installdeps tinyc")
|
||||
{.compile: tinycRoot / "tinyc/libtcc.c".}
|
||||
|
||||
var
|
||||
gConf: ConfigRef # ugly but can be cleaned up if this is revived
|
||||
|
||||
proc tinyCErrorHandler(closure: pointer, msg: cstring) {.cdecl.} =
|
||||
rawMessage(errGenerated, $msg)
|
||||
rawMessage(gConf, errGenerated, $msg)
|
||||
|
||||
proc initTinyCState: PccState =
|
||||
result = openCCState()
|
||||
|
|
@ -25,7 +33,7 @@ var
|
|||
|
||||
proc addFile(filename: string) =
|
||||
if addFile(gTinyC, filename) != 0'i32:
|
||||
rawMessage(errCannotOpenFile, filename)
|
||||
rawMessage(gConf, errCannotOpenFile, filename)
|
||||
|
||||
proc setupEnvironment =
|
||||
when defined(amd64):
|
||||
|
|
@ -35,42 +43,47 @@ proc setupEnvironment =
|
|||
when defined(linux):
|
||||
defineSymbol(gTinyC, "__linux__", nil)
|
||||
defineSymbol(gTinyC, "__linux", nil)
|
||||
var nimDir = getPrefixDir()
|
||||
|
||||
var nimDir = getPrefixDir(gConf).string
|
||||
var tinycRoot = nimDir / tinyPrefix
|
||||
let libpath = nimDir / "lib"
|
||||
|
||||
addIncludePath(gTinyC, libpath)
|
||||
when defined(windows):
|
||||
addSysincludePath(gTinyC, nimDir / "tinyc/win32/include")
|
||||
addSysincludePath(gTinyC, nimDir / "tinyc/include")
|
||||
addSysincludePath(gTinyC, tinycRoot / "tinyc/win32/include")
|
||||
addSysincludePath(gTinyC, tinycRoot / "tinyc/include")
|
||||
when defined(windows):
|
||||
defineSymbol(gTinyC, "_WIN32", nil)
|
||||
# we need Mingw's headers too:
|
||||
var gccbin = getConfigVar("gcc.path") % ["nim", nimDir]
|
||||
var gccbin = getConfigVar("gcc.path") % ["nim", tinycRoot]
|
||||
addSysincludePath(gTinyC, gccbin /../ "include")
|
||||
#addFile(nimDir / r"tinyc\win32\wincrt1.o")
|
||||
addFile(nimDir / r"tinyc\win32\alloca86.o")
|
||||
addFile(nimDir / r"tinyc\win32\chkstk.o")
|
||||
#addFile(nimDir / r"tinyc\win32\crt1.o")
|
||||
#addFile(tinycRoot / r"tinyc\win32\wincrt1.o")
|
||||
addFile(tinycRoot / r"tinyc\win32\alloca86.o")
|
||||
addFile(tinycRoot / r"tinyc\win32\chkstk.o")
|
||||
#addFile(tinycRoot / r"tinyc\win32\crt1.o")
|
||||
|
||||
#addFile(nimDir / r"tinyc\win32\dllcrt1.o")
|
||||
#addFile(nimDir / r"tinyc\win32\dllmain.o")
|
||||
addFile(nimDir / r"tinyc\win32\libtcc1.o")
|
||||
#addFile(tinycRoot / r"tinyc\win32\dllcrt1.o")
|
||||
#addFile(tinycRoot / r"tinyc\win32\dllmain.o")
|
||||
addFile(tinycRoot / r"tinyc\win32\libtcc1.o")
|
||||
|
||||
#addFile(nimDir / r"tinyc\win32\lib\crt1.c")
|
||||
#addFile(nimDir / r"tinyc\lib\libtcc1.c")
|
||||
#addFile(tinycRoot / r"tinyc\win32\lib\crt1.c")
|
||||
#addFile(tinycRoot / r"tinyc\lib\libtcc1.c")
|
||||
else:
|
||||
addSysincludePath(gTinyC, "/usr/include")
|
||||
when defined(amd64):
|
||||
addSysincludePath(gTinyC, "/usr/include/x86_64-linux-gnu")
|
||||
|
||||
proc compileCCode*(ccode: string) =
|
||||
proc compileCCode*(ccode: string, conf: ConfigRef) =
|
||||
gConf = conf
|
||||
if not libIncluded:
|
||||
libIncluded = true
|
||||
setupEnvironment()
|
||||
discard compileString(gTinyC, ccode)
|
||||
|
||||
proc run*(args: string) =
|
||||
var s = @[cstring(gProjectName)] & map(split(args), proc(x: string): cstring = cstring(x))
|
||||
proc run*(conf: ConfigRef, args: string) =
|
||||
doAssert gConf == conf
|
||||
var s = @[cstring(conf.projectName)] & map(split(args), proc(x: string): cstring = cstring(x))
|
||||
var err = tinyc.run(gTinyC, cint(s.len), cast[cstringArray](addr(s[0]))) != 0'i32
|
||||
closeCCState(gTinyC)
|
||||
if err: rawMessage(errExecutionOfProgramFailed, "")
|
||||
if err: rawMessage(conf, errUnknown, "")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue