forked from electric-capital/open-dev-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·170 lines (151 loc) · 4.16 KB
/
run.sh
File metadata and controls
executable file
·170 lines (151 loc) · 4.16 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
ZIG_VERSION="0.14.0"
NEWLINE=$'\n'
print_usage() {
echo "crypto-ecosystems 2.0"
echo "Taxonomy of crypto open source repositories${NEWLINE}"
echo "USAGE:${NEWLINE} $0 <command> [arguments...]${NEWLINE}"
echo "SUBCOMMANDS:"
echo " build build the ce executable"
echo " validate build and validate the taxonomy using the migrations data"
echo " export <output_file> export the taxonomy to a json file"
echo " test run unit tests"
exit 1
}
if [ $# -eq 0 ]; then
print_usage
fi
detect_local_zig() {
if ! command -v zig &> /dev/null; then
echo "zig not found"
exit 1
fi
SYSTEM_ZIG_VERSION=$(zig version | cut -d' ' -f2)
if [[ "$SYSTEM_ZIG_VERSION
" < "0.14.0" ]]; then
echo "zig version $version is too old, need 0.14.0+"
exit 1
fi
echo "zig $SYSTEM_ZIG_VERSION found on system"
SYSTEM_ZIG_EXEC=$(command -v zig)
}
# Detect OS and architecture
detect_platform() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m)
local full_platform=""
local supported=true
case "$os" in
"windows"* | "mingw"* | "msys"*)
case "$arch" in
"x86_64")
full_platform="windows-x86_64"
;;
*)
supported=false
;;
esac
;;
"darwin"*)
case "$arch" in
"arm64")
full_platform="macos-aarch64"
;;
*)
supported=false
;;
esac
;;
"linux"*)
case "$arch" in
"x86_64")
full_platform="linux-x86_64"
;;
*)
supported=false
;;
esac
;;
*)
supported=false
;;
esac
if [ "$supported" = false ]; then
# If you are on an unsupported architecture, check to see if a
# sufficient zig compiler is available.
detect_local_zig
if [ -z "${SYSTEM_ZIG_EXEC}" ]; then
echo "$os-$arch is unsupported with the embedded build system."
echo ""
echo "Please use an architecture of the following:"
echo " - linux-x86_64"
echo " - macos-aarch64"
echo ""
echo "Or if you can run your own compiler do the following:"
echo "1/ Download a zig compiler with a version > 0.14.0 here: https://ziglang.org/download/"
echo "2/ Install zig into your path"
echo "3/ Run ./run.sh again"
exit 1
fi
fi
PLATFORM="$full_platform"
}
detect_platform
# Build function
setup() {
if [ -z "${SYSTEM_ZIG_EXEC:x}" ]; then
ZIG_FILE_ROOT="zig-${PLATFORM}-${ZIG_VERSION}"
ZIG_PACKAGE="toolchains/${ZIG_FILE_ROOT}.tar.xz"
mkdir -p .tcache
if [ ! -f ".tcache/$ZIG_FILE_ROOT/zig" ]; then
echo "Setting up build system for $PLATFORM..."
tar -xf "${ZIG_PACKAGE}" -C .tcache
fi
ZIG_EXEC=".tcache/${ZIG_FILE_ROOT}/zig"
else
echo "Using system zig for build"
ZIG_EXEC="${SYSTEM_ZIG_EXEC}"
fi
}
setup
if [ ! -f "$ZIG_EXEC" ] || [ ! -x "$ZIG_EXEC" ]; then
echo "Error: Zig executable not found or not executable at $ZIG_EXEC"
exit 1
fi
build() {
$ZIG_EXEC build -Doptimize=ReleaseSafe
}
validate() {
$ZIG_EXEC build -Doptimize=ReleaseSafe run -- validate
}
export_taxonomy() {
$ZIG_EXEC build -Doptimize=ReleaseSafe run -- export "${@}"
}
test() {
$ZIG_EXEC build -Doptimize=ReleaseSafe test --summary all
}
help() {
$ZIG_EXEC build -Doptimize=ReleaseSafe run -- help
}
# Main script logic
case "$1" in
"build")
build
;;
"validate")
validate "$@"
;;
"export")
shift
export_taxonomy "$@"
;;
"test")
test
;;
"help")
help
;;
*)
echo "Unknown command: $1"
exit 1
esac