15
15
set -e
16
16
17
17
function follow_links() {
18
- file=" $1 "
18
+ local file=" $1 "
19
19
while [ -h " $file " ]; do
20
20
# On Mac OS, readlink -f doesn't work.
21
21
file=" $( readlink " $file " ) "
@@ -31,6 +31,8 @@ CUR_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
31
31
32
32
SDK_DIR=" $CUR_DIR /../../.."
33
33
34
+ . " $CUR_DIR /shared_functions.sh"
35
+
34
36
OPTIONS=()
35
37
GEN_KERNEL_OPTIONS=()
36
38
PACKAGES=
@@ -98,19 +100,37 @@ else
98
100
OUT_DIR=" $SDK_DIR /out"
99
101
fi
100
102
101
- HOST_ARCH=" X64"
102
- if [[ ` uname -m` == ' arm64' ]]; then
103
- HOST_ARCH=" ARM64"
104
- fi
103
+ HOST_ARCH=" $( host_arch) "
105
104
106
105
export DART_CONFIGURATION=${DART_CONFIGURATION:- Release$HOST_ARCH }
106
+ TARGET_ARCH=" $( parse_target_arch " $DART_CONFIGURATION " ) "
107
107
BUILD_DIR=" $OUT_DIR /$DART_CONFIGURATION "
108
-
109
- DART=" ${SDK_DIR} /tools/sdks/dart-sdk/bin/dart"
110
- if [ ! -f " $DART " ]; then
111
- DART=" $BUILD_DIR /dart"
108
+ if [ ! -d " $BUILD_DIR " ]; then
109
+ echo " $BUILD_DIR is not a directory"
110
+ exit 1
112
111
fi
113
112
113
+ function find_dart {
114
+ local tools_dart=" ${SDK_DIR} /tools/sdks/dart-sdk/bin/dart"
115
+ if [ -f " $tools_dart " ]; then
116
+ echo " $tools_dart "
117
+ else
118
+ local host_dart=" "
119
+ if [[ " $HOST_ARCH " == " $TARGET_ARCH " ]]; then
120
+ host_dart=" $BUILD_DIR /dart"
121
+ else
122
+ host_dart=" $OUT_DIR /Release$HOST_ARCH /dart"
123
+ fi
124
+ if [ ! -f " $host_dart " ]; then
125
+ echo " Cannot find dart at either $tools_dart or $host_dart "
126
+ exit 1
127
+ fi
128
+ echo " $host_dart "
129
+ fi
130
+ }
131
+
132
+ DART=" $( find_dart) "
133
+
114
134
function gen_kernel() {
115
135
if [[ " $DART_GN_ARGS " == * " precompile_tools=true" * ]]; then
116
136
# Precompile gen_kernel to an AOT app.
@@ -129,10 +149,29 @@ gen_kernel --platform "${BUILD_DIR}/vm_platform_strong.dill" \
129
149
-o " $SNAPSHOT_FILE .dill" \
130
150
" $SOURCE_FILE "
131
151
132
-
152
+ GEN_SNAPSHOT=" gen_snapshot"
153
+ # If the target architecture differs from the host architecture, use
154
+ # gen_snapshot for the host architecture for cross compilation, which is
155
+ # denoted by an X between the build mode and the architecture name,
156
+ # e.g., ReleaseXARM64 on X64.
157
+ if [[ ( " $DART_CONFIGURATION " =~ (Debug| Release| Product)X[^6] ) && \
158
+ ( " $HOST_ARCH " ! = " $TARGET_ARCH " ) ]]; then
159
+ case " $HOST_ARCH " in
160
+ " X64" )
161
+ GEN_SNAPSHOT=" clang_x64/${GEN_SNAPSHOT} "
162
+ ;;
163
+ " ARM64" )
164
+ GEN_SNAPSHOT=" clang_arm64/${GEN_SNAPSHOT} "
165
+ ;;
166
+ * )
167
+ echo " Unexpected host architecture $HOST_ARCH for cross compilation"
168
+ exit 1
169
+ ;;
170
+ esac
171
+ fi
133
172
134
173
# Step 2: Generate snapshot from the Kernel binary.
135
- " $ BUILD_DIR" /gen_snapshot \
174
+ ${ BUILD_DIR} / ${GEN_SNAPSHOT} \
136
175
${GEN_SNAPSHOT_FLAGS} \
137
176
" $GEN_SNAPSHOT_OPTION " \
138
177
" $GEN_SNAPSHOT_FILENAME " \
0 commit comments