aboutsummaryrefslogtreecommitdiff
path: root/src/nimpb_protoc.nim
blob: 951849a9f15cfe752afcc9ed1788a52c99f6017c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import strformat

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 = ""

let
    paths = @[
        # getAppDir() / "src" / "nimpb_protocpkg" / "protobuf",
        # getAppDir() / "nimpb_protocpkg" / "protobuf",
        parentDir(currentSourcePath()) / "nimpb_protocpkg" / "protobuf",
    ]

proc getCompilerPath*(): string =
    let
        compilerName = &"protoc-{compilerId}{exeSuffix}"

    for path in paths:
        if fileExists(path / compilerName):
            return path / compilerName

    raise newException(Exception, &"{compilerName} not found!")

proc getProtoIncludeDir*(): string =
    for path in paths:
        if fileExists(path / "include"):
            return path / "include"