Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How pack std lib to run without Nim installed #19

Closed
thisago opened this issue Sep 16, 2022 · 6 comments
Closed

How pack std lib to run without Nim installed #19

thisago opened this issue Sep 16, 2022 · 6 comments

Comments

@thisago
Copy link

thisago commented Sep 16, 2022

When the Nimscript script imports some std lib, it tries to open from Nim, but I need to run the app in a PC that doesn't have the Nim installed, I tried to list the exported procs from a list of libs and call exportTo, but it doesn't work, maybe it's related to #9

Here's what I tried:

import std/macros
import pkg/fusion/matching
from compiler/nimeval import findNimStdLibCompileTime
from std/os import walkDirRec, pcFile, extractFilename
include std/tables

{.experimental: "caseStmtMacros".}
macro listMethods(modules: static openArray[string]): untyped =
  var procs: Table[string, seq[string]]
  var i = 0
  for moduleName in modules:
    for path in walkDirRec(findNimStdLibCompileTime(), {pcFile}):
      if moduleName & ".nim" == extractFilename path:
        procs[moduleName] = newSeq[string]()
        let module = parseStmt(staticRead(path))
        for stmt in module:
          case stmt
            of (kind: in {nnkFuncDef,nnkProcDef..nnkIteratorDef}):#any kind of methody thing
              case stmt
              of [
                PostFix[_, @name],#only exported procs
                _,
                _,
                FormalParams[
                  _, #return type
                  .._], #other params
                .._]: procs[moduleName].add($name)
  result = newLit(procs)

macro addVmStd*(module: untyped): untyped =
  result = newStmtList()
  for (stdModule, procs) in listMethods(modules).pairs:
    for name in procs:
      result.add newCall("exportTo", module, ident name)

but it doesn't work

@beef331
Copy link
Owner

beef331 commented Sep 16, 2022

@thisago
Copy link
Author

thisago commented Sep 16, 2022

https://github.com/beef331/nimscripter/blob/master/src/nimscripter.nim#L60

ok, this is for specify the nim lib path, but I need to run without nim installed

i solved this by reading all std lib at compilation and writing at run time, isn't ideal, but works

@beef331
Copy link
Owner

beef331 commented Sep 16, 2022

It's the stdlib path you dont need nim installed you need a copy of the nim stdlib then you specify the stdpath wherever you placed that.

@thisago
Copy link
Author

thisago commented Sep 16, 2022

yea, that it that i've made, but there's a way to bundle everything in the binary (like using exportTo)?

@beef331
Copy link
Owner

beef331 commented Sep 16, 2022

No there is not, PRs welcome there. I've personally never needed it and generally assumed people would make their own stdlib that's not a 1:1 of Nim's due to adding size and features that might not be needed.

@thisago
Copy link
Author

thisago commented Sep 16, 2022

ok, thanks

@thisago thisago closed this as completed Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants