aboutsummaryrefslogtreecommitdiff
path: root/fetch.nim
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2018-04-06 00:08:34 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2018-04-06 00:08:34 +0300
commit203b887dd33f52ad88d3afd8ef54ea444319346a (patch)
tree7ba70973bfd418c60848b3d54cd2afabcc9b606e /fetch.nim
downloadnimpb_protoc-203b887dd33f52ad88d3afd8ef54ea444319346a.tar.gz
nimpb_protoc-203b887dd33f52ad88d3afd8ef54ea444319346a.zip
Initial commit
Diffstat (limited to 'fetch.nim')
-rw-r--r--fetch.nim70
1 files changed, 70 insertions, 0 deletions
diff --git a/fetch.nim b/fetch.nim
new file mode 100644
index 0000000..8e1e262
--- /dev/null
+++ b/fetch.nim
@@ -0,0 +1,70 @@
+import httpclient
+import os
+import osproc
+import strformat
+
+const
+ Version = "3.5.1"
+ 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()