diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-05-11 03:01:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 12:01:18 +0200 |
commit | 9502e39b634eea8e04f07ddc110b466387f42322 (patch) | |
tree | 240ffa98d6f1d556986dccbb66e9f5e0e81675e4 /compiler/main.nim | |
parent | d11cb9d49596957e9fa097110cf19e9caf085592 (diff) | |
download | Nim-9502e39b634eea8e04f07ddc110b466387f42322.tar.gz |
`nim doc --backend:js`, `nim doc --doccmd:-d:foo`, `nim r --backend:js`, `--doccmd:skip` + other improvements (#14278)
* `nim doc --backend:js|cpp...` `nim doc --doccmd:'-d:foo --threads:on'` `nim r --backend:cpp...` (implies --run --usenimcache) * --usenimcache works with all targets * --docCmd:skip now skips compiling snippets; 50X speedup for doc/manual.rst
Diffstat (limited to 'compiler/main.nim')
-rw-r--r-- | compiler/main.nim | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/compiler/main.nim b/compiler/main.nim index c94af24d5..00bc579df 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -119,8 +119,7 @@ when not defined(leanCompiler): let conf = graph.config conf.exc = excCpp - if conf.outDir.isEmpty: - conf.outDir = conf.projectPath + setOutDir(conf) if conf.outFile.isEmpty: conf.outFile = RelativeFile(conf.projectName & ".js") @@ -128,7 +127,6 @@ when not defined(leanCompiler): setTarget(graph.config.target, osJS, cpuJS) #initDefines() defineSymbol(graph.config.symbols, "ecmascript") # For backward compatibility - defineSymbol(graph.config.symbols, "js") semanticPasses(graph) registerPass(graph, JSgenPass) compileProject(graph) @@ -190,25 +188,46 @@ proc mainCommand*(graph: ModuleGraph) = conf.lastCmdTime = epochTime() conf.searchPaths.add(conf.libpath) setId(100) - template handleC() = - conf.cmd = cmdCompileToC - if conf.exc == excNone: conf.exc = excSetjmp - defineSymbol(graph.config.symbols, "c") - commandCompileToC(graph) + + ## Calling `setOutDir(conf)` unconditionally would fix regression + ## https://github.com/nim-lang/Nim/issues/6583#issuecomment-625711125 + when false: setOutDir(conf) + if optUseNimcache in conf.globalOptions: setOutDir(conf) + + template handleBackend(backend2: TBackend) = + conf.backend = backend2 + conf.cmd = cmdCompileToBackend + defineSymbol(graph.config.symbols, $backend2) + case backend2 + of backendC: + if conf.exc == excNone: conf.exc = excSetjmp + commandCompileToC(graph) + of backendCpp: + if conf.exc == excNone: conf.exc = excCpp + commandCompileToC(graph) + of backendObjc: + commandCompileToC(graph) + of backendJs: + when defined(leanCompiler): + globalError(conf, unknownLineInfo, "compiler wasn't built with JS code generator") + else: + if conf.hcrOn: + # XXX: At the moment, system.nim cannot be compiled in JS mode + # with "-d:useNimRtl". The HCR option has been processed earlier + # and it has added this define implictly, so we must undo that here. + # A better solution might be to fix system.nim + undefSymbol(conf.symbols, "useNimRtl") + commandCompileToJS(graph) + of backendInvalid: doAssert false + case conf.command.normalize - of "c", "cc", "compile", "compiletoc": handleC() # compile means compileToC currently - of "cpp", "compiletocpp": - conf.cmd = cmdCompileToCpp - if conf.exc == excNone: conf.exc = excCpp - defineSymbol(graph.config.symbols, "cpp") - commandCompileToC(graph) - of "objc", "compiletooc": - conf.cmd = cmdCompileToOC - defineSymbol(graph.config.symbols, "objc") - commandCompileToC(graph) + of "c", "cc", "compile", "compiletoc": handleBackend(backendC) # compile means compileToC currently + of "cpp", "compiletocpp": handleBackend(backendCpp) + of "objc", "compiletooc": handleBackend(backendObjc) + of "js", "compiletojs": handleBackend(backendJs) of "r": # different from `"run"`! conf.globalOptions.incl {optRun, optUseNimcache} - handleC() + handleBackend(conf.backend) of "run": conf.cmd = cmdRun when hasTinyCBackend: @@ -216,18 +235,6 @@ proc mainCommand*(graph: ModuleGraph) = commandCompileToC(graph) else: rawMessage(conf, errGenerated, "'run' command not available; rebuild with -d:tinyc") - of "js", "compiletojs": - when defined(leanCompiler): - quit "compiler wasn't built with JS code generator" - else: - conf.cmd = cmdCompileToJS - if conf.hcrOn: - # XXX: At the moment, system.nim cannot be compiled in JS mode - # with "-d:useNimRtl". The HCR option has been processed earlier - # and it has added this define implictly, so we must undo that here. - # A better solution might be to fix system.nim - undefSymbol(conf.symbols, "useNimRtl") - commandCompileToJS(graph) of "doc0": when defined(leanCompiler): quit "compiler wasn't built with documentation generator" |