Skip to content

Commit

Permalink
Use SPM as the build manager; etc. (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Mar 11, 2024
1 parent ce874f5 commit 3b7dc43
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 552 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/continuous-integration-workflow-spm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build_UnitTest_SPM
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
swift: ["5.9.2"]
steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: Build
run: swift build
20 changes: 0 additions & 20 deletions .github/workflows/continuous-integration-workflow-xcode-latest.yml

This file was deleted.

6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(Tekkon)

set(CMAKE_CXX_STANDARD 17)

add_library(TekkonLib Tekkon/Tekkon.hh Tekkon/main.cc)
add_library(TekkonLib ./Sources/Tekkon/include/Tekkon.hh ./Sources/Tekkon/Tekkon.cc)

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
Expand All @@ -16,14 +16,14 @@ include(FetchContent)
FetchContent_Declare(
googletest
# Specify the commit you depend on and update it regularly.
URL https://gitcode.net/mirrors/google/googletest/-/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5/googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Test target declarations.
add_executable(TekkonTest TekkonCCTest_gtest/TekkonTest.cc)
add_executable(TekkonTest ./GTests/TekkonTest.cc)
target_link_libraries(TekkonTest gtest_main TekkonLib)
include(GoogleTest)
gtest_discover_tests(TekkonTest)
Expand Down
30 changes: 7 additions & 23 deletions TekkonCCTest_gtest/TekkonTest.cc → GTests/TekkonTest.cc
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
// (c) 2022 and onwards The vChewing Project (MIT-NTL License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.

1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "../Tekkon/Tekkon.hh"
#include "../Sources/Tekkon/include/Tekkon.hh"
#include "gtest/gtest.h"

namespace Tekkon {
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Tekkon",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Tekkon",
targets: ["Tekkon"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Tekkon",
cxxSettings: [.unsafeFlags(["-fcxx-modules", "-fmodules"])]
),
.testTarget(
name: "TekkonCCTests",
dependencies: ["Tekkon"]
// swiftSettings: [.interoperabilityMode(.Cxx)]
),
],
cxxLanguageStandard: .cxx17
)
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@

鐵恨引擎的 Cpp 版本,依 Cpp 17 標準編寫完成。

該專案雖使用 Xcode 開發維護+單元測試,但不妨礙在任何平台使用,因為實體只有「Tekkon.hh」這一個檔案(格式:UTF8 無 BOM)。

該專案推薦至少使用 Xcode 13.4.1。更舊版的 Xcode 的話,只要你能跑 Cpp 17 沒問題就行。或者,「`cmake -S . -B Build`」然後到 Build 目錄下執行「`make runTest`」。
該專案雖使用 Swift Package Manager (SPM) 開發維護+單元測試,但不妨礙在任何平台使用,因為**實體只有「Tekkon.hh」這一個檔案(格式:UTF8 無 BOM)**
- 敝倉庫的 ObjC 檔案全都是給 SPM 專用的單元測試腳本。

該專案推薦使用的建置手段:
- [跨平台 OS] 任何有支援 Cpp17 的 compiler,比如符合這種要求的 Clang 或 GCC。
- [跨平台 OS] Swift 5.9,以 SPM 的形式建置。
- 因為沒有用到任何 Swift 原始碼,所以建置產物對 Swift 不會構成依賴。SPM 在這裡充當了 CMake 的替代角色。
- [僅 Apple 平台] 使用 Xcode 的話,須至少 Xcode 15.1。 // Xcode 15.0 因為 Bug 太多的原因不推薦使用。

該專案推薦使用的單元測試手段:
- [僅 Apple 平台] SPM 單元測試,直接使用上文提到的 SPM 或 Xcode 即可。
- [跨平台 OS] GoogleTests,詳見 GTests 目錄下的內容。
- 但因為 GoogleTests 官方程式包 Archive 無法在某些國家和地區穩定獲取的緣故,敝倉庫不推薦在這些市場使用這個測試手段。
- SPM 的單元測試是 Objective-C 寫的,但 SPM 在非 Apple 平台下無法使用 ObjC 來完成單元測試。

> 注意:該引擎會將「ㄅㄨㄥ ㄆㄨㄥ ㄇㄨㄥ ㄈㄨㄥ」這四種讀音自動轉換成「ㄅㄥ ㄆㄥ ㄇㄥ ㄈㄥ」、將「ㄅㄨㄛ ㄆㄨㄛ ㄇㄨㄛ ㄈㄨㄛ」這四種讀音自動轉換成「ㄅㄛ ㄆㄛ ㄇㄛ ㄈㄛ」。如果您正在開發的輸入法的詞庫內的「甮」字的讀音沒有從「ㄈㄨㄥˋ」改成「ㄈㄥˋ」、或者說需要保留「ㄈㄨㄥˋ」的讀音的話,請按需修改「receiveKeyfromPhonabet()」函式當中的相關步驟、來跳過該轉換。該情形為十分罕見之情形。類似情形則是台澎金馬審音的慣用讀音「ㄌㄩㄢˊ」,因為使用者眾、所以不會被該引擎自動轉換成「ㄌㄨㄢˊ」。威注音輸入法內部已經從辭典角度做了處理、允許在敲「ㄌㄨㄢˊ」的時候出現以「ㄌㄩㄢˊ」為讀音的漢字。我們鼓勵輸入法開發者們使用 [威注音語彙庫](https://gitee.com/vChewing/libvchewing-data) 來實現對兩岸讀音習慣的同時兼顧。
Expand Down
13 changes: 13 additions & 0 deletions Sources/Tekkon/Tekkon.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// (c) 2022 and onwards The vChewing Project (MIT-NTL License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.

#include "./include/Tekkon.hh"

namespace Tekkon {};

int main(int argc, const char* argv[]) { return 0; }
44 changes: 15 additions & 29 deletions Tekkon/Tekkon.hh → Sources/Tekkon/include/Tekkon.hh
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
// (c) 2022 and onwards The vChewing Project (MIT-NTL License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.

// ADVICE: Save as UTF8 without BOM signature!!!

Expand All @@ -29,7 +13,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/// 那樣放在檔案末尾,就只能放在檔案開頭了。另外,Cpp 的 select case 語句是可以
/// 將 std::string 拿來 switch 的,但必須做雜湊化處理(hashify)使其整數化。

// This module conforms to Cpp20 standard. Use Clang-14 or higher to compile.
// This module conforms to Cpp17 standard.
// Clang-14 or higher is recommended for compilation.
// If using Swift Package Manager to compile, use Swift 5.9 or newer.

#ifndef TEKKON_HH_
#define TEKKON_HH_
Expand Down Expand Up @@ -93,11 +79,11 @@ std::vector<T>& operator+=(std::vector<T>& x, std::vector<T>& y) {
}

// The following function is taken from boost internals.
// License https://www.boost.org/users/license.html
inline static unsigned utf8ByteCount(uint8_t theChar) {
// License: https://www.boost.org/users/license.html
inline static unsigned utf8ByteCount(unsigned theChar) {
// if the most significant bit with a zero in it is in position
// 8-N then there are N bytes in this UTF-8 sequence:
uint8_t mask = 0x80u;
unsigned mask = 0x80u;
unsigned result = 0;
while (theChar & mask) {
++result;
Expand All @@ -107,12 +93,12 @@ inline static unsigned utf8ByteCount(uint8_t theChar) {
}

// The following function is taken from boost internals.
// License https://www.boost.org/users/license.html
// License: https://www.boost.org/users/license.html
inline static std::vector<std::string> splitByCodepoint(std::string input) {
std::vector<std::string> arrReturned;
auto netaIterated = input.cbegin();
while (netaIterated != input.cend()) {
uint8_t count = utf8ByteCount(*netaIterated);
unsigned count = utf8ByteCount(*netaIterated);
arrReturned.emplace_back(std::string{netaIterated, netaIterated + count});
netaIterated += count;
}
Expand Down Expand Up @@ -399,7 +385,7 @@ inline static std::vector<std::vector<std::string>>
{"v1", "ǖ"}, {"v2", "ǘ"}, {"v3", "ǚ"},
{"v4", "ǜ"}};

// MARK, - Maps for Keyboard-to-Pinyin parsers
// MARK: - Maps for Keyboard-to-Pinyin parsers

/// 任何形式的拼音排列都會用到的陣列(韋氏拼音與趙元任國語羅馬字除外),
/// 用 Strings 反而省事一些。
Expand Down
16 changes: 0 additions & 16 deletions Tekkon/main.cc

This file was deleted.

Loading

0 comments on commit 3b7dc43

Please sign in to comment.