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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import httpclient
import os
import osproc
import strformat
if paramCount() != 1:
echo(&"usage: {extractFilename(getAppFilename())} <version>")
quit(QuitFailure)
var version = paramStr(1)
const
BaseUrl = "https://github.com/google/protobuf/releases/download"
Systems = [
"linux-aarch_64",
"linux-x86_32",
"linux-x86_64",
"osx-x86_64",
"win32",
]
proc zipName(identifier: string): string =
&"protoc-{version}-{identifier}.zip"
proc exeSuffix(identifier: string): string =
result = ""
if identifier == "win32":
result = ".exe"
proc compilerName(identifier: string): string =
&"protoc-{identifier}{exeSuffix(identifier)}"
proc downloadFile(url, target: string) =
let
client = newHttpClient()
echo(&"downloading {url} -> {target}")
if not fileExists(target):
downloadFile(client, url, target)
proc downloadRelease(identifier: string) =
let
url = &"{BaseUrl}/v{version}/{zipName(identifier)}"
target = zipName(identifier)
downloadFile(url, target)
proc downloadSources() =
let url = &"https://github.com/google/protobuf/archive/v{version}.zip"
downloadFile(url, &"v{version}.zip")
proc extractCompiler(identifier: string) =
echo(&"extracting compiler: {identifier}")
createDir("src/nimpb_buildpkg/protobuf")
let args = @["-j", "-o", zipName(identifier), &"bin/protoc{exeSuffix(identifier)}"]
discard execProcess("unzip", args, nil, {poStdErrToStdout, poUsePath})
moveFile(&"protoc{exeSuffix(identifier)}", &"src/nimpb_buildpkg/protobuf/{compilerName(identifier)}")
proc extractIncludes() =
echo("extracting includes")
createDir("src/nimpb_buildpkg/protobuf")
let args = @["-o", zipName("linux-x86_64"), "include/*", "-d", "src/nimpb_buildpkg/protobuf"]
discard execProcess("unzip", args, nil, {poStdErrToStdout, poUsePath})
proc extractLicense() =
echo("extracting LICENSE")
let args = @["-o", "-j", &"v{version}.zip", &"protobuf-{version}/LICENSE", "-d", "src/nimpb_buildpkg/protobuf"]
discard execProcess("unzip", args, nil, {poStdErrToStdout, poUsePath})
for system in Systems:
downloadRelease(system)
extractCompiler(system)
downloadSources()
extractIncludes()
extractLicense()
|