Skip to content

Commit

Permalink
fix #62 ; toast is now automatically built on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 26, 2019
1 parent f367234 commit fc2620d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion nimterop/cimport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,39 @@ proc getToastError(output: string): string =
if result.len == 0:
result = output

proc nimteropTempDir(): string =
## all nimterop generated files go under here
getTempDir() / "nimterop"

proc getToastExe(): string =
# TODO: also allow user override (via -d:nimteropToast:path or
# see https://github.com/genotrance/nimterop/issues/68)
result = nimteropTempDir() / "toast"
#[
todo:
use same algo as shown here https://github.com/genotrance/nimterop/issues/69
but using nim deps instead of c deps; they can be obtained via:
`nim genDepend/--genDeps` or `https://github.com/nim-lang/RFCs/issues/123`
]#
if not fileExists(result) or gStateCT.nocache:
let toastSrc = currentSourcePath.parentDir.parentDir / "toast.nim"
let cmd = &"nim c -o:{result.quoteShell} {toastSrc.quoteShell}"
when nimvm:
echo ("getToastExe", cmd)
let (result, ret) = gorgeEx(cmd, cache=getCacheValue(toastSrc))
doAssert ret == 0, $(cmd, result, toastSrc)
else:
# todo: maybe support if it makes sense
doAssert false # TODO
else:
echo ("getToastExe: using cache", result)

proc getToast(fullpath: string, recurse: bool = false): string =
var
ret = 0
cmd = when defined(Windows): "cmd /c " else: ""

cmd &= "toast --pnim --preprocess "
cmd &= &"{getToastExe()} --pnim --preprocess "

if recurse:
cmd.add "--recurse "
Expand All @@ -104,6 +131,7 @@ proc getToast(fullpath: string, recurse: bool = false): string =
cmd.add &"{fullpath.quoteShell}"
echo cmd
# see https://github.com/genotrance/nimterop/issues/69
(result, ret) = gorgeEx(cmd, cache=getCacheValue(fullpath))
doAssert ret == 0, getToastError(result)
Expand Down
1 change: 1 addition & 0 deletions toast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ when isMainModule:
"debug": 'd',
"pgrammar": 'g'
})

1 comment on commit fc2620d

@genotrance
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick thoughts - I like that we have a fixed path but why not just point to toast in currentSourcePath.parentDir and call it? If it's not there, complain. Why rebuild and put it in temp? This will skip recompile for standard users as well as elaborate toast dep check every time anyone compiles any wrapper. Toast won't change for them so it will be a waste of build time.

Meanwhile, you'd want nimble to build binaries on nimble develop rather than doing it here.

With full path, we can also close #33 since there will be no collisions.

This really is only a problem for nimterop devs like us, better to rebuild toast in the nimble test target in the nimble file.

Please sign in to comment.