Files
fcitx5-m3ui/scripts/build.sh
T
justmeandClaude Sonnet 5.5 9cb4134203 Build from commits that are checked, and refuse unsafe paths
The plugin runs inside the input method and sees everything that is typed, so
what it is built from matters. build.sh used to download a tag archive and a
yoga archive without checking them. It now fetches both by commit hash and
verifies the hash afterwards: a tag can be moved and an archive swapped, a
commit hash cannot be faked. A version without a pinned commit is refused
unless FCITX_COMMIT is given. Archive checksums were not used on purpose, GitHub
does not keep the bytes of generated archives stable.

enable-autostart.sh writes paths into an Exec line and a service file and now
refuses paths that would need quoting there.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-19 23:36:54 +08:00

72 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# Builds libm3ui.so against an upstream Fcitx5 source tree of the same version
# as the Fcitx5 installed on this system. The addon needs Fcitx5's internal
# Wayland protocol wrappers, which are not part of fcitx5-devel, so it is built
# inside the upstream tree.
set -euo pipefail
root=$(cd "$(dirname "$0")/.." && pwd)
work=${WORK_DIR:-$root/build}
version=${FCITX_VERSION:-$(pkg-config --modversion Fcitx5Core)}
die() { echo "build.sh: $*" >&2; exit 1; }
command -v git >/dev/null || die "git is needed to fetch the sources"
# The sources are fetched by commit hash and the hash is checked afterwards. A
# tag can be moved and a downloaded archive can be swapped, a commit hash cannot
# be faked, Git verifies the content against it. This plugin runs inside the
# input method and sees everything that is typed, so what it is built from
# matters.
#
# Commit the Fcitx5 release tag points to, check it yourself when adding one:
# git ls-remote https://github.com/fcitx/fcitx5 "refs/tags/<version>^{}"
declare -A known_commits=(
["5.1.23"]="27cca6e0239938b2d53937061d0980c087856b22"
)
commit=${FCITX_COMMIT:-${known_commits[$version]:-}}
[ -n "$commit" ] || die "no pinned commit for Fcitx5 $version. Look up the commit of its tag and pass it as FCITX_COMMIT=<sha>"
# Commit of the yoga submodule pinned by Fcitx5 (third_party/yoga).
yoga_commit=${YOGA_COMMIT:-042f5013152eb81c1552dec945b88f7b95ca350f}
# fetch_commit <url> <dir> <commit>, leaves <dir> checked out at exactly <commit>
fetch_commit() {
local url=$1 dir=$2 want=$3
if [ -d "$dir/.git" ] && [ "$(git -C "$dir" rev-parse HEAD 2>/dev/null)" = "$want" ]; then
return 0
fi
rm -rf "$dir"
mkdir -p "$dir"
git -C "$dir" init -q
git -C "$dir" fetch -q --depth 1 "$url" "$want" || die "could not fetch $want from $url"
git -C "$dir" checkout -q FETCH_HEAD
[ "$(git -C "$dir" rev-parse HEAD)" = "$want" ] || die "$url gave a different commit than $want"
}
srcdir=$work/fcitx5-$version
mkdir -p "$work"
echo ">> fetching Fcitx5 $version ($commit)"
fetch_commit https://github.com/fcitx/fcitx5 "$srcdir" "$commit"
echo ">> fetching yoga ($yoga_commit)"
fetch_commit https://github.com/facebook/yoga "$srcdir/third_party/yoga" "$yoga_commit"
[ -z "${FETCH_ONLY:-}" ] || { echo ">> sources are in place"; exit 0; }
echo ">> overlaying m3ui"
rm -rf "$srcdir/src/ui/m3ui"
cp -r "$root/src" "$srcdir/src/ui/m3ui"
if ! grep -q 'add_subdirectory(m3ui)' "$srcdir/src/ui/CMakeLists.txt"; then
sed -i 's/^add_subdirectory(classic)$/add_subdirectory(classic)\nadd_subdirectory(m3ui)/' \
"$srcdir/src/ui/CMakeLists.txt"
fi
echo ">> configuring"
cmake -S "$srcdir" -B "$work/cmake" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${PREFIX:-$HOME/.local/m3ui}" \
-DENABLE_X11=On -DENABLE_WAYLAND=On \
-DENABLE_TEST=Off -DENABLE_TESTING_ADDONS=Off -DENABLE_ENCHANT=Off \
-DENABLE_DOC=Off -DENABLE_XDGAUTOSTART=Off -DENABLE_EMOJI=Off
echo ">> building"
ninja -C "$work/cmake" m3ui src/ui/m3ui/m3ui.conf
echo ">> done, run scripts/install.sh"