-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
191 lines (161 loc) · 4.6 KB
/
build.sh
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
#!/usr/bin/env bash
USAGE=$(cat <<EOF
usage: build.sh [option*]
Foolang build script.
Stages:
1. build the bootstrap compiler unless it already exists.
2. build current compiler with the bootstrap compiler.
3. build current compiler with compiler from stage 2.
4. build current compiler with compiler from stage 3.
5. verify that steps #3 and #4 result in identical builds.
The stage 3 build always is the final artefact.
Options:
--bootstrap
Force stage 1. even if bootstrap compiler already exists.
--no-interpreter-build
Skip building the bootstrap interpreter. This is for CI use only.
--no-verify
Skip steps #4 and #5.
--quick-and-dirty
Just does the step 3: useful when eg. working with main.c.
EOF
)
set -euo pipefail
source utils.sh
write_build_info
on_exit restore_build_info
BOOTSTRAP_INTERPRETER=$(exename target/debug/bootstrap-interpreter)
BOOTSTRAP_COMPILER=$(exename build/bootstrap-compiler)
SELF_COMPILER=$(exename build/self-compiler)
FOO=$(exename build/foo)
FOO2=$(exename build/foo2)
CLEAN=false
BOOTSTRAP=false
NO_INTERPRETER_BUILD=false
NO_SELF_COMPILER_BUILD=false
VERIFY=true
for option in $@
do
case $option in
--help|-h)
echo "$USAGE"
exit
;;
--bootstrap)
BOOTSTRAP=true
;;
--no-interpreter-build)
NO_INTERPRETER_BUILD=true
;;
--no-verify)
# It's just easier to keep verify option this way around.
VERIFY=false
;;
--quick-and-dirty)
NO_INTERPRETER_BUILD=true
NO_SELF_COMPILER_BUILD=true
VERIFY=false
BOOTSTRAP=false
;;
*)
echo "ERROR: unknown option to build.sh: $option"
echo "$USAGE"
exit 1
;;
esac
done
mkdir -p build/
# Figure out if we need a bootstrap or not.
if ! $BOOTSTRAP && ! [[ -e $BOOTSTRAP_COMPILER ]]; then
echo "Bootstrap compiler not found, bootstrapping."
BOOTSTRAP=true
fi
if $BOOTSTRAP && $VERIFY; then
echo "Expected build time: ~7min (bootstrap, self-build, foo, verify)"
elif $BOOTSTRAP; then
echo "Expected build time: ~6min (bootstrap, self-build, foo)"
elif $VERIFY; then
echo "Expected build time: ~3min (self-build, foo, verify)"
elif $NO_SELF_COMPILER_BUILD; then
echo "Expected build time: <1min (foo)"
else
echo "Expected build time: ~1.5min (self-build, foo)"
fi
if $BOOTSTRAP; then
if $NO_INTERPRETER_BUILD && [[ -e $BOOTSTRAP_INTERPRETER ]]; then
echo "Skipping bootstrap interpreter build."
else
if $NO_INTERPRETER_BUILD; then
echo "Bootstrap interpreter not found, build forced."
fi
start_clock "building bootstrap interpreter"
if cargo build &> build/bootstrap-interpreter.log; then
ok
else
fail build/bootstrap-interpreter.log
fi
fi
rm -rf build/bootstrap-compiler-c
start_clock "building bootstrap compiler"
if $BOOTSTRAP_INTERPRETER foo/foo.foo -- --compile foo/foo.foo \
&> build/bootstrap-compiler.log
then
ok
mv $(exename foo/foo) $BOOTSTRAP_COMPILER
cp -a c build/bootstrap-compiler-c
else
fail build/bootstrap-compiler.log
fi
fi
if ! $NO_SELF_COMPILER_BUILD; then
rm -rf build/self-compiler-c
start_clock "building self-compiler"
if $BOOTSTRAP_COMPILER --compile foo/foo.foo \
&> build/self-compiler.log
then
ok
mv $(exename foo/foo) $SELF_COMPILER
cp -a c build/self-compiler-c
else
fail build/self-compiler.log
fi
fi
rm -rf build/foo-c
start_clock "building foo"
if $SELF_COMPILER --compile foo/foo.foo \
&> build/foo.log
then
ok
mv $(exename foo/foo) $FOO
cp -a c build/foo-c
else
fail build/foo.log
fi
rm -rf build/foo2-c
if $VERIFY; then
start_clock "building second generation foo"
if $FOO --compile foo/foo.foo \
&> build/foo2.log
then
ok
mv $(exename foo/foo) $FOO2
cp -a c build/foo2-c
else
fail build/foo2.log
fi
if diff -u --recursive build/foo-c build/foo2-c \
&> build/self-build.diff
then
echo "Self-build complete, enjoy quietly!"
else
echo -n "$(red WARNING): inconsistent self-build!"
echo
echo "Please report with contents of build/self-build.diff to"
echo
echo " https://github.com/nikodemus/foolang"
echo
fi
else
echo "Unverified build, consistency not checked - enjoy quietly!"
fi
echo "Binary: $FOO"