diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91129d22f..b4b55af78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CMAKE_GENERATOR: Ninja jobs: build: @@ -19,7 +20,11 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] with_rust: ['true', 'false'] - rust_version: ['1.70', 'stable'] + rust_version: ['1.70'] + include: + - os: ubuntu-latest + with_rust: true + rust_version: stable exclude: - with_rust: 'false' rust_version: 'stable' @@ -31,6 +36,15 @@ jobs: with: submodules: 'true' + - if: ${{ matrix.os == 'ubuntu-latest' }} + run: sudo apt-get install ninja-build + - if: ${{ matrix.os == 'macos-latest' }} + run: brew install ninja + - if: ${{ matrix.os == 'windows-latest' }} + run: choco install ninja + - if: ${{ matrix.os == 'windows-latest' }} + uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 + - name: Setup rustup run: | rustup default ${{ matrix.rust_version }} @@ -50,6 +64,8 @@ jobs: with: submodules: 'true' + - run: sudo apt-get install ninja-build + - name: Build run: cargo xtask build --build-type ${{env.BUILD_TYPE}} --with-rust false --with-hash true --verbose true @@ -61,13 +77,15 @@ jobs: matrix: with_rust: ['true', 'false'] runs-on: ubuntu-latest - name: with_rust=${{ matrix.with_rust }} + name: Coverage with_rust=${{ matrix.with_rust }} steps: - uses: actions/checkout@v3 with: submodules: 'true' + - run: sudo apt-get install ninja-build + - name: Setup rustup run: | rustup default stable diff --git a/CMakeLists.txt b/CMakeLists.txt index f4b08d4c7..1e28b38c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,15 +15,14 @@ endif() include(CheckCCompilerFlag) -option(BUILD_DLL "Build dynamic link library (*.dll) instead of static lib." true) +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) -if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR - ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") +if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang) set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") add_compile_definitions(_GNU_SOURCE) option(ENABLE_GCOV "Coverage support" false) if(ENABLE_GCOV) - if (WITH_RUST AND ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") + if(WITH_RUST AND CMAKE_C_COMPILER_ID MATCHES Clang) set(CMAKE_C_FLAGS "-fprofile-instr-generate -fcoverage-mapping ${CMAKE_C_FLAGS}") else() set(CMAKE_C_FLAGS "--coverage ${CMAKE_C_FLAGS}") @@ -55,8 +54,6 @@ elseif(MSVC) if(MSVC_VERSION LESS 1900) add_compile_definitions(snprintf=_snprintf) endif() - - set(BUILD_DLL false) endif() @@ -83,16 +80,15 @@ endif() option(USE_VALGRIND "Use valgrind when testing" true) option(WITH_RUST "Use rust implemented internals (experimental)" false) -if (WITH_RUST) +if(WITH_RUST) add_subdirectory(cmake/corrosion) - if (CMAKE_BUILD_TYPE MATCHES DEBUG) + if(CMAKE_BUILD_TYPE MATCHES DEBUG) corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing FEATURES capi test-tracing) else() corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing FEATURES capi) endif() corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing-tools) add_compile_definitions(WITH_RUST) - corrosion_set_env_vars(chewing CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}) if(ENABLE_GCOV) corrosion_set_env_vars(chewing CARGO_INCREMENTAL=0) corrosion_add_target_local_rustflags(chewing -Cinstrument-coverage -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort) @@ -106,12 +102,31 @@ check_type_size(uint16_t UINT16_T) set(CURSES_NEED_WIDE true) find_package(Curses) -if (WITH_SQLITE3) - if (WITH_INTERNAL_SQLITE3) +if(WITH_SQLITE3) + if(WITH_INTERNAL_SQLITE3) set(SQLITE3_SRC_DIR ${PROJECT_SOURCE_DIR}/thirdparty/sqlite-amalgamation) include_directories( ${SQLITE3_SRC_DIR} ) + find_package (Threads) + add_library(sqlite3_library STATIC + ${SQLITE3_SRC_DIR}/sqlite3.c + ${SQLITE3_SRC_DIR}/sqlite3.h + ) + target_link_libraries(sqlite3_library ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) + + add_executable(sqlite3 + ${SQLITE3_SRC_DIR}/shell.c + ) + target_link_libraries(sqlite3 sqlite3_library) + set_target_properties(sqlite3 PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${SQLITE3_SRC_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${SQLITE3_SRC_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SQLITE3_SRC_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SQLITE3_SRC_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${SQLITE3_SRC_DIR} + ) + set(SQLite3_LIBRARIES sqlite3_library) else() find_package(SQLite3 REQUIRED) include_directories(SQLite3_INCLUDE_DIRS) @@ -179,7 +194,7 @@ set(ALL_INC ${INC_DIR}/mod_aux.h ) -if (WITH_RUST) +if(WITH_RUST) list(APPEND ALL_INC ${INC_DIR}/chewing_rs.h) endif() @@ -192,159 +207,117 @@ add_library(common OBJECT src/porting_layer/src/asprintf.h src/porting_layer/src/asprintf.c - src/chewing.c ) target_compile_definitions(common PRIVATE CHEWING_DATADIR=\"${CMAKE_INSTALL_FULL_DATADIR}/libchewing\" ) -add_library(chewing_c OBJECT - ${ALL_INC} -) -if (WITH_RUST) -target_sources(chewing_c PRIVATE - src/rust_wrapper.c -) -else() -target_sources(common PRIVATE - ${SRC_DIR}/porting_layer/include/plat_mmap.h - ${SRC_DIR}/porting_layer/include/plat_path.h - ${SRC_DIR}/porting_layer/include/plat_types.h - ${SRC_DIR}/porting_layer/include/sys/plat_posix.h - ${SRC_DIR}/porting_layer/include/sys/plat_windows.h - - ${SRC_DIR}/porting_layer/src/plat_mmap_posix.c - ${SRC_DIR}/porting_layer/src/plat_mmap_windows.c - ${SRC_DIR}/porting_layer/src/plat_path.c - ${SRC_DIR}/porting_layer/src/rpl_malloc.c - ${SRC_DIR}/common/chewing-utf8-util.c - ${SRC_DIR}/common/key2pho.c -) -target_sources(chewing_c PRIVATE - ${INC_DIR}/internal/bopomofo-private.h - ${INC_DIR}/internal/chewing-private.h - ${INC_DIR}/internal/chewingutil.h - ${INC_DIR}/internal/choice-private.h - ${INC_DIR}/internal/dict-private.h - ${INC_DIR}/internal/global-private.h - ${INC_DIR}/internal/pinyin-private.h - ${INC_DIR}/internal/tree-private.h - ${INC_DIR}/internal/userphrase-private.h - - ${SRC_DIR}/bopomofo.c - ${SRC_DIR}/chewingio.c - ${SRC_DIR}/chewingutil.c - ${SRC_DIR}/choice.c - ${SRC_DIR}/compat.c - ${SRC_DIR}/dict.c - ${SRC_DIR}/mod_aux.c - ${SRC_DIR}/pinyin.c - ${SRC_DIR}/private.h - ${SRC_DIR}/tree.c - ${SRC_DIR}/userphrase.c -) -endif() -target_compile_definitions(chewing_c PRIVATE +add_library(libchewing ${ALL_INC} src/chewing.c) +set_target_properties(libchewing PROPERTIES LINKER_LANGUAGE C) +target_compile_definitions(libchewing PRIVATE CHEWING_DATADIR=\"${CMAKE_INSTALL_FULL_DATADIR}/libchewing\" ) - -if (WITH_INTERNAL_SQLITE3) - find_package (Threads) - add_library(sqlite3_library STATIC - ${SQLITE3_SRC_DIR}/sqlite3.c - ${SQLITE3_SRC_DIR}/sqlite3.h - ) - target_link_libraries(sqlite3_library ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) - - add_executable(sqlite3 - ${SQLITE3_SRC_DIR}/shell.c +if(NOT WITH_RUST) + target_sources(common PRIVATE + ${SRC_DIR}/porting_layer/include/plat_mmap.h + ${SRC_DIR}/porting_layer/include/plat_path.h + ${SRC_DIR}/porting_layer/include/plat_types.h + ${SRC_DIR}/porting_layer/include/sys/plat_posix.h + ${SRC_DIR}/porting_layer/include/sys/plat_windows.h + + ${SRC_DIR}/porting_layer/src/plat_mmap_posix.c + ${SRC_DIR}/porting_layer/src/plat_mmap_windows.c + ${SRC_DIR}/porting_layer/src/plat_path.c + ${SRC_DIR}/porting_layer/src/rpl_malloc.c + ${SRC_DIR}/common/chewing-utf8-util.c + ${SRC_DIR}/common/key2pho.c ) - target_link_libraries(sqlite3 sqlite3_library) - set_target_properties(sqlite3 PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${SQLITE3_SRC_DIR} - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${SQLITE3_SRC_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SQLITE3_SRC_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SQLITE3_SRC_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${SQLITE3_SRC_DIR} + target_sources(libchewing PRIVATE + ${INC_DIR}/internal/bopomofo-private.h + ${INC_DIR}/internal/chewing-private.h + ${INC_DIR}/internal/chewingutil.h + ${INC_DIR}/internal/choice-private.h + ${INC_DIR}/internal/dict-private.h + ${INC_DIR}/internal/global-private.h + ${INC_DIR}/internal/pinyin-private.h + ${INC_DIR}/internal/tree-private.h + ${INC_DIR}/internal/userphrase-private.h + + ${SRC_DIR}/bopomofo.c + ${SRC_DIR}/chewingio.c + ${SRC_DIR}/chewingutil.c + ${SRC_DIR}/choice.c + ${SRC_DIR}/compat.c + ${SRC_DIR}/dict.c + ${SRC_DIR}/mod_aux.c + ${SRC_DIR}/pinyin.c + ${SRC_DIR}/private.h + ${SRC_DIR}/tree.c + ${SRC_DIR}/userphrase.c ) - set(SQLite3_LIBRARIES sqlite3_library) -endif() - -if (WITH_SQLITE3) - if (NOT WITH_RUST) - add_library(userphrase STATIC + if(WITH_SQLITE3) + add_library(userphrase OBJECT ${INC_DIR}/internal/chewing-sql.h - ${SRC_DIR}/chewing-sql.c ${SRC_DIR}/userphrase-sql.c ) + else() + add_library(userphrase OBJECT + ${INC_DIR}/internal/hash-private.h + ${SRC_DIR}/hash.c + ${SRC_DIR}/userphrase-hash.c + ) + endif() + target_link_libraries(libchewing + PRIVATE common + PRIVATE userphrase) + if(BUILD_SHARED_LIBS AND MSVC) + target_compile_definitions(libchewing PRIVATE CHEWINGDLL_EXPORTS) endif() -else() - add_library(userphrase STATIC - ${INC_DIR}/internal/hash-private.h - - ${SRC_DIR}/hash.c - ${SRC_DIR}/userphrase-hash.c - ) endif() -if (BUILD_DLL OR NOT MSVC) - if (MSVC) - add_compile_definitions(CHEWINGDLL_EXPORTS) - endif() - add_library(chewing_shared SHARED - $ - $ - ) - if (WITH_RUST) - if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR - ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") - target_link_options(chewing_shared PRIVATE "-Wl,-version-script,${CMAKE_BINARY_DIR}/symbols.map") - target_link_options(chewing_shared PRIVATE "-Wl,--gc-sections") - elseif (${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang") - target_link_options(chewing_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_BINARY_DIR}/symbols.map") - target_link_options(chewing_shared PRIVATE "-Wl,-dead_strip") - elseif (MSVC) - target_link_options(chewing_shared PRIVATE "/DEF ${CMAKE_BINARY_DIR}/symbols.map") - set_target_properties(chewing_shared PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +if(WITH_RUST) + target_link_libraries(libchewing PRIVATE chewing) + target_link_libraries(chewing INTERFACE ${SQLite3_LIBRARIES}) + if(BUILD_SHARED_LIBS) + if(CMAKE_C_COMPILER_ID MATCHES GNU|^Clang) + target_link_options(libchewing + PRIVATE LINKER:-version-script,${CMAKE_SOURCE_DIR}/src/symbols-elf.map + PRIVATE LINKER:--gc-sections + PRIVATE LINKER:-u,chewing_new + PRIVATE LINKER:-u,ueStrLen + PRIVATE LINKER:-u,UintFromPhone + PRIVATE LINKER:-u,find_path_by_files + ) + elseif(CMAKE_C_COMPILER_ID MATCHES AppleClang) + target_link_options(libchewing + PRIVATE LINKER:-exported_symbols_list,${CMAKE_SOURCE_DIR}/src/symbols-mach_o.map + PRIVATE LINKER:-dead_strip + ) + elseif(MSVC) + target_link_options(libchewing + PRIVATE /DEF:${CMAKE_SOURCE_DIR}/src/symbols-msvc.map + PRIVATE /MACHINE:X64) + set_target_properties(libchewing PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") endif() endif() - - list(APPEND LIBS chewing_shared) - add_dependencies(check chewing_shared) +elseif(WITH_SQLITE3) + target_link_libraries(libchewing PRIVATE ${SQLite3_LIBRARIES}) endif() -if (NOT BUILD_DLL) - add_library(chewing_static STATIC - $ - $ +if(MSVC) + set_target_properties(libchewing PROPERTIES + OUTPUT_NAME chewing-msvc + ) +else() + set_target_properties(libchewing PROPERTIES + OUTPUT_NAME chewing + SOVERSION 3 + VERSION 3.3.1 ) - list(APPEND LIBS chewing_static) - add_dependencies(check chewing_static) endif() -foreach(lib ${LIBS}) - if (WITH_RUST) - target_link_libraries(${lib} PRIVATE chewing) - if (WITH_SQLITE3) - target_link_libraries(chewing INTERFACE ${SQLite3_LIBRARIES}) - endif() - else() - target_link_libraries(${lib} userphrase) - if (WITH_SQLITE3) - target_link_libraries(userphrase ${SQLite3_LIBRARIES}) - endif() - endif() -endforeach() - -set_target_properties(${LIBS} PROPERTIES - OUTPUT_NAME chewing - SOVERSION 3 - VERSION 3.3.1 -) - -# install install(FILES ${ALL_INC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/chewing) install(FILES ${PROJECT_BINARY_DIR}/chewing.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -install(TARGETS ${LIBS} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(TARGETS libchewing DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/Cargo.lock b/Cargo.lock index 8c1245b7b..ce9485795 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -66,23 +66,6 @@ dependencies = [ "serde", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "1.3.2" @@ -112,26 +95,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", -] - -[[package]] -name = "cbindgen" -version = "0.24.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b922faaf31122819ec80c4047cc684c6979a087366c069611e33649bf98e18d" -dependencies = [ - "clap", - "heck", - "indexmap 1.9.3", - "log", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn 1.0.109", - "tempfile", - "toml", + "syn", ] [[package]] @@ -154,9 +118,8 @@ name = "chewing" version = "0.6.0-alpha.1" dependencies = [ "bytemuck", - "cbindgen", "directories", - "indexmap 2.1.0", + "indexmap", "riff", "rusqlite", "tempfile", @@ -176,30 +139,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags 1.3.2", - "clap_lex", - "indexmap 1.9.3", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "directories" version = "5.0.1" @@ -266,12 +205,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.3" @@ -288,32 +221,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.14.3", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", + "hashbrown", ] [[package]] @@ -323,15 +231,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown", ] -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - [[package]] name = "lazy_static" version = "1.4.0" @@ -415,12 +317,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "overload" version = "0.1.1" @@ -441,18 +337,18 @@ checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "proc-macro2" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a293318316cf6478ec1ad2a21c49390a8d5b5eae9fab736467d93fbc0edc29c5" +checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" dependencies = [ "proc-macro2", ] @@ -554,12 +450,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - [[package]] name = "serde" version = "1.0.193" @@ -577,18 +467,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", -] - -[[package]] -name = "serde_json" -version = "1.0.108" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" -dependencies = [ - "itoa", - "ryu", - "serde", + "syn", ] [[package]] @@ -606,28 +485,11 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "syn" -version = "1.0.109" +version = "2.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "0eae3c679c56dc214320b67a1bc04ef3dfbd6411f6443974b5e4893231298e66" dependencies = [ "proc-macro2", "quote", @@ -647,21 +509,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.53" @@ -679,7 +526,7 @@ checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -692,15 +539,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "tracing" version = "0.1.40" @@ -720,7 +558,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -808,15 +646,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -996,5 +825,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 916908d46..95dde9f8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,13 +32,9 @@ crate-type = ["lib", "staticlib"] [features] default = [] -capi = ["cbindgen"] +capi = [] test-tracing = ["tracing-subscriber"] -[build-dependencies] -# https://github.com/mozilla/cbindgen/issues/891 -cbindgen = { version = "0.24.5", optional = true } - [dev-dependencies] tempfile = "3" diff --git a/build.rs b/build.rs deleted file mode 100644 index 5de744065..000000000 --- a/build.rs +++ /dev/null @@ -1,206 +0,0 @@ -fn main() { - #[cfg(feature = "capi")] - { - use std::{env, fs::File, path::PathBuf}; - - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - cbindgen::generate(crate_dir) - .expect("Unable to generate C headers for Rust code") - .write_to_file("include/chewing_rs.h"); - println!("cargo:rerun-if-env-changed=CMAKE_BINARY_DIR"); - - if let Ok(cmake_build_dir) = env::var("CMAKE_BINARY_DIR") { - let mut path = PathBuf::new(); - path.push(cmake_build_dir); - path.push("symbols.map"); - let mut symbols_file = File::create(path).expect("open file"); - #[cfg(target_os = "linux")] - capi::write_version_script(&mut symbols_file).expect("writing to file"); - #[cfg(target_os = "macos")] - capi::write_exported_symbols(&mut symbols_file).expect("writing to file"); - #[cfg(target_os = "windows")] - capi::write_def(&mut symbols_file).expect("writing to file"); - } - } -} - -#[cfg(feature = "capi")] -mod capi { - use std::io::{Result, Write}; - - #[cfg(target_os = "linux")] - pub(super) fn write_version_script(f: &mut impl Write) -> Result<()> { - for (version, symbol_list) in SYMBOLS { - writeln!(f, "{version} {{")?; - writeln!(f, " global:")?; - for sym in symbol_list.iter() { - writeln!(f, " {sym};")?; - } - writeln!(f, "}};")?; - } - writeln!(f, "LOCAL {{ local: *; }};")?; - Ok(()) - } - - #[cfg(target_os = "windows")] - pub(super) fn write_def(f: &mut impl Write) -> Result<()> { - writeln!(f, "EXPORTS")?; - for (version, symbol_list) in SYMBOLS { - for sym in symbol_list.iter() { - writeln!(f, " {sym};")?; - } - } - Ok(()) - } - - #[cfg(target_os = "macos")] - pub(super) fn write_exported_symbols(f: &mut impl Write) -> Result<()> { - for (version, symbol_list) in SYMBOLS { - for sym in symbol_list.iter() { - writeln!(f, "_{sym}")?; - } - } - Ok(()) - } - - const SYMBOLS: &[(&str, &[&str])] = &[ - ( - "CHEWING_0.5", - &[ - "chewing_aux_Check", - "chewing_aux_Length", - "chewing_aux_String", - "chewing_aux_String_static", - "chewing_bopomofo_Check", - "chewing_bopomofo_String_static", - "chewing_buffer_Check", - "chewing_buffer_Len", - "chewing_buffer_String", - "chewing_buffer_String_static", - "chewing_cand_CheckDone", - "chewing_cand_ChoicePerPage", - "chewing_cand_choose_by_index", - "chewing_cand_close", - "chewing_cand_CurrentPage", - "chewing_cand_Enumerate", - "chewing_cand_hasNext", - "chewing_cand_list_first", - "chewing_cand_list_has_next", - "chewing_cand_list_has_prev", - "chewing_cand_list_last", - "chewing_cand_list_next", - "chewing_cand_list_prev", - "chewing_cand_open", - "chewing_cand_String", - "chewing_cand_string_by_index_static", - "chewing_cand_String_static", - "chewing_cand_TotalChoice", - "chewing_cand_TotalPage", - "chewing_clean_bopomofo_buf", - "chewing_clean_preedit_buf", - "chewing_commit_Check", - "chewing_commit_preedit_buf", - "chewing_commit_String", - "chewing_commit_String_static", - "chewing_Configure", - "chewing_cursor_Current", - "chewing_delete", - "chewing_free", - "chewing_get_addPhraseDirection", - "chewing_get_autoLearn", - "chewing_get_autoShiftCur", - "chewing_get_candPerPage", - "chewing_get_ChiEngMode", - "chewing_get_easySymbolInput", - "chewing_get_escCleanAllBuf", - "chewing_get_hsuSelKeyType", - "chewing_get_KBString", - "chewing_get_KBType", - "chewing_get_maxChiSymbolLen", - "chewing_get_phoneSeq", - "chewing_get_phoneSeqLen", - "chewing_get_phraseChoiceRearward", - "chewing_get_selKey", - "chewing_get_ShapeMode", - "chewing_get_spaceAsSelection", - "chewing_handle_Backspace", - "chewing_handle_Capslock", - "chewing_handle_CtrlNum", - "chewing_handle_DblTab", - "chewing_handle_Default", - "chewing_handle_Del", - "chewing_handle_Down", - "chewing_handle_End", - "chewing_handle_Enter", - "chewing_handle_Esc", - "chewing_handle_Home", - "chewing_handle_Left", - "chewing_handle_Numlock", - "chewing_handle_PageDown", - "chewing_handle_PageUp", - "chewing_handle_Right", - "chewing_handle_ShiftLeft", - "chewing_handle_ShiftRight", - "chewing_handle_ShiftSpace", - "chewing_handle_Space", - "chewing_handle_Tab", - "chewing_handle_Up", - "chewing_Init", - "chewing_interval_Enumerate", - "chewing_interval_Get", - "chewing_interval_hasNext", - "chewing_KBStr2Num", - "chewing_kbtype_Enumerate", - "chewing_kbtype_hasNext", - "chewing_kbtype_String", - "chewing_kbtype_String_static", - "chewing_kbtype_Total", - "chewing_keystroke_CheckAbsorb", - "chewing_keystroke_CheckIgnore", - "chewing_new", - "chewing_new2", - "chewing_phone_to_bopomofo", - "chewing_Reset", - "chewing_set_addPhraseDirection", - "chewing_set_autoLearn", - "chewing_set_autoShiftCur", - "chewing_set_candPerPage", - "chewing_set_ChiEngMode", - "chewing_set_easySymbolInput", - "chewing_set_escCleanAllBuf", - "chewing_set_hsuSelKeyType", - "chewing_set_KBType", - "chewing_set_logger", - "chewing_set_maxChiSymbolLen", - "chewing_set_phraseChoiceRearward", - "chewing_set_selKey", - "chewing_set_ShapeMode", - "chewing_set_spaceAsSelection", - "chewing_Terminate", - "chewing_userphrase_add", - "chewing_userphrase_enumerate", - "chewing_userphrase_get", - "chewing_userphrase_has_next", - "chewing_userphrase_lookup", - "chewing_userphrase_remove", - "chewing_zuin_Check", - "chewing_zuin_String", - ], - ), - ( - "CHEWING_INTERNAL", - &[ - "find_path_by_files", - "get_search_path", - "ueBytesFromChar", - "ueConstStrSeek", - "ueStrLen", - "ueStrNBytes", - "ueStrNCpy", - "ueStrSeek", - "ueStrStr", - "UintFromPhone", - ], - ), - ]; -} diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 161168be1..de3926868 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,13 +1,13 @@ -if (WITH_RUST) -set(ALL_DATA - ${DATA_BIN_DIR}/tsi.dat - ${DATA_BIN_DIR}/word.dat -) +if(WITH_RUST) + set(ALL_DATA + ${DATA_BIN_DIR}/tsi.dat + ${DATA_BIN_DIR}/word.dat + ) else() -set(ALL_DATA - ${DATA_BIN_DIR}/dictionary.dat - ${DATA_BIN_DIR}/index_tree.dat -) + set(ALL_DATA + ${DATA_BIN_DIR}/dictionary.dat + ${DATA_BIN_DIR}/index_tree.dat + ) endif() add_custom_target(data ALL DEPENDS ${ALL_DATA}) @@ -28,13 +28,13 @@ add_custom_target(all_static_data # tools set(ALL_TOOLS init_database) -if (NOT WITH_RUST) -list(APPEND ALL_TOOLS dump_database) -add_executable(init_database ${TOOLS_SRC_DIR}/init_database.c $) -add_executable(dump_database - ${TOOLS_SRC_DIR}/dump_database.c - $ -) +if(NOT WITH_RUST) + list(APPEND ALL_TOOLS dump_database) + add_executable(init_database ${TOOLS_SRC_DIR}/init_database.c $) + add_executable(dump_database + ${TOOLS_SRC_DIR}/dump_database.c + $ + ) endif() set_target_properties(${ALL_TOOLS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TOOLS_BIN_DIR} @@ -46,44 +46,44 @@ set_target_properties(${ALL_TOOLS} PROPERTIES # tools command file(MAKE_DIRECTORY ${DATA_BIN_DIR}) -if (WITH_RUST) -set(DATA_COPYRIGHT "Copyright \\(c\\) 2022 libchewing Core Team") -set(DATA_LICENSE "LGPL-2.1-or-later") -set(DATA_VERSION ${LIBCHEWING_VERSION}) -add_custom_command( - OUTPUT - ${ALL_DATA} - COMMAND init_database - -c ${DATA_COPYRIGHT} - -l ${DATA_LICENSE} - -r ${DATA_VERSION} - -t trie - -n 內建詞庫 - ${DATA_SRC_DIR}/tsi.src tsi.dat - COMMAND init_database - -c ${DATA_COPYRIGHT} - -l ${DATA_LICENSE} - -r ${DATA_VERSION} - -t trie - -n 內建字庫 - ${DATA_SRC_DIR}/word.src word.dat - DEPENDS - ${ALL_TOOLS} - ${DATA_SRC_DIR}/word.src - ${DATA_SRC_DIR}/tsi.src - WORKING_DIRECTORY ${DATA_BIN_DIR} -) +if(WITH_RUST) + set(DATA_COPYRIGHT "Copyright \\(c\\) 2022 libchewing Core Team") + set(DATA_LICENSE "LGPL-2.1-or-later") + set(DATA_VERSION ${LIBCHEWING_VERSION}) + add_custom_command( + OUTPUT + ${ALL_DATA} + COMMAND init_database + -c ${DATA_COPYRIGHT} + -l ${DATA_LICENSE} + -r ${DATA_VERSION} + -t trie + -n 內建詞庫 + ${DATA_SRC_DIR}/tsi.src tsi.dat + COMMAND init_database + -c ${DATA_COPYRIGHT} + -l ${DATA_LICENSE} + -r ${DATA_VERSION} + -t trie + -n 內建字庫 + ${DATA_SRC_DIR}/word.src word.dat + DEPENDS + ${ALL_TOOLS} + ${DATA_SRC_DIR}/word.src + ${DATA_SRC_DIR}/tsi.src + WORKING_DIRECTORY ${DATA_BIN_DIR} + ) else() -add_custom_command( - OUTPUT - ${ALL_DATA} - COMMAND init_database ${DATA_SRC_DIR}/phone.cin ${DATA_SRC_DIR}/tsi.src - DEPENDS - ${ALL_TOOLS} - ${DATA_SRC_DIR}/phone.cin - ${DATA_SRC_DIR}/tsi.src - WORKING_DIRECTORY ${DATA_BIN_DIR} -) + add_custom_command( + OUTPUT + ${ALL_DATA} + COMMAND init_database ${DATA_SRC_DIR}/phone.cin ${DATA_SRC_DIR}/tsi.src + DEPENDS + ${ALL_TOOLS} + ${DATA_SRC_DIR}/phone.cin + ${DATA_SRC_DIR}/tsi.src + WORKING_DIRECTORY ${DATA_BIN_DIR} + ) endif() install(FILES ${ALL_DATA} DESTINATION ${CMAKE_INSTALL_DATADIR}/libchewing) diff --git a/include/chewing_rs.h b/include/chewing_rs.h index 0c573b250..a052832cc 100644 --- a/include/chewing_rs.h +++ b/include/chewing_rs.h @@ -153,8 +153,6 @@ typedef struct ChewingConfigData { extern "C" { #endif // __cplusplus -void rust_link_io(void); - struct ChewingContext *chewing_new(void); void chewing_delete(struct ChewingContext *ctx); @@ -401,20 +399,8 @@ void chewing_set_hsuSelKeyType(struct ChewingContext *_ctx, int mode); int chewing_get_hsuSelKeyType(struct ChewingContext *_ctx); -void rust_link_key2pho(void); - uint16_t UintFromPhone(const char *phone); -uint16_t UintFromPhoneInx(const int *ph_inx); - -int PhoneFromUint(char *phone, uintptr_t phone_len, uint16_t phone_num); - -intptr_t UintArrayFromBopomofo(uint16_t *phone_seq, uintptr_t phone_len, const char *bopomofo_buf); - -int GetPhoneLenFromUint(uint16_t phone_num); - -void rust_link_path(void); - int get_search_path(char *path, uintptr_t path_len); int find_path_by_files(const char *search_path, @@ -422,8 +408,6 @@ int find_path_by_files(const char *search_path, char *output, uintptr_t output_len); -void rust_link_utf8(void); - int ueStrLen(const char *str); int ueBytesFromChar(unsigned char b); diff --git a/src/capi/io.rs b/src/capi/io.rs index f599e83a7..71ef0945c 100644 --- a/src/capi/io.rs +++ b/src/capi/io.rs @@ -35,9 +35,6 @@ use crate::{ zhuyin::Syllable, }; -#[no_mangle] -pub extern "C" fn rust_link_io() {} - enum Owned { CString, CUShortSlice(usize), diff --git a/src/capi/key2pho.rs b/src/capi/key2pho.rs index 31450c089..38864b441 100644 --- a/src/capi/key2pho.rs +++ b/src/capi/key2pho.rs @@ -1,12 +1,6 @@ -use std::{ - ffi::{c_char, c_int, CStr}, - ptr, slice, -}; +use std::ffi::{c_char, CStr}; -use crate::zhuyin::{Bopomofo, Syllable}; - -#[no_mangle] -pub extern "C" fn rust_link_key2pho() {} +use crate::zhuyin::Syllable; #[no_mangle] pub unsafe extern "C" fn UintFromPhone(phone: *const c_char) -> u16 { @@ -21,115 +15,3 @@ pub unsafe extern "C" fn UintFromPhone(phone: *const c_char) -> u16 { }; syl.to_u16() } - -#[no_mangle] -pub unsafe extern "C" fn UintFromPhoneInx(ph_inx: *const c_int) -> u16 { - let ph_inx = unsafe { slice::from_raw_parts(ph_inx, 4) }; - let mut builder = Syllable::builder(); - if ph_inx[0] > 0 { - let bopomofo = match Bopomofo::from_initial(ph_inx[0] as u16) { - Ok(bopomofo) => bopomofo, - Err(_) => return 0, - }; - builder = match builder.insert(bopomofo) { - Ok(builder) => builder, - Err(_) => return 0, - }; - } - if ph_inx[1] > 0 { - let bopomofo = match Bopomofo::from_medial(ph_inx[1] as u16) { - Ok(bopomofo) => bopomofo, - Err(_) => return 0, - }; - builder = match builder.insert(bopomofo) { - Ok(builder) => builder, - Err(_) => return 0, - }; - } - if ph_inx[2] > 0 { - let bopomofo = match Bopomofo::from_rime(ph_inx[2] as u16) { - Ok(bopomofo) => bopomofo, - Err(_) => return 0, - }; - builder = match builder.insert(bopomofo) { - Ok(builder) => builder, - Err(_) => return 0, - }; - } - if ph_inx[3] > 0 { - let bopomofo = match Bopomofo::from_tone(ph_inx[3] as u16) { - Ok(bopomofo) => bopomofo, - Err(_) => return 0, - }; - builder = match builder.insert(bopomofo) { - Ok(builder) => builder, - Err(_) => return 0, - }; - } - let syl = builder.build(); - if syl.is_empty() { - return 0; - } - syl.to_u16() -} - -#[no_mangle] -pub unsafe extern "C" fn PhoneFromUint( - phone: *mut c_char, - phone_len: usize, - phone_num: u16, -) -> c_int { - let syl = match Syllable::try_from(phone_num) { - Ok(syl) => syl, - Err(_) => return 1, - }; - let str = syl.to_string(); - if phone_len < str.len() + 1 { - return 1; - } - unsafe { - phone.copy_from(str.as_ptr() as *const c_char, str.len()); - ptr::write(phone.add(str.len()), 0); - } - 0 -} - -#[no_mangle] -pub unsafe extern "C" fn UintArrayFromBopomofo( - phone_seq: *mut u16, - phone_len: usize, - bopomofo_buf: *const c_char, -) -> isize { - let syllables_str = match unsafe { CStr::from_ptr(bopomofo_buf) }.to_str() { - Ok(str) => str, - Err(_) => return -1, - }; - let syllables: Vec<_> = syllables_str - .split_ascii_whitespace() - .map(|it| it.parse::().map(|syl| syl.to_u16())) - .collect(); - let len = syllables.len(); - if syllables.iter().any(|it| it.is_err()) { - return -1; - } - if len > phone_len || phone_seq.is_null() { - return len as isize; - } - for (i, syl) in syllables.into_iter().enumerate() { - let syl_u16 = syl.unwrap(); - unsafe { ptr::write(phone_seq.add(i), syl_u16) }; - } - len as isize -} - -#[no_mangle] -pub extern "C" fn GetPhoneLenFromUint(phone_num: u16) -> c_int { - let syl = match Syllable::try_from(phone_num) { - Ok(syl) => syl, - Err(_) => return -1, - }; - if syl.is_empty() { - return -1; - } - (syl.to_string().len() + 1) as c_int -} diff --git a/src/capi/path.rs b/src/capi/path.rs index cf5600f4d..16b0a4905 100644 --- a/src/capi/path.rs +++ b/src/capi/path.rs @@ -8,9 +8,6 @@ use std::{ use crate::path; -#[no_mangle] -pub extern "C" fn rust_link_path() {} - #[cfg(target_family = "windows")] const SEARCH_PATH_SEP: char = ';'; diff --git a/src/capi/utf8.rs b/src/capi/utf8.rs index 1a9e66637..71c11113f 100644 --- a/src/capi/utf8.rs +++ b/src/capi/utf8.rs @@ -4,9 +4,6 @@ use std::{ str, }; -#[no_mangle] -pub extern "C" fn rust_link_utf8() {} - #[no_mangle] pub unsafe extern "C" fn ueStrLen(str: *const c_char) -> c_int { let cstr = unsafe { CStr::from_ptr(str) }; diff --git a/src/rust_wrapper.c b/src/rust_wrapper.c deleted file mode 100644 index 0d80e3cdc..000000000 --- a/src/rust_wrapper.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "chewing_rs.h" - -void force_linkage() { - rust_link_io(); - rust_link_key2pho(); - rust_link_path(); - rust_link_utf8(); -} \ No newline at end of file diff --git a/src/symbols-elf.map b/src/symbols-elf.map new file mode 100644 index 000000000..9c01f1382 --- /dev/null +++ b/src/symbols-elf.map @@ -0,0 +1,132 @@ +{ + global: + chewing_aux_Check; + chewing_aux_Length; + chewing_aux_String; + chewing_aux_String_static; + chewing_bopomofo_Check; + chewing_bopomofo_String_static; + chewing_buffer_Check; + chewing_buffer_Len; + chewing_buffer_String; + chewing_buffer_String_static; + chewing_cand_CheckDone; + chewing_cand_ChoicePerPage; + chewing_cand_choose_by_index; + chewing_cand_close; + chewing_cand_CurrentPage; + chewing_cand_Enumerate; + chewing_cand_hasNext; + chewing_cand_list_first; + chewing_cand_list_has_next; + chewing_cand_list_has_prev; + chewing_cand_list_last; + chewing_cand_list_next; + chewing_cand_list_prev; + chewing_cand_open; + chewing_cand_String; + chewing_cand_string_by_index_static; + chewing_cand_String_static; + chewing_cand_TotalChoice; + chewing_cand_TotalPage; + chewing_clean_bopomofo_buf; + chewing_clean_preedit_buf; + chewing_commit_Check; + chewing_commit_preedit_buf; + chewing_commit_String; + chewing_commit_String_static; + chewing_Configure; + chewing_cursor_Current; + chewing_delete; + chewing_free; + chewing_get_addPhraseDirection; + chewing_get_autoLearn; + chewing_get_autoShiftCur; + chewing_get_candPerPage; + chewing_get_ChiEngMode; + chewing_get_easySymbolInput; + chewing_get_escCleanAllBuf; + chewing_get_hsuSelKeyType; + chewing_get_KBString; + chewing_get_KBType; + chewing_get_maxChiSymbolLen; + chewing_get_phoneSeq; + chewing_get_phoneSeqLen; + chewing_get_phraseChoiceRearward; + chewing_get_selKey; + chewing_get_ShapeMode; + chewing_get_spaceAsSelection; + chewing_handle_Backspace; + chewing_handle_Capslock; + chewing_handle_CtrlNum; + chewing_handle_DblTab; + chewing_handle_Default; + chewing_handle_Del; + chewing_handle_Down; + chewing_handle_End; + chewing_handle_Enter; + chewing_handle_Esc; + chewing_handle_Home; + chewing_handle_Left; + chewing_handle_Numlock; + chewing_handle_PageDown; + chewing_handle_PageUp; + chewing_handle_Right; + chewing_handle_ShiftLeft; + chewing_handle_ShiftRight; + chewing_handle_ShiftSpace; + chewing_handle_Space; + chewing_handle_Tab; + chewing_handle_Up; + chewing_Init; + chewing_interval_Enumerate; + chewing_interval_Get; + chewing_interval_hasNext; + chewing_KBStr2Num; + chewing_kbtype_Enumerate; + chewing_kbtype_hasNext; + chewing_kbtype_String; + chewing_kbtype_String_static; + chewing_kbtype_Total; + chewing_keystroke_CheckAbsorb; + chewing_keystroke_CheckIgnore; + chewing_new; + chewing_new2; + chewing_phone_to_bopomofo; + chewing_Reset; + chewing_set_addPhraseDirection; + chewing_set_autoLearn; + chewing_set_autoShiftCur; + chewing_set_candPerPage; + chewing_set_ChiEngMode; + chewing_set_easySymbolInput; + chewing_set_escCleanAllBuf; + chewing_set_hsuSelKeyType; + chewing_set_KBType; + chewing_set_logger; + chewing_set_maxChiSymbolLen; + chewing_set_phraseChoiceRearward; + chewing_set_selKey; + chewing_set_ShapeMode; + chewing_set_spaceAsSelection; + chewing_Terminate; + chewing_userphrase_add; + chewing_userphrase_enumerate; + chewing_userphrase_get; + chewing_userphrase_has_next; + chewing_userphrase_lookup; + chewing_userphrase_remove; + chewing_zuin_Check; + chewing_zuin_String; + find_path_by_files; + get_search_path; + ueBytesFromChar; + ueConstStrSeek; + ueStrLen; + ueStrNBytes; + ueStrNCpy; + ueStrSeek; + ueStrStr; + UintFromPhone; + local: *; +}; diff --git a/src/symbols-mach_o.map b/src/symbols-mach_o.map new file mode 100644 index 000000000..74326e0f4 --- /dev/null +++ b/src/symbols-mach_o.map @@ -0,0 +1,128 @@ +_chewing_aux_Check +_chewing_aux_Length +_chewing_aux_String +_chewing_aux_String_static +_chewing_bopomofo_Check +_chewing_bopomofo_String_static +_chewing_buffer_Check +_chewing_buffer_Len +_chewing_buffer_String +_chewing_buffer_String_static +_chewing_cand_CheckDone +_chewing_cand_ChoicePerPage +_chewing_cand_choose_by_index +_chewing_cand_close +_chewing_cand_CurrentPage +_chewing_cand_Enumerate +_chewing_cand_hasNext +_chewing_cand_list_first +_chewing_cand_list_has_next +_chewing_cand_list_has_prev +_chewing_cand_list_last +_chewing_cand_list_next +_chewing_cand_list_prev +_chewing_cand_open +_chewing_cand_String +_chewing_cand_string_by_index_static +_chewing_cand_String_static +_chewing_cand_TotalChoice +_chewing_cand_TotalPage +_chewing_clean_bopomofo_buf +_chewing_clean_preedit_buf +_chewing_commit_Check +_chewing_commit_preedit_buf +_chewing_commit_String +_chewing_commit_String_static +_chewing_Configure +_chewing_cursor_Current +_chewing_delete +_chewing_free +_chewing_get_addPhraseDirection +_chewing_get_autoLearn +_chewing_get_autoShiftCur +_chewing_get_candPerPage +_chewing_get_ChiEngMode +_chewing_get_easySymbolInput +_chewing_get_escCleanAllBuf +_chewing_get_hsuSelKeyType +_chewing_get_KBString +_chewing_get_KBType +_chewing_get_maxChiSymbolLen +_chewing_get_phoneSeq +_chewing_get_phoneSeqLen +_chewing_get_phraseChoiceRearward +_chewing_get_selKey +_chewing_get_ShapeMode +_chewing_get_spaceAsSelection +_chewing_handle_Backspace +_chewing_handle_Capslock +_chewing_handle_CtrlNum +_chewing_handle_DblTab +_chewing_handle_Default +_chewing_handle_Del +_chewing_handle_Down +_chewing_handle_End +_chewing_handle_Enter +_chewing_handle_Esc +_chewing_handle_Home +_chewing_handle_Left +_chewing_handle_Numlock +_chewing_handle_PageDown +_chewing_handle_PageUp +_chewing_handle_Right +_chewing_handle_ShiftLeft +_chewing_handle_ShiftRight +_chewing_handle_ShiftSpace +_chewing_handle_Space +_chewing_handle_Tab +_chewing_handle_Up +_chewing_Init +_chewing_interval_Enumerate +_chewing_interval_Get +_chewing_interval_hasNext +_chewing_KBStr2Num +_chewing_kbtype_Enumerate +_chewing_kbtype_hasNext +_chewing_kbtype_String +_chewing_kbtype_String_static +_chewing_kbtype_Total +_chewing_keystroke_CheckAbsorb +_chewing_keystroke_CheckIgnore +_chewing_new +_chewing_new2 +_chewing_phone_to_bopomofo +_chewing_Reset +_chewing_set_addPhraseDirection +_chewing_set_autoLearn +_chewing_set_autoShiftCur +_chewing_set_candPerPage +_chewing_set_ChiEngMode +_chewing_set_easySymbolInput +_chewing_set_escCleanAllBuf +_chewing_set_hsuSelKeyType +_chewing_set_KBType +_chewing_set_logger +_chewing_set_maxChiSymbolLen +_chewing_set_phraseChoiceRearward +_chewing_set_selKey +_chewing_set_ShapeMode +_chewing_set_spaceAsSelection +_chewing_Terminate +_chewing_userphrase_add +_chewing_userphrase_enumerate +_chewing_userphrase_get +_chewing_userphrase_has_next +_chewing_userphrase_lookup +_chewing_userphrase_remove +_chewing_zuin_Check +_chewing_zuin_String +_find_path_by_files +_get_search_path +_ueBytesFromChar +_ueConstStrSeek +_ueStrLen +_ueStrNBytes +_ueStrNCpy +_ueStrSeek +_ueStrStr +_UintFromPhone diff --git a/src/symbols-msvc.map b/src/symbols-msvc.map new file mode 100644 index 000000000..a5730e9b9 --- /dev/null +++ b/src/symbols-msvc.map @@ -0,0 +1,129 @@ +EXPORTS + chewing_aux_Check; + chewing_aux_Length; + chewing_aux_String; + chewing_aux_String_static; + chewing_bopomofo_Check; + chewing_bopomofo_String_static; + chewing_buffer_Check; + chewing_buffer_Len; + chewing_buffer_String; + chewing_buffer_String_static; + chewing_cand_CheckDone; + chewing_cand_ChoicePerPage; + chewing_cand_choose_by_index; + chewing_cand_close; + chewing_cand_CurrentPage; + chewing_cand_Enumerate; + chewing_cand_hasNext; + chewing_cand_list_first; + chewing_cand_list_has_next; + chewing_cand_list_has_prev; + chewing_cand_list_last; + chewing_cand_list_next; + chewing_cand_list_prev; + chewing_cand_open; + chewing_cand_String; + chewing_cand_string_by_index_static; + chewing_cand_String_static; + chewing_cand_TotalChoice; + chewing_cand_TotalPage; + chewing_clean_bopomofo_buf; + chewing_clean_preedit_buf; + chewing_commit_Check; + chewing_commit_preedit_buf; + chewing_commit_String; + chewing_commit_String_static; + chewing_Configure; + chewing_cursor_Current; + chewing_delete; + chewing_free; + chewing_get_addPhraseDirection; + chewing_get_autoLearn; + chewing_get_autoShiftCur; + chewing_get_candPerPage; + chewing_get_ChiEngMode; + chewing_get_easySymbolInput; + chewing_get_escCleanAllBuf; + chewing_get_hsuSelKeyType; + chewing_get_KBString; + chewing_get_KBType; + chewing_get_maxChiSymbolLen; + chewing_get_phoneSeq; + chewing_get_phoneSeqLen; + chewing_get_phraseChoiceRearward; + chewing_get_selKey; + chewing_get_ShapeMode; + chewing_get_spaceAsSelection; + chewing_handle_Backspace; + chewing_handle_Capslock; + chewing_handle_CtrlNum; + chewing_handle_DblTab; + chewing_handle_Default; + chewing_handle_Del; + chewing_handle_Down; + chewing_handle_End; + chewing_handle_Enter; + chewing_handle_Esc; + chewing_handle_Home; + chewing_handle_Left; + chewing_handle_Numlock; + chewing_handle_PageDown; + chewing_handle_PageUp; + chewing_handle_Right; + chewing_handle_ShiftLeft; + chewing_handle_ShiftRight; + chewing_handle_ShiftSpace; + chewing_handle_Space; + chewing_handle_Tab; + chewing_handle_Up; + chewing_Init; + chewing_interval_Enumerate; + chewing_interval_Get; + chewing_interval_hasNext; + chewing_KBStr2Num; + chewing_kbtype_Enumerate; + chewing_kbtype_hasNext; + chewing_kbtype_String; + chewing_kbtype_String_static; + chewing_kbtype_Total; + chewing_keystroke_CheckAbsorb; + chewing_keystroke_CheckIgnore; + chewing_new; + chewing_new2; + chewing_phone_to_bopomofo; + chewing_Reset; + chewing_set_addPhraseDirection; + chewing_set_autoLearn; + chewing_set_autoShiftCur; + chewing_set_candPerPage; + chewing_set_ChiEngMode; + chewing_set_easySymbolInput; + chewing_set_escCleanAllBuf; + chewing_set_hsuSelKeyType; + chewing_set_KBType; + chewing_set_logger; + chewing_set_maxChiSymbolLen; + chewing_set_phraseChoiceRearward; + chewing_set_selKey; + chewing_set_ShapeMode; + chewing_set_spaceAsSelection; + chewing_Terminate; + chewing_userphrase_add; + chewing_userphrase_enumerate; + chewing_userphrase_get; + chewing_userphrase_has_next; + chewing_userphrase_lookup; + chewing_userphrase_remove; + chewing_zuin_Check; + chewing_zuin_String; + find_path_by_files; + get_search_path; + ueBytesFromChar; + ueConstStrSeek; + ueStrLen; + ueStrNBytes; + ueStrNCpy; + ueStrSeek; + ueStrStr; + UintFromPhone; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eb08e94fa..8766efbbe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,7 +38,11 @@ endif() set(ALL_TESTS ${ALL_TESTCASES} ${ALL_TESTTOOLS}) foreach(target ${ALL_TESTCASES}) - add_test(${target} ${TEST_BIN_DIR}/${target}) + add_test( + NAME ${target} + COMMAND ${TEST_BIN_DIR}/${target} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) endforeach() if(USE_VALGRIND) @@ -53,11 +57,7 @@ endif() foreach(target ${ALL_TESTS}) add_executable(${target} ${TEST_SRC_DIR}/${target}.c) target_link_libraries(${target} testhelper) - if (BUILD_DLL) - target_link_libraries(${target} chewing_shared) - else() - target_link_libraries(${target} chewing_static) - endif() + target_link_libraries(${target} libchewing) target_compile_definitions(${target} PRIVATE CHEWING_DATA_PREFIX=\"${DATA_BIN_DIR}\" TEST_HASH_DIR=\"${TEST_BIN_DIR}\" @@ -72,9 +72,6 @@ add_library(testhelper STATIC ${TEST_SRC_DIR}/testhelper.c $ ) -if (NOT WITH_RUST) - target_link_libraries(testhelper userphrase) -endif() target_compile_definitions(testhelper PRIVATE CHEWING_DATA_PREFIX=\"${DATA_BIN_DIR}\" TEST_HASH_DIR=\"${TEST_BIN_DIR}\" @@ -100,4 +97,4 @@ foreach(target ${ALL_STATIC_TEST}) COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TEST_SRC_DIR}/${target} ${TEST_BIN_DIR}/${target} ) add_dependencies(check ${target}) -endforeach() \ No newline at end of file +endforeach()