aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2018-04-11 19:37:14 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2018-04-11 19:37:14 +0300
commitad3a344c8f3c79ba487d45b70b269fa55423670a (patch)
treeb74dd630d30a06a6c67213e4575685151dbce1ef
parent2cf4a1710c7fac6263e50b384592df6a18f5da08 (diff)
downloadnimpb-ad3a344c8f3c79ba487d45b70b269fa55423670a.tar.gz
nimpb-ad3a344c8f3c79ba487d45b70b269fa55423670a.zip
Changes to finding the protoc compiler
Now there are three ways we can find the protoc compiler: 1. The user tells us the full path to it with NIMPB_PROTOC env var 2. The user puts protoc in PATH 3. The user installs nimpb_protoc (renamed from nimpb_build) with Nimble These are listed in current precedence order.
-rw-r--r--nimpb.nimble2
-rw-r--r--nimpb/compiler/compiler.nim92
-rw-r--r--nimpb/compiler/generator.nim (renamed from nimpb/compiler/plugin.nim)0
3 files changed, 45 insertions, 49 deletions
diff --git a/nimpb.nimble b/nimpb.nimble
index 7f55df3..28247db 100644
--- a/nimpb.nimble
+++ b/nimpb.nimble
@@ -5,4 +5,6 @@ license = "MIT"
skipDirs = @["examples", "tests"]
+bin = @["nimpb/compiler/compiler"]
+
requires "nim >= 0.18.0"
diff --git a/nimpb/compiler/compiler.nim b/nimpb/compiler/compiler.nim
index b93d158..fe0a5e4 100644
--- a/nimpb/compiler/compiler.nim
+++ b/nimpb/compiler/compiler.nim
@@ -1,64 +1,58 @@
+import macros
import os
import osproc
-import streams
import strformat
-import strtabs
import strutils
-from plugin import processFileDescriptorSet, ServiceGenerator, Service, ServiceMethod
-
+from generator import processFileDescriptorSet, ServiceGenerator, Service, ServiceMethod
export Service, ServiceMethod
-when defined(windows):
- const compilerId = "win32"
-elif defined(linux):
- when defined(i386):
- const arch = "x86_32"
- elif defined(amd64):
- const arch = "x86_64"
- elif defined(arm64):
- const arch = "aarch_64"
- else:
- {.fatal:"unsupported architecture".}
- const compilerId = "linux-" & arch
-elif defined(macosx):
- when defined(amd64):
- const arch = "x86_64"
- else:
- {.fatal:"unsupported architecture".}
- const compilerId = "osx-" & arch
-else:
- {.fatal:"unsupported platform".}
-
-when defined(windows):
- const exeSuffix = ".exe"
-else:
- const exeSuffix = ""
-
-proc findCompiler(): string =
- let
- compilerName = &"protoc-{compilerId}{exeSuffix}"
- paths = @[
- getAppDir() / "src" / "nimpb_buildpkg" / "protobuf",
- getAppDir() / "nimpb_buildpkg" / "protobuf",
- parentDir(currentSourcePath()) / "nimpb_buildpkg" / "protobuf",
- ]
-
- for path in paths:
- if fileExists(path / compilerName):
- return path / compilerName
-
- raise newException(Exception, &"{compilerName} not found!")
+const
+ nimpbBuildInfo = gorgeEx("nimble dump nimpb_protoc")
+ isNimpbBuildAvailable = nimpbBuildInfo[1] == 0
+
+when isNimpbBuildAvailable:
+ import nimpb_protoc/nimpb_protoc
+
+proc findCompiler*(): string =
+ result = ""
+
+ if existsEnv("NIMPB_PROTOC"):
+ result = getEnv("NIMPB_PROTOC")
+ if not fileExists(result):
+ result = ""
+
+ if result == "":
+ result = findExe("protoc")
+
+ when isNimpbBuildAvailable:
+ if result == "":
+ result = nimpb_protoc.getCompilerPath()
+
+ if result == "":
+ let msg = """
+error: protoc compiler not found
+
+Now you have three options to make this work:
+
+1. Tell me the full path to the protoc executable by using NIMPB_PROTOC
+ environment variable
+
+2. You can also make sure that protoc is in PATH, which will make me find it
+
+3. Install nimpb_protoc with nimble, which includes the protoc compiler for the
+ most common platforms (Windows, Linux, macOS) and I should be able to pick
+ it up after a recompile
+
+"""
+
+ raise newException(Exception, msg)
proc builtinIncludeDir(compilerPath: string): string =
parentDir(compilerPath) / "include"
-template verboseEcho(x: untyped): untyped =
- if verbose:
- echo(x)
-
proc myTempDir(): string =
- result = getTempDir() / "nimpb_build_tmp"
+ result = getTempDir() / "nimpb_protoc_tmp"
proc compileProtos*(protos: openArray[string],
includes: openArray[string],
diff --git a/nimpb/compiler/plugin.nim b/nimpb/compiler/generator.nim
index abdad07..abdad07 100644
--- a/nimpb/compiler/plugin.nim
+++ b/nimpb/compiler/generator.nim