File karukan.spec of Package karukan

#
# spec file for package karukan
#
# Copyright (c) 2026 Gakuto Furuya <g.furuya@gaato.net>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

Name:           karukan
Version:        0.1.0
Release:        0
Summary:        Japanese input method for Fcitx5 powered by neural kana-kanji conversion
Summary(ja):    ニューラルかな漢字変換を搭載した Fcitx5 用日本語入力メソッド
License:        MIT OR Apache-2.0
Group:          System/I18n/Japanese
URL:            https://github.com/togatoga/karukan
Source0:        karukan-%{version}.tar.gz
Source1:        vendor.tar.zst
# Skip cargo build in CMake -- already built in %%build via cargo
Patch0:         fcitx5-karukan-skip-cargo-build.patch
# Make karukan-server serve packaged static files from %%{_datadir}
Patch1:         karukan-server-static-path.patch
# KDE icon theme engine strips hyphens on fallback; use underscores
Patch2:         fcitx5-karukan-icon-underscore.patch

# Rust toolchain — openSUSE supports "or" syntax for fallback to rust-bin;
# other distros (Fedora, etc.) just require system rust/cargo directly.
%if 0%{?suse_version}
BuildRequires:  (rust >= 1.92 or rust-bin >= 1.92)
BuildRequires:  (cargo >= 1.92 or rust-bin >= 1.92)
%else
BuildRequires:  rust >= 1.92
BuildRequires:  cargo >= 1.92
%endif
BuildRequires:  gcc-c++
BuildRequires:  cmake >= 3.16
BuildRequires:  make
BuildRequires:  clang-devel
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(xkbcommon)
BuildRequires:  extra-cmake-modules
BuildRequires:  fcitx5-devel
BuildRequires:  cmake(Fcitx5Core) >= 5.0
BuildRequires:  zstd

Requires:       fcitx5
%if 0%{?suse_version}
Supplements:    (fcitx5 and bundle-lang-ja)
%endif

%description
Karukan is a Japanese Input Method Engine for Linux that uses neural
kana-kanji conversion powered by llama.cpp. It provides a fcitx5 addon
for romaji-to-hiragana conversion and intelligent kana-kanji conversion
using small neural network models (auto-downloaded on first use).

Features:
- Romaji-to-hiragana conversion with 200+ rules
- Neural kana-kanji conversion via llama.cpp (GGUF models)
- Adaptive model selection for low-latency input
- Learning cache for user conversion history
- System dictionary with double-array trie

%prep
%autosetup -p1 -n karukan-%{version} -a1

%build
# Workaround: llama-cpp-sys-2 build.rs requires CARGO_CFG_TARGET_FEATURE
# which is unset on some architectures (ppc64le, armv7l, etc.)
export CARGO_CFG_TARGET_FEATURE="${CARGO_CFG_TARGET_FEATURE:-}"

# Build the Rust shared library and CLI tools (vendored, offline)
export CARGO_HOME="$PWD/.cargo_home"
cargo build --release -p karukan-im -p karukan-cli --offline

# Build the fcitx5 C++ addon
pushd karukan-im/fcitx5-addon
%cmake
%cmake_build
popd

%install
# Install the fcitx5 C++ addon via cmake
pushd karukan-im/fcitx5-addon
%cmake_install
popd

# CLI tools
install -Dm755 target/release/karukan-dict %{buildroot}%{_bindir}/karukan-dict
install -Dm755 target/release/karukan-server %{buildroot}%{_bindir}/karukan-server
install -Dm755 target/release/sudachi-dict %{buildroot}%{_bindir}/sudachi-dict
install -Dm755 target/release/ajimee-bench %{buildroot}%{_bindir}/ajimee-bench

# Server static assets (served by karukan-server at runtime)
install -d %{buildroot}%{_datadir}/karukan/static
install -Dm644 karukan-cli/static/index.html %{buildroot}%{_datadir}/karukan/static/index.html
install -Dm644 karukan-cli/static/app.js %{buildroot}%{_datadir}/karukan/static/app.js
install -Dm644 karukan-cli/static/styles.css %{buildroot}%{_datadir}/karukan/static/styles.css

# Flatpak-style icon symlinks required by fcitx5 system tray
for size in 16 24 32 48 128; do
    ln -s fcitx_karukan.png \
        %{buildroot}%{_datadir}/icons/hicolor/${size}x${size}/apps/org.fcitx.Fcitx5.fcitx_karukan.png
done

# Default config and user dictionary
install -Dm644 karukan-im/config/default.toml \
    %{buildroot}%{_datadir}/fcitx5/karukan/default.toml
install -Dm644 karukan-im/config/default_user_dict.txt \
    %{buildroot}%{_datadir}/fcitx5/karukan/default_user_dict.txt

%check
export CARGO_CFG_TARGET_FEATURE="${CARGO_CFG_TARGET_FEATURE:-}"
export CARGO_HOME="$PWD/.cargo_home"
# Skip tests that require downloading models from Hugging Face (no network in OBS)
cargo test -p karukan-engine --lib --offline -- --skip kanji::backend::tests
cargo test -p karukan-engine --test romaji_tests --offline -- --skip test_zenninn_kanji_conversion
cargo test -p karukan-im --lib --offline

%files
%license LICENSE-MIT LICENSE-APACHE
%doc README.md
%{_bindir}/karukan-dict
%{_bindir}/karukan-server
%{_bindir}/sudachi-dict
%{_bindir}/ajimee-bench
%{_libdir}/fcitx5/karukan.so
%{_libdir}/fcitx5/libkarukan_im.so
%{_datadir}/fcitx5/addon/karukan.conf
%{_datadir}/fcitx5/inputmethod/karukan.conf
%{_datadir}/fcitx5/karukan/
%{_datadir}/metainfo/org.fcitx.Fcitx5.Addon.Karukan.metainfo.xml
%{_datadir}/icons/hicolor/16x16/apps/fcitx_karukan.png
%{_datadir}/icons/hicolor/24x24/apps/fcitx_karukan.png
%{_datadir}/icons/hicolor/32x32/apps/fcitx_karukan.png
%{_datadir}/icons/hicolor/48x48/apps/fcitx_karukan.png
%{_datadir}/icons/hicolor/128x128/apps/fcitx_karukan.png
%{_datadir}/icons/hicolor/16x16/apps/org.fcitx.Fcitx5.fcitx_karukan.png
%{_datadir}/icons/hicolor/24x24/apps/org.fcitx.Fcitx5.fcitx_karukan.png
%{_datadir}/icons/hicolor/32x32/apps/org.fcitx.Fcitx5.fcitx_karukan.png
%{_datadir}/icons/hicolor/48x48/apps/org.fcitx.Fcitx5.fcitx_karukan.png
%{_datadir}/icons/hicolor/128x128/apps/org.fcitx.Fcitx5.fcitx_karukan.png
%{_datadir}/karukan/

%changelog
openSUSE Build Service is sponsored by