[geary/mjog/search-update: 8/9] build: Add minimal ICU VAPI for UBreakIterator




commit beb162c6fd11151ab76c43967c3108ca6065c0c4
Author: Michael Gratton <mike vee net>
Date:   Mon Jan 18 22:16:24 2021 +1100

    build: Add minimal ICU VAPI for UBreakIterator

 bindings/vapi/icu-uc.vapi | 95 +++++++++++++++++++++++++++++++++++++++++++++++
 meson.build               | 16 ++++----
 src/client/meson.build    |  1 +
 src/engine/meson.build    |  4 +-
 src/meson.build           |  1 +
 5 files changed, 106 insertions(+), 11 deletions(-)
---
diff --git a/bindings/vapi/icu-uc.vapi b/bindings/vapi/icu-uc.vapi
new file mode 100644
index 000000000..b470faff1
--- /dev/null
+++ b/bindings/vapi/icu-uc.vapi
@@ -0,0 +1,95 @@
+// Based on icu-uc.vapi from the Dino project.
+
+[CCode (cprefix="u_")]
+namespace Icu {
+
+    [CCode (cname = "UChar")]
+    [IntegerType (rank = 5, min = 0, max = 65535)]
+    struct Char {}
+
+    [CCode (cname = "UErrorCode", cprefix = "U_", cheader_filename = "unicode/utypes.h")]
+    enum ErrorCode {
+        ZERO_ERROR,
+        INVALID_CHAR_FOUND,
+        INDEX_OUTOFBOUNDS_ERROR,
+        BUFFER_OVERFLOW_ERROR,
+        STRINGPREP_PROHIBITED_ERROR,
+        UNASSIGNED_CODE_POINT_FOUND,
+        IDNA_STD3_ASCII_RULES_ERROR;
+
+        [CCode (cname = "u_errorName")]
+        public unowned string errorName();
+
+        [CCode (cname = "U_SUCCESS")]
+        public bool is_success();
+
+        [CCode (cname = "U_FAILURE")]
+        public bool is_failure();
+    }
+
+    [CCode (cname = "UParseError", cprefix = "U_", cheader_filename = "unicode/parseerr.h")]
+    struct ParseError {}
+
+    [CCode (cname = "UText", cprefix = "utext_", free_function = "utext_close", cheader_filename = 
"unicode/utext.h")]
+    [Compact]
+    class Text {
+        [CCode (cname="utext_openUTF8")]
+        public static Text open_utf8(Text* existing, [CCode (array_length_type = "int64_t")] uint8[] text, 
ref ErrorCode status);
+    }
+
+    [CCode (cname = "UBreakIterator", cprefix = "ubrk_", free_function = "ubrk_close", cheader_filename = 
"unicode/ubrk.h")]
+    [Compact]
+    class BreakIterator {
+
+        [CCode (cname = "UBRK_DONE")]
+        public const int32 DONE;
+
+        [CCode (cname = "UBreakIteratorType", cprefix = "UBRK_")]
+        public enum Type {
+            CHARACTER,
+            WORD,
+            LINE,
+            SENTENCE;
+        }
+
+        [CCode (cname = "UWordBreak", cprefix = "UBRK_WORD_")]
+        enum WordBreak {
+            NONE,
+            NONE_LIMIT,
+            NUMBER,
+            NUMBER_LIMIT,
+            LETTER,
+            LETTER_LIMIT,
+            KANA,
+            KANA_LIMIT,
+            IDEO,
+            IDEO_LIMIT;
+        }
+
+        public static BreakIterator open(Type type, string locale, Char* text, int32 text_len, ref ErrorCode 
status);
+
+        public int32 current {
+            [CCode (cname="ubrk_current")] get;
+        }
+        public int32 rule_status {
+            [CCode (cname="ubrk_getRuleStatus")] get;
+        }
+
+        [CCode (cname="ubrk_isBoundary")]
+        public bool is_boundary(int32 offset);
+
+        public int32 first();
+        public int32 last();
+
+        public int32 next();
+        public int32 previous();
+
+        public int32 proceeding(int32 offset);
+        public int32 following(int32 offset);
+
+        [CCode (cname="ubrk_setUText")]
+        public void set_utext(Text text, ref ErrorCode status);
+    }
+
+
+}
\ No newline at end of file
diff --git a/meson.build b/meson.build
index d974e55b6..0b875e86f 100644
--- a/meson.build
+++ b/meson.build
@@ -111,6 +111,13 @@ webkit2gtk_web_extension = dependency('webkit2gtk-web-extension-4.0', version: '
 # following libraries, but the declared dependency is what we actually
 # build against so we can include the custom VAPI correctly.
 
+icu_uc = declare_dependency(
+  dependencies: [
+    valac.find_library('icu-uc', dirs: [vapi_dir]),
+    cc.find_library('icuuc'),
+  ],
+)
+
 if libunwind_dep.found()
   # We need to add native lib to the search path for these so Flatpak
   # builds can find it.
@@ -131,15 +138,6 @@ libstemmer = declare_dependency(
   ],
 )
 
-# Faux ICU dependency to prevent ICU being passed to valac as a
-# package by meson
-icu = declare_dependency(
-  dependencies: [
-    cc.find_library('icuuc'),
-    cc.find_library('icudata'),
-  ],
-)
-
 # Optional dependencies
 appstream_util = find_program('appstream-util', required: false)
 desktop_file_validate = find_program('desktop-file-validate', required: false)
diff --git a/src/client/meson.build b/src/client/meson.build
index aeea36d01..e4726cebb 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -164,6 +164,7 @@ client_dependencies = [
   goa,
   gspell,
   gtk,
+  icu_uc,
   javascriptcoregtk,
   json_glib,
   libhandy,
diff --git a/src/engine/meson.build b/src/engine/meson.build
index ba9941ffa..a29daf0b0 100644
--- a/src/engine/meson.build
+++ b/src/engine/meson.build
@@ -325,7 +325,7 @@ engine_dependencies = [
   gio,
   glib,
   gmime,
-  icu,
+  icu_uc,
   libmath,
   libstemmer,
   libxml,
@@ -416,7 +416,7 @@ engine_internal_dep = declare_dependency(
 # command line app can still be used.
 tokeniser_lib = shared_library('geary-tokeniser',
   files('imap-db/imap-db-fts5-tokeniser.c'),
-  dependencies: [ glib, icu, sqlite ],
+  dependencies: [ glib, icu_uc, sqlite ],
   c_args: [
     # Enable GLib structured logging
     '-DG_LOG_USE_STRUCTURED',
diff --git a/src/meson.build b/src/meson.build
index 1ce6681ca..d2b018038 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -149,6 +149,7 @@ foreach dep : valadoc_dependencies
   valadoc_dep_args += '--pkg'
   valadoc_dep_args += dep.name()
 endforeach
+valadoc_dep_args += [ '--pkg', 'icu-uc' ]
 valadoc_dep_args += [ '--pkg', 'libstemmer' ]
 valadoc_dep_args += [ '--pkg', 'posix' ]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]