Skip to content

Instantly share code, notes, and snippets.

@hjanuschka
Created March 12, 2026 08:07
Show Gist options
  • Select an option

  • Save hjanuschka/ed780aaff7fe8824e97c9d73205bbe12 to your computer and use it in GitHub Desktop.

Select an option

Save hjanuschka/ed780aaff7fe8824e97c9d73205bbe12 to your computer and use it in GitHub Desktop.
Script to switch Chromium between vendored and local jxl-rs checkout (symlinks, bisect, override)
#!/bin/bash
# Switch Chromium to use local jxl-rs checkout for development
# Usage: ./use-local-jxl-rs.sh [setup|restore|status|clean|bisect|override]
set -e
CHROMIUM_SRC="/home/chrome/chromium_2/src"
CHROMIUM_VENDOR="$CHROMIUM_SRC/third_party/rust/chromium_crates_io/vendor"
LOCAL_JXL="$HOME/jxl-rs_1"
BUILD_GN="$CHROMIUM_SRC/third_party/rust/jxl/v0_3/BUILD.gn"
CRATES=(
"jxl-v0_3:jxl"
"jxl_macros-v0_3:jxl_macros"
"jxl_simd-v0_3:jxl_simd"
"jxl_transforms-v0_3:jxl_transforms"
)
clean_build_cache() {
echo "Cleaning jxl build artifacts..."
rm -rf "$CHROMIUM_SRC/out/Default/obj/third_party/rust/jxl"* 2>/dev/null || true
rm -rf "$CHROMIUM_SRC/out/Default/clang_x64_for_rust_host_build_tools/libjxl"* 2>/dev/null || true
echo " Build cache cleaned."
}
regen_ninja() {
echo "Regenerating ninja files..."
cd "$CHROMIUM_SRC" && gn gen out/Default
echo " Ninja files regenerated."
}
fix_build_gn() {
echo "Syncing BUILD.gn with current jxl-rs checkout..."
# Handle premultiply_alpha.rs - added in d04806e
if [ -f "$LOCAL_JXL/jxl/src/render/stages/premultiply_alpha.rs" ]; then
if ! grep -q "premultiply_alpha.rs" "$BUILD_GN" 2>/dev/null; then
echo " Adding premultiply_alpha.rs to BUILD.gn..."
sed -i '/stages\/patches\.rs/a\ "//third_party/rust/chromium_crates_io/vendor/jxl-v0_3/src/render/stages/premultiply_alpha.rs",' "$BUILD_GN"
fi
else
if grep -q "premultiply_alpha.rs" "$BUILD_GN" 2>/dev/null; then
echo " Removing premultiply_alpha.rs from BUILD.gn..."
sed -i '/premultiply_alpha\.rs/d' "$BUILD_GN"
fi
fi
# Handle x86_64.rs - deleted in fa0211d
if [ -f "$LOCAL_JXL/jxl/src/render/low_memory_pipeline/save/x86_64.rs" ]; then
if ! grep -q "save/x86_64.rs" "$BUILD_GN" 2>/dev/null; then
echo " Adding save/x86_64.rs to BUILD.gn..."
sed -i '/save\/mod\.rs/a\ "//third_party/rust/chromium_crates_io/vendor/jxl-v0_3/src/render/low_memory_pipeline/save/x86_64.rs",' "$BUILD_GN"
fi
else
if grep -q "save/x86_64.rs" "$BUILD_GN" 2>/dev/null; then
echo " Removing save/x86_64.rs from BUILD.gn..."
sed -i '/save\/x86_64\.rs/d' "$BUILD_GN"
fi
fi
# Handle atomic_refcell - added in eaf6923
if [ -f "$LOCAL_JXL/jxl/src/util/atomic_refcell/mod.rs" ]; then
if ! grep -q "atomic_refcell" "$BUILD_GN" 2>/dev/null; then
echo " Adding atomic_refcell to BUILD.gn..."
sed -i '/util\/vec_helpers\.rs/a\ "//third_party/rust/chromium_crates_io/vendor/jxl-v0_3/src/util/atomic_refcell/mod.rs",\n "//third_party/rust/chromium_crates_io/vendor/jxl-v0_3/src/util/atomic_refcell/internal.rs",' "$BUILD_GN"
fi
else
if grep -q "atomic_refcell" "$BUILD_GN" 2>/dev/null; then
echo " Removing atomic_refcell from BUILD.gn..."
sed -i '/atomic_refcell/d' "$BUILD_GN"
fi
fi
# Handle smallvec.rs - added in 99e245a
if [ -f "$LOCAL_JXL/jxl/src/util/smallvec.rs" ]; then
if ! grep -q "util/smallvec.rs" "$BUILD_GN" 2>/dev/null; then
echo " Adding smallvec.rs to BUILD.gn..."
sed -i '/util\/vec_helpers\.rs/a\ "//third_party/rust/chromium_crates_io/vendor/jxl-v0_3/src/util/smallvec.rs",' "$BUILD_GN"
fi
else
if grep -q "util/smallvec.rs" "$BUILD_GN" 2>/dev/null; then
echo " Removing smallvec.rs from BUILD.gn..."
sed -i '/util\/smallvec\.rs/d' "$BUILD_GN"
fi
fi
echo " BUILD.gn synced."
}
setup() {
echo "Setting up local jxl-rs symlinks..."
if [ ! -d "$LOCAL_JXL" ]; then
echo "ERROR: Local jxl-rs not found at $LOCAL_JXL"
exit 1
fi
cd "$CHROMIUM_VENDOR"
for entry in "${CRATES[@]}"; do
chromium_name="${entry%%:*}"
local_name="${entry##*:}"
if [ -L "$chromium_name" ]; then
echo " $chromium_name is already a symlink, skipping backup"
elif [ -d "$chromium_name" ]; then
echo " Backing up $chromium_name -> $chromium_name.bak"
mv "$chromium_name" "$chromium_name.bak"
fi
if [ ! -L "$chromium_name" ]; then
echo " Symlinking $LOCAL_JXL/$local_name -> $chromium_name"
ln -s "$LOCAL_JXL/$local_name" "$chromium_name"
fi
done
# Clean build cache to avoid stale proc_macro issues
clean_build_cache
# Fix BUILD.gn for upstream compatibility
fix_build_gn
# Regenerate ninja files for the new symlinks
regen_ninja
echo ""
echo "Done! Local jxl-rs is now active."
echo "Build with: autoninja -C out/Default blink_platform_unittests"
echo "Test with: out/Default/blink_platform_unittests --gtest_filter='*JXL*'"
}
restore() {
echo "Restoring original vendored jxl-rs..."
cd "$CHROMIUM_VENDOR"
for entry in "${CRATES[@]}"; do
chromium_name="${entry%%:*}"
if [ -L "$chromium_name" ]; then
echo " Removing symlink $chromium_name"
rm "$chromium_name"
fi
if [ -d "$chromium_name.bak" ]; then
echo " Restoring $chromium_name.bak -> $chromium_name"
mv "$chromium_name.bak" "$chromium_name"
fi
done
# Clean build cache
clean_build_cache
# Regenerate ninja files
regen_ninja
echo ""
echo "Done! Original vendored jxl-rs restored."
}
status() {
echo "Current status:"
cd "$CHROMIUM_VENDOR"
for entry in "${CRATES[@]}"; do
chromium_name="${entry%%:*}"
if [ -L "$chromium_name" ]; then
target=$(readlink "$chromium_name")
echo " $chromium_name -> $target (LOCAL)"
elif [ -d "$chromium_name" ]; then
echo " $chromium_name (vendored)"
else
echo " $chromium_name (MISSING!)"
fi
done
echo ""
if [ -L "$CHROMIUM_VENDOR/jxl-v0_3" ]; then
echo "Local jxl-rs branch:"
cd "$LOCAL_JXL" && git branch --show-current && git log --oneline -1
fi
}
clean() {
clean_build_cache
echo "Done!"
}
bisect() {
local commit="$1"
if [ -z "$commit" ]; then
echo "Usage: $0 bisect <commit>"
echo ""
echo "Switches local jxl-rs to the specified commit and rebuilds."
echo "After testing, mark as good/bad:"
echo " cd ~/jxl-rs && git bisect good"
echo " cd ~/jxl-rs && git bisect bad"
echo "Then run: $0 bisect \$(cd ~/jxl-rs && git rev-parse HEAD)"
exit 1
fi
echo "Switching to commit: $commit"
cd "$LOCAL_JXL" && git checkout "$commit"
echo ""
echo "Current commit:"
cd "$LOCAL_JXL" && git log --oneline -1
# Clean and sync
clean_build_cache
fix_build_gn
regen_ninja
echo ""
echo "Ready to build and test!"
echo "After testing, run:"
echo " cd ~/jxl-rs && git bisect good # if no bug"
echo " cd ~/jxl-rs && git bisect bad # if bug present"
echo "Then: ~/use-local-jxl-rs.sh bisect \$(cd ~/jxl-rs && git rev-parse HEAD)"
}
override() {
echo "Copying local jxl-rs to vendor directory (for committing to Chromium)..."
if [ ! -d "$LOCAL_JXL" ]; then
echo "ERROR: Local jxl-rs not found at $LOCAL_JXL"
exit 1
fi
cd "$CHROMIUM_VENDOR"
for entry in "${CRATES[@]}"; do
chromium_name="${entry%%:*}"
local_name="${entry##*:}"
# Remove existing symlink or directory
if [ -L "$chromium_name" ]; then
echo " Removing symlink $chromium_name"
rm "$chromium_name"
elif [ -d "$chromium_name" ]; then
echo " Removing existing $chromium_name"
rm -rf "$chromium_name"
fi
# Copy from local jxl-rs
echo " Copying $LOCAL_JXL/$local_name -> $chromium_name"
cp -r "$LOCAL_JXL/$local_name" "$chromium_name"
# Remove .git directory if copied
rm -rf "$chromium_name/.git" 2>/dev/null || true
done
# Clean build cache
clean_build_cache
# Fix BUILD.gn for upstream compatibility
fix_build_gn
# Regenerate ninja files
regen_ninja
echo ""
echo "Done! Local jxl-rs copied to vendor directory."
echo "Files are now ready to be committed to Chromium."
echo ""
echo "From ~/jxl-rs:"
cd "$LOCAL_JXL" && git log --oneline -1
}
case "${1:-status}" in
setup)
setup
;;
restore)
restore
;;
status)
status
;;
clean)
clean
;;
bisect)
bisect "$2"
;;
override)
override
;;
*)
echo "Usage: $0 [setup|restore|status|clean|bisect <commit>|override]"
echo ""
echo " setup - Switch to local jxl-rs at ~/jxl-rs (symlinks)"
echo " restore - Restore original vendored jxl-rs"
echo " status - Show current state (default)"
echo " clean - Clean jxl build artifacts"
echo " bisect <commit> - Switch to specific commit and sync BUILD.gn"
echo " override - Copy local jxl-rs to vendor (for committing)"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment