if ab_match_arch loongarch64; then
    abinfo "Setting CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER for napi-rs ..."
    export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER=gcc

    abinfo "Overridding Electron mirror ..."
    export ELECTRON_MIRROR="https://github.com/darkyzhou/electron-loong64/releases/download/"
    export electron_use_remote_checksums=1

    abinfo "Updating rustlang/libc to the patched version ..."
    cd "$SRCDIR"/bitwarden/apps/desktop/desktop_native
    cargo update -p libc

    abinfo "Installing NPM dependencies ..."
    cd "$SRCDIR"/bitwarden
    npm install

    abinfo "Replace sass-embedded with sass ..."
    cd "$SRCDIR"/bitwarden
    npm install -D sass-embedded@npm:sass@latest
else
    abinfo "Installing NPM dependencies ..."
    cd "$SRCDIR"/bitwarden
    npm install
fi

abinfo "Building native module ..."
cd "$SRCDIR"/bitwarden/apps/desktop/desktop_native
node build.js --release

abinfo "Building Bitwarden Desktop ..."
cd "$SRCDIR"/bitwarden/apps/desktop
npm run dist:dir

abinfo "Installing Bitwarden ..."
install -dvm755 "$PKGDIR"/usr/lib/bitwarden
cp -rv "$SRCDIR"/bitwarden/apps/desktop/dist/linux*-unpacked/* "$PKGDIR"/usr/lib/bitwarden/

abinfo "Creating symbolic link ..."
mkdir -pv "$PKGDIR"/usr/bin
ln -sv ../lib/bitwarden/bitwarden "$PKGDIR"/usr/bin/bitwarden

abinfo "Installing application icon ..."
for i in 16 32 64 128 256 512 1024; do
    install -Dvm644 "$SRCDIR"/bitwarden/apps/desktop/resources/icons/${i}x${i}.png \
                    "$PKGDIR"/usr/share/icons/hicolor/${i}x${i}/apps/bitwarden.png
done
