Skip to content

Commit de4e234

Browse files
committed
Build watchman from source on ARM64, and add support for custom download URLs for both source and archive installs.
1 parent 662b0a0 commit de4e234

1 file changed

Lines changed: 91 additions & 3 deletions

File tree

.devcontainer/install-watchman.sh

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,117 @@
33
set -eu
44

55
WATCHMAN_VERSION="${WATCHMAN_VERSION:-v2026.05.04.00}"
6-
DOWNLOAD_URL="${WATCHMAN_DOWNLOAD_URL:-https://github.com/facebook/watchman/releases/download/${WATCHMAN_VERSION}/watchman-${WATCHMAN_VERSION}-linux.zip}"
6+
ARCH="$(uname -m)"
7+
SOURCE_URL="${WATCHMAN_SOURCE_URL:-https://github.com/facebook/watchman/archive/refs/tags/${WATCHMAN_VERSION}.tar.gz}"
8+
9+
if [ -n "${WATCHMAN_DOWNLOAD_URL:-}" ]; then
10+
INSTALL_METHOD="archive"
11+
DOWNLOAD_URL="$WATCHMAN_DOWNLOAD_URL"
12+
else
13+
case "$ARCH" in
14+
x86_64|amd64)
15+
INSTALL_METHOD="archive"
16+
DOWNLOAD_URL="https://github.com/facebook/watchman/releases/download/${WATCHMAN_VERSION}/watchman-${WATCHMAN_VERSION}-linux.zip"
17+
;;
18+
aarch64|arm64)
19+
INSTALL_METHOD="source"
20+
;;
21+
*)
22+
echo "Error: unsupported architecture ${ARCH}."
23+
echo "Set WATCHMAN_DOWNLOAD_URL to a compatible archive if you need Watchman in this container."
24+
exit 1
25+
;;
26+
esac
27+
fi
28+
729
TMPDIR=$(mktemp -d)
830
ARCHIVE_PATH="$TMPDIR/watchman.zip"
9-
EXTRACT_DIR="$TMPDIR/watchman-${WATCHMAN_VERSION}-linux"
31+
SOURCE_ARCHIVE_PATH="$TMPDIR/watchman.tar.gz"
1032

1133
cleanup() {
1234
rm -rf "$TMPDIR"
1335
}
1436

1537
trap cleanup EXIT
1638

39+
setup_runtime_dir() {
40+
install -d /usr/local/var/run/watchman
41+
chmod 2777 /usr/local/var/run/watchman
42+
}
43+
44+
if [ "$INSTALL_METHOD" = "source" ]; then
45+
echo "Building Watchman ${WATCHMAN_VERSION} from source for ${ARCH}"
46+
apt-get update
47+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
48+
bash \
49+
ca-certificates \
50+
cargo \
51+
git \
52+
python3 \
53+
python3-pip
54+
55+
if ! command -v pip >/dev/null 2>&1 && command -v pip3 >/dev/null 2>&1; then
56+
ln -s "$(command -v pip3)" /usr/local/bin/pip
57+
fi
58+
59+
curl -fsSL "$SOURCE_URL" -o "$SOURCE_ARCHIVE_PATH"
60+
tar -xzf "$SOURCE_ARCHIVE_PATH" -C "$TMPDIR"
61+
62+
SOURCE_DIR="$(find "$TMPDIR" -mindepth 1 -maxdepth 1 -type d -name 'watchman-*' | head -n 1 || true)"
63+
64+
if [ -z "$SOURCE_DIR" ]; then
65+
echo "Error: Watchman source archive did not contain the expected directory"
66+
exit 1
67+
fi
68+
69+
cd "$SOURCE_DIR"
70+
PIP_BREAK_SYSTEM_PACKAGES=1 python3 build/fbcode_builder/getdeps.py --allow-system-packages install-system-deps --recursive watchman
71+
PREFIX=/usr/local ./autogen.sh
72+
73+
if [ ! -x built/bin/watchman ] || [ ! -x built/bin/watchmanctl ]; then
74+
echo "Error: Watchman source build did not produce the expected binaries"
75+
exit 1
76+
fi
77+
78+
install -d /usr/local/bin
79+
install built/bin/watchman /usr/local/bin/watchman
80+
install built/bin/watchmanctl /usr/local/bin/watchmanctl
81+
setup_runtime_dir
82+
83+
if [ -d built/lib ] && find built/lib -mindepth 1 -maxdepth 1 | read -r _; then
84+
install -d /usr/local/lib
85+
cp -a built/lib/. /usr/local/lib/
86+
fi
87+
88+
if command -v ldconfig >/dev/null 2>&1; then
89+
ldconfig
90+
fi
91+
92+
exit 0
93+
fi
94+
1795
echo "Downloading Watchman from: $DOWNLOAD_URL"
1896
curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE_PATH"
1997
unzip -q "$ARCHIVE_PATH" -d "$TMPDIR"
2098

21-
if [ ! -x "$EXTRACT_DIR/bin/watchman" ]; then
99+
WATCHMAN_BIN="$(find "$TMPDIR" -path '*/bin/watchman' -type f | head -n 1 || true)"
100+
101+
if [ -z "$WATCHMAN_BIN" ]; then
102+
echo "Error: Watchman archive did not contain the expected binaries"
103+
exit 1
104+
fi
105+
106+
EXTRACT_DIR="${WATCHMAN_BIN%/bin/watchman}"
107+
108+
if [ ! -x "$EXTRACT_DIR/bin/watchman" ] || [ ! -x "$EXTRACT_DIR/bin/watchmanctl" ]; then
22109
echo "Error: Watchman archive did not contain the expected binaries"
23110
exit 1
24111
fi
25112

26113
install -d /usr/local/bin /usr/local/lib
27114
install "$EXTRACT_DIR/bin/watchman" /usr/local/bin/watchman
28115
install "$EXTRACT_DIR/bin/watchmanctl" /usr/local/bin/watchmanctl
116+
setup_runtime_dir
29117
cp -a "$EXTRACT_DIR/lib/." /usr/local/lib/
30118

31119
if command -v ldconfig >/dev/null 2>&1; then

0 commit comments

Comments
 (0)