-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.nims
99 lines (80 loc) · 2.63 KB
/
config.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import strutils
switch("define", "testCases")
switch("debugger", "native")
switch("d", "nimPreviewHashRef")
switch("d", "ssl")
switch("d", "useOpenSSL3")
switch("gc", "refc")
when (NimMajor, NimMinor) < (1, 7):
# Locklevels never worked and are gone but warnings persist.
switch("warning", "LockLevel:off")
when (NimMajor, NimMinor, NimPatch) >= (1, 6, 12):
# Someone made a move to deprecate, but they're undoing it.
switch("warning", "BareExcept:off")
when not defined(debug):
switch("d", "release")
switch("opt", "speed")
var targetArch = hostCPU
when defined(macosx):
# -d:arch=amd64 will allow you to specifically cross-compile to intel.
# The .strdefine. pragma sets the variable from the -d: flag w/ the same
# name, overriding the value of the const.
const arch {.strdefine.} = "detect"
var
targetStr = ""
if arch == "detect":
# On an x86 mac, the proc_translated OID doesn't exist. So if this
# returns either 0 or 1, we know we're running on an arm. Right now,
# nim will always use rosetta, so should always give us a '1', but
# that might change in the future.
let sysctlOut = staticExec("sysctl -n sysctl.proc_translated")
if sysctlOut in ["0", "1"]:
targetArch = "arm64"
else:
targetArch = "amd64"
else:
echo "Override: arch = " & arch
if targetArch == "arm64":
echo "Building for arm64"
targetStr = "arm64-apple-macos13"
elif targetArch == "amd64":
targetStr = "x86_64-apple-macos13"
echo "Building for amd64"
else:
echo "Invalid target architecture for MacOs: " & arch
quit(1)
switch("cpu", targetArch)
switch("passc", "-flto -target " & targetStr)
switch("passl", "-flto -w -target " & targetStr &
"-Wl,-object_path_lto,lto.o")
elif defined(linux):
switch("passc", "-static")
switch("passl", "-static")
else:
echo "Platform not supported."
quit(1)
var
subdir = ""
for item in listDirs(thisDir()):
if item.endswith("/files"):
subdir = "/files"
break
proc getEnvDir(s: string, default = ""): string =
result = getEnv(s, default)
if not result.endsWith("/"):
result &= "/"
exec thisDir() & subdir & "/bin/buildlibs.sh " & thisDir() & "/files/deps"
var
default = getEnvDir("HOME") & ".local/c0"
localDir = getEnvDir("LOCAL_INSTALL_DIR", default)
libDir = localdir & "libs"
libs = ["pcre", "ssl", "crypto", "gumbo"]
when defined(linux):
var
muslPath = localdir & "musl/bin/musl-gcc"
switch("gcc.exe", muslPath)
switch("gcc.linkerexe", muslPath)
for item in libs:
let libFile = "lib" & item & ".a"
switch("passL", libDir & "/" & libFile)
switch("dynlibOverride", item)