Skip to content

Commit d4871a3

Browse files
authored
Run native ST build on arm64 host when using docker (#298)
This commit installs ST builds matching host's architecture by default. Docker by default starts native docker image (on arm64 system it runs arm64 linux image) but the install_sublime_text script always installed x64 ST build which either ran very slowly or completely failed (for example latest ubuntu fails on mac arm when running under Rosetta).
1 parent 1b8a161 commit d4871a3

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎docker/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ docker run --rm -it \
154154
-v unittesting-home:/root \
155155
unittesting-local run_tests --tests-dir tests --pattern test_example.py
156156
```
157+
158+
## ARM hosts (Apple Silicon, arm64 Linux)
159+
160+
On an ARM host, the launcher builds and runs a native arm64 image. The
161+
container installs the arm64 build of Sublime Text 4.
162+
163+
Runs under amd64 emulation (for example `DOCKER_DEFAULT_PLATFORM=linux/amd64`)
164+
are not supported.

‎docker/entrypoint.sh‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
echo PACKAGE = $PACKAGE
4+
echo ARCHITECTURE = $(uname -m)
45

56
set -e
67

@@ -84,6 +85,37 @@ write_package_dependency_marker() {
8485
printf '%s\n' "$dependency_fingerprint" > "$DEPENDENCY_MARKER_DIR/$PACKAGE.sha256"
8586
}
8687

88+
ensure_sublime_text_arch_matches() {
89+
# A cache volume created on a different architecture holds a Sublime Text
90+
# binary that cannot run here, and the bootstrap marker skips reinstall.
91+
local binary="$HOME/sublime_text/sublime_text"
92+
[ -f "$binary" ] || return 0
93+
94+
local expected
95+
case "$(uname -m)" in
96+
x86_64) expected=3e ;;
97+
aarch64) expected=b7 ;;
98+
*) return 0 ;;
99+
esac
100+
101+
# e_machine field of the ELF header (low byte, little-endian).
102+
local actual
103+
actual=$(od -An -tx1 -j18 -N1 "$binary" | tr -d ' \n')
104+
if [ "$actual" != "$expected" ]; then
105+
local found
106+
case "$actual" in
107+
3e) found=x86_64 ;;
108+
b7) found=aarch64 ;;
109+
*) found="unknown (ELF machine 0x$actual)" ;;
110+
esac
111+
echo "Error: the cache volume has a Sublime Text build for $found," >&2
112+
echo "but this container runs on $(uname -m)." >&2
113+
echo "Run ut-run-tests with --refresh-cache, or use a different cache volume." >&2
114+
exit 1
115+
fi
116+
}
117+
118+
ensure_sublime_text_arch_matches
87119
sudo sh -e /etc/init.d/xvfb start
88120
ensure_git_identity
89121
ensure_ci_platform_compat

‎docker/ut-run-tests‎

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
set -euo pipefail
33

44
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
5-
exec python "$SCRIPT_DIR/run_tests.py" "$@"
5+
PYTHON="$(command -v python3 || command -v python)"
6+
exec "$PYTHON" "$SCRIPT_DIR/run_tests.py" "$@"

‎sbin/install_sublime_text.sh‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ if [ -z $SUBLIME_TEXT_VERSION ]; then
2828
fi
2929

3030
if [ -z $SUBLIME_TEXT_ARCH ]; then
31-
SUBLIME_TEXT_ARCH=x64
31+
case "$(uname -m)" in
32+
aarch64|arm64) SUBLIME_TEXT_ARCH=arm64 ;;
33+
*) SUBLIME_TEXT_ARCH=x64 ;;
34+
esac
3235
fi
3336

34-
if [ $SUBLIME_TEXT_VERSION -ge 4 ] && [ "$SUBLIME_TEXT_ARCH" != "x64" ]; then
37+
if [ $SUBLIME_TEXT_VERSION -ge 4 ] && [ "$SUBLIME_TEXT_ARCH" != "x64" ] && [ "$SUBLIME_TEXT_ARCH" != "arm64" ]; then
3538
echo "wrong value of $SUBLIME_TEXT_ARCH for Sublime Text version $SUBLIME_TEXT_VERSION"
3639
exit 1
3740
fi
@@ -132,7 +135,7 @@ else
132135
echo "installing sublime text $SUBLIME_TEXT_VERSION"
133136
for i in {1..20}; do
134137
if [ $SUBLIME_TEXT_VERSION -ge 4 ]; then
135-
URL=$(curl -s "$STWEB" | sed -n 's/.*href="\([^"]*_x64\.tar\.xz\)".*/\1/p')
138+
URL=$(curl -s "$STWEB" | sed -n "s/.*href=\"\([^\"]*_${SUBLIME_TEXT_ARCH}\.tar\.xz\)\".*/\1/p")
136139
else
137140
if [ "$SUBLIME_TEXT_ARCH" = "x64" ]; then
138141
URL=$(curl -s "$STWEB" | sed -n 's/.*href="\([^"]*x64\.tar\.bz2\)".*/\1/p')

0 commit comments

Comments
 (0)