1
1
#! /bin/sh
2
2
3
- # build development version of the compiler; can be rerun safely.
3
+ # build development version of the compiler; can be rerun safely and will pickup
4
+ # any modification in config/build_config.txt
4
5
# arguments can be passed, eg `--os freebsd`
6
+ #
7
+ # Usage:
8
+ # sh build_all.sh # builds all
9
+ # NIMBUILD_ACTION=action_build_koch sh build_all.sh # just builds everything up to koch
10
+
5
11
6
12
set -u # error on undefined variables
7
13
set -e # exit on first error
@@ -11,9 +17,20 @@ echo_run(){
11
17
" $@ "
12
18
}
13
19
14
- [ -d csources ] || echo_run git clone -q --depth 1 https://github.com/nim-lang/csources.git
20
+ echo_run . config/build_config.txt
21
+
22
+ nim_csources=bin/nim_csources2
15
23
16
- nim_csources=bin/nim_csources
24
+ fetch_nim_csources (){
25
+ (
26
+ [ -d csources ] || echo_run $nim_csources2_clone_cmd
27
+ echo_run cd csources
28
+ echo_run git remote set-url origin $nim_csources2url
29
+ echo_run git fetch -q --depth 1 origin tag $nim_csources2_tag
30
+ echo_run git checkout $nim_csources2_tag
31
+ echo_run git reset --hard $nim_csources2_tag
32
+ )
33
+ }
17
34
18
35
build_nim_csources_via_script (){
19
36
echo_run cd csources
@@ -23,6 +40,8 @@ build_nim_csources_via_script(){
23
40
build_nim_csources (){
24
41
# avoid changing dir in case of failure
25
42
(
43
+ [ -f bin/nim ] && echo_run rm bin/nim # otherwise wrongly says: `bin/nim' is up to date.
44
+ # it's cheap to redo the linking step anyway
26
45
if [ $# -ne 0 ]; then
27
46
# some args were passed (eg: `--cpu i386`), need to call build.sh
28
47
build_nim_csources_via_script " $@ "
@@ -37,16 +56,50 @@ build_nim_csources(){
37
56
which $makeX && echo_run $makeX -C csources -j $(( nCPU + 2 )) -l $nCPU || build_nim_csources_via_script
38
57
fi
39
58
)
59
+ echo_run bin/nim -v
40
60
# keep $nim_csources in case needed to investigate bootstrap issues
41
61
# without having to rebuild from csources
42
62
echo_run cp bin/nim $nim_csources
43
63
}
44
64
45
- [ -f $nim_csources ] || echo_run build_nim_csources $@
65
+ # # stable API below here
66
+ action_fetch_csources (){
67
+ echo_run fetch_nim_csources
68
+ }
46
69
47
- # Note: if fails, may need to `cd csources && git pull`
48
- echo_run bin/nim c --skipUserCfg --skipParentCfg koch
70
+ action_build_csources (){
71
+ action_fetch_csources
72
+ echo_run build_nim_csources
73
+ }
74
+
75
+ action_build_koch (){
76
+ action_build_csources
77
+ # always bootstrap from $nim_csources for reproducibility, in case this is rerun
78
+ echo_run $nim_csources c --skipUserCfg --skipParentCfg --hints:off koch
79
+ }
80
+
81
+ action_build_all (){
82
+ action_build_koch
83
+ # re-running without modifications takes 2 seconds up to this line
84
+ echo_run ./koch boot -d:release --skipUserCfg --skipParentCfg --hints:off
85
+ echo_run ./koch tools --skipUserCfg --skipParentCfg --hints:off # Compile Nimble and other tools.
86
+ }
49
87
50
- echo_run ./koch boot -d:release --skipUserCfg --skipParentCfg
51
- echo_run ./koch tools --skipUserCfg --skipParentCfg # Compile Nimble and other tools.
88
+ echo " NIMBUILD_ACTION: ${NIMBUILD_ACTION} "
52
89
90
+ if [ -z " ${NIMBUILD_ACTION} " ]; then
91
+ action_build_all # backward compatibility: same as action_build_all
92
+ elif [ " ${NIMBUILD_ACTION} " = " action_definitions" ]; then
93
+ echo " bash functions defined" # useful if we source this, then we can call individual functions
94
+ elif [ " ${NIMBUILD_ACTION} " = " action_fetch_csources" ]; then
95
+ action_fetch_csources
96
+ elif [ " ${NIMBUILD_ACTION} " = " action_build_csources" ]; then
97
+ echo_run fetch_nim_csources
98
+ elif [ " ${NIMBUILD_ACTION} " = " action_build_koch" ]; then
99
+ action_build_koch
100
+ elif [ " ${NIMBUILD_ACTION} " = " action_build_all" ]; then
101
+ action_build_all
102
+ else
103
+ echo " unrecognized NIMBUILD_ACTION: $NIMBUILD_ACTION "
104
+ exit 1
105
+ fi
0 commit comments