-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·235 lines (211 loc) · 7.34 KB
/
build.sh
File metadata and controls
executable file
·235 lines (211 loc) · 7.34 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
function exit_usage() {
echo "Usage: build.sh <wizeng|objdump|unittest> <x86-linux|x86-64-darwin|x86-64-linux|jvm|wasm-wave>"
exit 1
}
# Append a comma-separated string to the given variable.
append_comma_sep() {
local varname=$1
local newpair=$2
local current="${!varname}"
if [ -z "$current" ]; then
eval "$varname=\"$newpair\""
else
eval "$varname=\"$current,$newpair\""
fi
}
if [ "$#" -lt 2 ]; then
exit_usage
fi
V3C=${V3C:=$(which v3c)}
if [ ! -x "$V3C" ]; then
echo "Virgil compiler (v3c) not found in \$PATH, and \$V3C not set"
exit 1
fi
if [ "$VIRGIL_LIB" = "" ]; then
if [ "$VIRGIL_LOC" = "" ]; then
V3C_LOC=$(dirname $(which v3c))
VIRGIL_LOC=$(cd $V3C_LOC/../ && pwd)
fi
VIRGIL_LIB=${VIRGIL_LOC}/lib/
fi
if [ ! -e "$VIRGIL_LIB/util/Vector.v3" ]; then
echo "Virgil library code not found (searched $VIRGIL_LIB)."
echo "Please set either: "
echo " VIRGIL_LOC, to the root of your Virgil installation"
echo " VIRGIL_LIB, to point directly to root of the library"
exit 1
fi
ENGINE="src/engine/*.v3 src/util/*.v3 $VIRGIL_LIB/util/*.v3"
MONITORS="src/monitors/*.v3"
TEST_MONITORS="src/monitors/test/*.v3"
DEBUG_MONITORS="src/monitors/debug/*.v3"
TARGET_V3="src/engine/v3/*.v3"
TARGET_X86_64="src/engine/native/*.v3 src/engine/compiler/*.v3 src/engine/x86-64/*.v3 $VIRGIL_LIB/asm/x86-64/*.v3"
UNITTEST="test/unittest/*.v3 test/wasm-spec/*.v3 test/unittest.main.v3 $VIRGIL_LIB/test/*.v3"
UNITTEST_X86_64_LINUX="test/unittest/x86-64-linux/*.v3"
SPECTEST_MODE="test/wasm-spec/*.v3 src/SpectestMode.v3"
WASM_MODE="src/WasmMode.v3"
WIZENG="src/wizeng.main.v3 src/modules/*.v3 src/modules/wizeng/*.v3"
WAVE="src/modules/wave/*.v3"
WASI="src/modules/wasi/*.v3"
WASI_X86_64_LINUX="src/modules/wasi/x86-64-linux/*.v3 $VIRGIL_LIB/x86-64-linux/SyscallLayouts.v3"
WALI="src/modules/wali/*.v3"
WALI_X86_64_LINUX="src/modules/wali/x86-64-linux/*.v3 $VIRGIL_LIB/wasm-linux/*.v3"
MODULES="src/modules/*.v3"
TARGET_CBD_SLOW="src/engine/cbd/slow/*.v3"
TARGET_CBD_FAST="src/engine/cbd/fast/*.v3"
CONTINUATION="src/engine/continuation/UnboxedContinuation.v3"
CONTINUATION_X86_64="src/engine/x86-64/continuation/X86_64UnboxedContinuation.v3"
while [[ $# -gt 0 ]]; do
case "$1" in
--nojit)
append_comma_sep REDEFS "SpcTuning.disable=true"
;;
--test-monitors)
MONITORS="$MONITORS $TEST_MONITORS"
;;
--debug)
MONITORS="$MONITORS $DEBUG_MONITORS"
append_comma_sep REDEFS "MonitorOptions.enableCheckMonitors=true"
;;
--debug-gc)
DEBUG_GC=1
;;
--no-spec-test)
SPECTEST_MODE=""
;;
--no-wasm-run)
WASM_MODE=""
;;
--boxed-continuation)
append_comma_sep REDEFS "FeatureDisable.unboxedConts=true"
CONTINUATION="src/engine/continuation/BoxedContinuation.v3"
CONTINUATION_X86_64="src/engine/x86-64/continuation/X86_64BoxedContinuation.v3"
;;
*)
break
;;
esac
shift
done
ENGINE="$ENGINE $CONTINUATION"
TARGET_X86_64="$TARGET_X86_64 $CONTINUATION_X86_64"
CBD=false
if [[ "$1" = "--cbd" ]]; then
CBD=true
shift
fi
PROGRAM=$1
TARGET=$2
if [[ "$TARGET" =~ x86 && $DEBUG_GC = 1 ]]; then
V3C_OPTS="$V3C_OPTS -redef-field=RiGc.debug=true"
fi
function make_build_file() {
local target=$TARGET
local build_time=$(date "+%Y-%m-%d %H:%M:%S")
build_file="bin/Build-${TARGET}.v3"
if [ "$release" == "release" ]; then
local build_data="$target $build_time Release"
else
local build_data="$target $build_time by ${USER}@${HOST}"
fi
# TODO: use -redef-field instead of generating a build file
REVS="$(git rev-list --count HEAD)"
if [ -z $REVS ];
then
REVS=$(date +%s)
fi
echo "var unused__ = (Version.buildData = \"$build_data\", Version.minorVersion = $REVS);" > $build_file
echo $build_file
}
# compute sources
if [ "$PROGRAM" = "wizeng" ]; then
SOURCES="$ENGINE $WAVE $WASI $WALI $MONITORS $SPECTEST_MODE $WASM_MODE $WIZENG"
if [[ "$TARGET" = "x86-64-linux" || "$TARGET" = "x86_64_linux" ]]; then
SOURCES="$SOURCES $WASI_X86_64_LINUX $WALI_X86_64_LINUX"
fi
elif [ "$PROGRAM" = "unittest" ]; then
SOURCES="$ENGINE $UNITTEST"
if [[ "$TARGET" = "x86-64-linux" || "$TARGET" = "x86_64_linux" ]]; then
SOURCES="$SOURCES $UNITTEST_X86_64_LINUX $MODULES $WASI $WASI_X86_64_LINUX"
fi
elif [ "$PROGRAM" = "objdump" ]; then
SOURCES="$ENGINE src/objdump.main.v3"
else
exit_usage
fi
# make build file with target
BUILD_FILE=$(make_build_file)
PREGEN=${PREGEN:=1}
LANG_OPTS="-fun-exprs -simple-bodies"
if [ "$REDEFS" != "" ]; then
V3C_OPTS="$V3C_OPTS -redef-field=$REDEFS"
fi
# build
exe=${PROGRAM}.${TARGET}
if [[ "$TARGET" = "x86-linux" || "$TARGET" = "x86_linux" ]]; then
TARGET_SRC=$TARGET_V3
if "$CBD"; then TARGET_SRC="$TARGET_CBD_SLOW $TARGET_V3"; fi
exec v3c-x86-linux -symbols -heap-size=512m -stack-size=1m $LANG_OPTS $V3C_OPTS -program-name=${PROGRAM}.x86-linux -output=bin/ $SOURCES $BUILD_FILE $TARGET_SRC
elif [[ "$TARGET" = "x86-64-darwin" || "$TARGET" = "x86_64_darwin" ]]; then
exec v3c-x86-64-darwin -symbols -heap-size=700m -stack-size=1m $LANG_OPTS $V3C_OPTS -program-name=${PROGRAM}.x86-64-darwin -output=bin/ $SOURCES $BUILD_FILE $TARGET_V3
elif [[ "$TARGET" = "x86-64-linux" || "$TARGET" = "x86_64_linux" ]]; then
TARGET_SRC=$TARGET_X86_64
if "$CBD"; then TARGET_SRC="$TARGET_CBD_FAST $TARGET_X86_64"; fi
exec v3c-x86-64-linux -symbols -heap-size=700m -stack-size=2m $LANG_OPTS $V3C_OPTS -program-name=${PROGRAM}.${TARGET} -output=bin/ $SOURCES $BUILD_FILE $TARGET_SRC
STATUS=$?
if [ $STATUS != 0 ]; then
exit $STATUS
fi
if [ $PROGRAM = "wizeng" ]; then
E=bin/${exe}
HOSTS=$(scripts/sense_host.sh)
if [[ "$PREGEN" != 0 && "$HOSTS" =~ "x86-64-linux" ]]; then
# try running pregen if the host platform can run the pregen binary
cp $E $E.pregen
$E.pregen --pregen=$E > /tmp/wizeng.$(whoami).pregen.out 2>&1
STATUS=$?
if [ $STATUS != 0 ]; then
echo "error: running $E.pregen failed"
exit $STATUS
else
rm $E.pregen
fi
fi
fi
elif [ "$TARGET" = "jvm" ]; then
exec v3c-jar $LANG_OPTS $V3C_OPTS -program-name=${PROGRAM}.jvm -output=bin/ $SOURCES $BUILD_FILE $TARGET_V3
elif [[ "$TARGET" == wasm-* ]]; then
# Compile to a wasm target
V3C_PATH=$(which v3c)
V3C_WASM_TARGET=${V3C_PATH/bin\/v3c/bin\/dev\/v3c-$TARGET}
if [ ! -x $V3C_WASM_TARGET ]; then
echo Unknown Wasm target \"$TARGET\". Found these:
ls -a ${V3C_PATH/bin\/v3c/bin\/dev\/v3c-wasm-*} | cat
exit 1
fi
exec $V3C_WASM_TARGET -symbols -heap-size=200m $LANG_OPTS $V3C_OPTS -program-name=${PROGRAM} -output=bin/ $SOURCES $BUILD_FILE $TARGET_V3
elif [ "$TARGET" = "v3i" ]; then
# check that the sources typecheck
$V3C $LANG_OPTS $V3C_OPTS $SOURCES $TARGET_V3
RET=$?
if [ $RET != 0 ]; then
exit $RET
fi
DIR=$(pwd)
LIST=""
for f in $SOURCES $TARGET_V3; do
if [[ "$f" != /* ]]; then
f="$DIR/$f"
fi
LIST="$LIST $(ls $f)"
done
echo '#!/usr/bin/env bash' > bin/$PROGRAM.v3i
echo "v3i $LANG_OPTS \$V3C_OPTS $LIST" '$@' >> bin/$PROGRAM.v3i
chmod 755 bin/$PROGRAM.v3i
# run v3c just to check for compile errors
exec $V3C $LANG_OPTS $V3C_OPTS $LIST
else
exit_usage
fi