forked from juancarlospaco/faster-than-requests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.nims
executable file
·74 lines (59 loc) · 2.98 KB
/
build.nims
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
#!/usr/bin/env nim
import os
rmDir("dist")
mkDir("dist")
const version = "1.0"
const packageName = "faster_than_requests"
const gccWin32 = system.findExe("x86_64-w64-mingw32-gcc")
assert gccWin32.len > 0, "x86_64-w64-mingw32-gcc not found"
const zipExe = system.findExe("zip")
assert zipExe.len > 0, "zip command not found"
const nimbaseH = getHomeDir() / ".choosenim/toolchains/nim-" & NimVersion / "lib/nimbase.h"
const rootFolder = system.getCurrentDir()
--app:lib
--opt:speed
--cpu:amd64
--forceBuild
--threads:on
--compileOnly
--define:danger
--define:release
--define:ssl
--exceptions:goto
--gc:markAndSweep
--tlsEmulation:off
--define:noSignalHandler
--excessiveStackTrace:off
--define:nimDisableCertificateValidation
--outdir:getTempDir() # Save the *.so to /tmp, so is not on the package
# writeFile("upload2pypi.sh", "twine upload --verbose --repository-url 'https://test.pypi.org/legacy/' --comment 'Powered by https://Nim-lang.org' dist/*.zip\n")
# writeFile("package4pypi.sh", "cd dist && zip -9 -T -v -r " & packageName & ".zip *\n")
# writeFile("install2local4testing.sh", "sudo pip --verbose install dist/*.zip --no-binary :all:\nsudo pip uninstall " & packageName)
cpFile(rootFolder / "setup.cfg", "dist/setup.cfg")
cpFile(rootFolder / "setup.py", "dist/setup.py")
withDir("dist"):
selfExec "c -d:release --os:windows --out:faster_than_requests.pyd --gcc.exe:" & gccWin32 & " --gcc.linkerexe:" & gccWin32 & " " & rootFolder / "src/faster_than_requests.nim"
selfExec "c -d:release --out:faster_than_requests.so " & rootFolder / "src/faster_than_requests.nim"
mkDir("lin") # C for Linux, compile for Linux, save C files to lin/*.c
mkDir("win") # C for Windows, compile for Windows, save C files to win/*.c
mkDir("mac") # C for Mac OSX, manual compile, manual copy C files to mac/*.c
mkDir(packageName & ".egg-info")
cpFile(rootFolder / "PKG-INFO", packageName & ".egg-info/PKG-INFO")
withDir(packageName & ".egg-info"): # Old and weird metadata format of Python packages
writeFile("top_level.txt", "") # Serializes data as empty files(?), because reasons
writeFile("dependency_links.txt", "")
writeFile("requires.txt", "")
writeFile("zip-safe", "")
withDir("lin"):
selfExec "compileToC --nimcache:. " & rootFolder / "src/faster_than_requests.nim"
rmFile(packageName & ".json")
cpFile(nimbaseH, "nimbase.h")
withDir("win"):
selfExec "compileToC --nimcache:. --os:windows --gcc.exe:" & gccWin32 & " --gcc.linkerexe:" & gccWin32 & " " & rootFolder / "src/faster_than_requests.nim"
rmFile(packageName & ".json")
cpFile(nimbaseH, "nimbase.h")
withDir("mac"):
cpFile(nimbaseH, "nimbase.h")
exec "zip -9 -T -v -r " & packageName & "-" & version & ".zip *"
echo "Apple Mac OSX: Compile manually and copy all the .c files to 'mac/' folder, see https://github.com/foxlet/macOS-Simple-KVM"
selfExec "c -d:release --os:windows --out:faster_than_requests.pyd --gcc.exe:" & gccWin32 & " --gcc.linkerexe:" & gccWin32 & " " & rootFolder / "src/faster_than_requests.nim"