Skip to content

Commit

Permalink
fcitx5-mozc: 2.26.4220.102 -> unstable-2023-08-18
Browse files Browse the repository at this point in the history
Migrate from the deprecated GYP build system to the new Bazel build
system.
  • Loading branch information
musjj committed Aug 27, 2023
1 parent b1eb33d commit 79e854f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 107 deletions.
210 changes: 108 additions & 102 deletions pkgs/tools/inputmethods/fcitx5/fcitx5-mozc.nix
Original file line number Diff line number Diff line change
@@ -1,128 +1,134 @@
{ lib, clangStdenv, fetchFromGitHub, fetchurl, fetchpatch
, python3Packages, ninja, pkg-config, protobuf, zinnia, qt5, fcitx5
, jsoncpp, gtest, which, gtk2, unzip, abseil-cpp, breakpad, nixosTests }:
let
inherit (python3Packages) python gyp six;
utdic = fetchurl {
url = "https://osdn.net/downloads/users/39/39056/mozcdic-ut-20220904.tar.bz2";
sha256 = "sha256-pmLBCcw2Zsirzl1PjYkviRIZoyfUz5rpESeABDxuhtU=";
};
japanese_usage_dictionary = fetchFromGitHub {
owner = "hiroyuki-komatsu";
repo = "japanese-usage-dictionary";
rev = "e5b3425575734c323e1d947009dd74709437b684";
sha256 = "0pyrpz9c8nxccwpgyr36w314mi8h132cis8ijvlqmmhqxwsi30hm";
};
zipcode_rel = "202011";
jigyosyo = fetchurl {
url = "https://osdn.net/projects/ponsfoot-aur/storage/mozc/jigyosyo-${zipcode_rel}.zip";
sha256 = "j7MkNtd4+QTi91EreVig4/OV0o5y1+KIjEJBEmLK/mY=";
};
x-ken-all = fetchurl {
url =
"https://osdn.net/projects/ponsfoot-aur/storage/mozc/x-ken-all-${zipcode_rel}.zip";
sha256 = "ExS0Cg3rs0I9IOVbZHLt8UEfk8/LmY9oAHPVVlYuTPw=";
};

in clangStdenv.mkDerivation {
{ bazel
, buildBazelPackage
, fcitx5
, fetchFromGitHub
, gettext
, lib
, mozc
, nixosTests
, pkg-config
, python3
, unzip
}:

buildBazelPackage {
pname = "fcitx5-mozc";
version = "2.26.4220.102";
version = "unstable-2023-08-18";

src = fetchFromGitHub {
srcs = fetchFromGitHub {
owner = "fcitx";
repo = "mozc";
rev = "1882e33b61673b66d63277f82b4c80ae4e506c10";
sha256 = "R+w0slVFpqtt7PIr1pyupJjRoQsABVZiMdZ9fKGKAqw=";
fetchSubmodules = true;
rev = "198608e08393dd26a81cd091e4916dfbc4196e5e";
hash = "sha256-6hTFCohmz+ijwWLQu65kKpiihs7XKqph3/JDwQjSHBw=";
};

nativeBuildInputs = [ gyp ninja python pkg-config qt5.wrapQtAppsHook six which unzip ];

buildInputs = [ protobuf zinnia qt5.qtbase fcitx5 abseil-cpp jsoncpp gtest gtk2 ];

patches = [
# Support linking system abseil-cpp
(fetchpatch {
url = "https://salsa.debian.org/debian/mozc/-/raw/debian/sid/debian/patches/0007-Update-src-base-absl.gyp.patch";
sha256 = "UiS0UScDKyAusXOhc7Bg8dF8ARQQiVTylEhAOxqaZt8=";
})
sourceRoot = "source/src";

nativeBuildInputs = [
gettext
pkg-config
python3
unzip
];

postUnpack = ''
unzip ${x-ken-all} -d $sourceRoot/src/
unzip ${jigyosyo} -d $sourceRoot/src/
mkdir $TMPDIR/unpack
tar xf ${utdic} -C $TMPDIR/unpack
cat $TMPDIR/unpack/mozcdic-ut-20220904/mozcdic-ut-20220904.txt >> $sourceRoot/src/data/dictionary_oss/dictionary00.txt
rmdir $sourceRoot/src/third_party/breakpad/
ln -s ${breakpad} $sourceRoot/src/third_party/breakpad
rmdir $sourceRoot/src/third_party/gtest/
ln -s ${gtest} $sourceRoot/src/third_party/gtest
rmdir $sourceRoot/src/third_party/gyp/
ln -s ${gyp} $sourceRoot/src/third_party/gyp
rmdir $sourceRoot/src/third_party/japanese_usage_dictionary/
ln -s ${japanese_usage_dictionary} $sourceRoot/src/third_party/japanese_usage_dictionary
'';

# Copied from https://github.com/archlinux/svntogit-community/blob/packages/fcitx5-mozc/trunk/PKGBUILD
configurePhase = ''
cd src
export GYP_DEFINES="document_dir=$out/share/doc/mozc use_libzinnia=1 use_libprotobuf=1 use_libabseil=1"
# disable fcitx4
rm unix/fcitx/fcitx.gyp
# gen zip code seed
PYTHONPATH="$PWD:$PYTHONPATH" python dictionary/gen_zip_code_seed.py --zip_code="x-ken-all.csv" --jigyosyo="JIGYOSYO.CSV" >> data/dictionary_oss/dictionary09.txt
# use libstdc++ instead of libc++
sed "/stdlib=libc++/d;/-lc++/d" -i gyp/common.gypi
buildInputs = [
mozc
fcitx5
];

# run gyp
python build_mozc.py gyp --gypdir=${gyp}/bin --server_dir=$out/lib/mozc
postPatch = ''
sed -i -e 's|^\(LINUX_MOZC_SERVER_DIR = \).\+|\1"${mozc}/lib/mozc"|' config.bzl
'';

buildPhase = ''
runHook preBuild
inherit bazel;
removeRulesCC = false;
dontAddBazelOpts = true;

python build_mozc.py build -c Release \
server/server.gyp:mozc_server \
gui/gui.gyp:mozc_tool \
unix/fcitx5/fcitx5.gyp:fcitx5-mozc
bazelFlags = [
"--config"
"oss_linux"
"--compilation_mode"
"opt"
];

runHook postBuild
'';
bazelTargets = [
"unix/fcitx5:fcitx5-mozc.so"
"unix/icons"
];

installPhase = ''
runHook preInstall
export PREFIX=$out
export _bldtype=Release
../scripts/install_server
install -d $out/share/licenses/fcitx5-mozc
head -n 29 server/mozc_server.cc > $out/share/licenses/fcitx5-mozc/LICENSE
install -m644 data/installer/*.html $out/share/licenses/fcitx5-mozc/
install -d $out/share/fcitx5/addon
install -d $out/share/fcitx5/inputmethod
install -d $out/lib/fcitx5
../scripts/install_fcitx5
runHook postInstall
'';
fetchAttrs = {
sha256 = "sha256-ENX0Z8+qSw2CBeuzL6qHWy19Dsij1x2n3W9nId4Ui5k=";
};

preFixup = ''
wrapQtApp $out/lib/mozc/mozc_tool
'';
buildAttrs = {
installPhase = ''
runHook preInstall
install -Dm644 ../LICENSE $out/share/licenses/fcitx5-mozc/LICENSE
install -Dm644 data/installer/credits_en.html $out/share/licenses/fcitx5-mozc/Submodules
install -Dm755 bazel-bin/unix/fcitx5/fcitx5-mozc.so $out/lib/fcitx5/fcitx5-mozc.so
install -Dm644 unix/fcitx5/mozc-addon.conf $out/share/fcitx5/addon/mozc.conf
install -Dm644 unix/fcitx5/mozc.conf $out/share/fcitx5/inputmethod/mozc.conf
for pofile in unix/fcitx5/po/*.po; do
filename=$(basename $pofile)
lang=''${filename/.po/}
mofile=''${pofile/.po/.mo}
msgfmt $pofile -o $mofile
install -Dm644 $mofile $out/share/locale/$lang/LC_MESSAGES/fcitx5-mozc.mo
done
msgfmt --xml -d unix/fcitx5/po/ --template unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml.in -o unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml
install -Dm644 unix/fcitx5/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml $out/share/metainfo/org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml
cd bazel-bin/unix
unzip -o icons.zip
install -Dm644 mozc.png $out/share/icons/hicolor/128x128/apps/org.fcitx.Fcitx5.fcitx-mozc.png
install -Dm644 alpha_full.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-alpha-full.svg
install -Dm644 alpha_half.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-alpha-half.svg
install -Dm644 direct.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-direct.svg
install -Dm644 hiragana.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-hiragana.svg
install -Dm644 katakana_full.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-katakana-full.svg
install -Dm644 katakana_half.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-katakana-half.svg
install -Dm644 outlined/dictionary.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-dictionary.svg
install -Dm644 outlined/properties.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-properties.svg
install -Dm644 outlined/tool.svg $out/share/icons/hicolor/scalable/apps/org.fcitx.Fcitx5.fcitx-mozc-tool.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc.png $out/share/icons/hicolor/128x128/apps/fcitx-mozc.png
ln -s org.fcitx.Fcitx5.fcitx-mozc-alpha-full.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-alpha-full.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-alpha-half.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-alpha-half.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-direct.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-direct.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-hiragana.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-hiragana.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-katakana-full.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-katakana-full.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-katakana-half.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-katakana-half.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-dictionary.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-dictionary.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-properties.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-properties.svg
ln -s org.fcitx.Fcitx5.fcitx-mozc-tool.svg $out/share/icons/hicolor/scalable/apps/fcitx-mozc-tool.svg
runHook postInstall
'';
};

passthru.tests = {
inherit (nixosTests) fcitx5;
};

meta = with lib; {
description = "Fcitx5 Module of A Japanese Input Method for Chromium OS, Windows, Mac and Linux (the Open Source Edition of Google Japanese Input)";
description = "Mozc - a Japanese Input Method Editor designed for multi-platform";
homepage = "https://github.com/fcitx/mozc";
license = licenses.bsd3;
license = with licenses; [
asl20
bsd2
bsd3
ipa
mit
mspl
publicDomain
];
maintainers = with maintainers; [ berberman govanify ];
platforms = platforms.linux;
};
Expand Down
6 changes: 1 addition & 5 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7994,11 +7994,7 @@ with pkgs;

fcitx5-chinese-addons = libsForQt5.callPackage ../tools/inputmethods/fcitx5/fcitx5-chinese-addons.nix { };

fcitx5-mozc = libsForQt5.callPackage ../tools/inputmethods/fcitx5/fcitx5-mozc.nix {
abseil-cpp = abseil-cpp.override {
cxxStandard = "17";
};
};
fcitx5-mozc = callPackage ../tools/inputmethods/fcitx5/fcitx5-mozc.nix { };

fcitx5-skk = libsForQt5.callPackage ../tools/inputmethods/fcitx5/fcitx5-skk.nix { };

Expand Down

0 comments on commit 79e854f

Please sign in to comment.