Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packaging/ export-ignore
92 changes: 86 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ option(USE_SYSTEM_MARISA "Use system version of Marisa" OFF)
option(USE_SYSTEM_PYBIND11 "Use system version of pybind11" OFF)
option(USE_SYSTEM_RAPIDJSON "Use system version of RapidJSON" OFF)
option(USE_SYSTEM_TCLAP "Use system version of TCLAP" OFF)
set(OPENCC_SOURCE_PACKAGE_PROFILE "full" CACHE STRING "Source package profile: full, opencc, or opencc-jieba")
set_property(CACHE OPENCC_SOURCE_PACKAGE_PROFILE PROPERTY STRINGS full opencc opencc-jieba)

######## Package information
set (PACKAGE_URL https://github.com/BYVoid/OpenCC)
Expand All @@ -70,11 +72,68 @@ include(GitVersion)
# such as librime to relink instead of loading an ABI-incompatible libopencc.
set (OPENCC_ABI_VERSION 1.4)

set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}"
set(_OPENCC_SOURCE_PACKAGE_SUFFIX "")
set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES "")
set(_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES
"/.appveyor.yml"
"/.bazel[^/]*"
"/.agents/"
"/.claude/"
"/.npmignore"
"/AGENTS.md"
"/BUILD.bazel"
"/CLAUDE.md"
"/CONTRIBUTING.md"
"/DESIGN_PRINCIPLES.md"
"/MODULE.bazel"
"/MODULE.bazel.lock"
"/MANIFEST.in"
"/Makefile"
"/OpenCC.egg-info/"
"/PUBLICATIONS.md"
"/binding.gyp"
"/build.cmd"
"/data/icon/"
"/deps/google-benchmark/"
"/deps/pybind11-2.13.1/"
"/doc/"
"/examples/"
"/node/"
"/package.json"
"/package-lock.json"
"/patches/"
"/pyproject.toml"
"/python[^/]*/"
"/release-pypi-[^/]*"
"${PROJECT_SOURCE_DIR}/scripts/"
"/setup.py"
"/test.cmd"
)
if(OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "opencc")
set(_OPENCC_SOURCE_PACKAGE_SUFFIX "-opencc-src")
set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES
${_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES}
"/plugins/"
)
elseif(OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "opencc-jieba")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"opencc-jieba-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}-src"
)
set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES
${_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES}
"/plugins/jieba/node/"
)
elseif(NOT OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "full")
message(FATAL_ERROR "OPENCC_SOURCE_PACKAGE_PROFILE must be 'full', 'opencc', or 'opencc-jieba'.")
endif()

if(NOT CPACK_SOURCE_PACKAGE_FILE_NAME)
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}${_OPENCC_SOURCE_PACKAGE_SUFFIX}"
)
endif()
set(CPACK_SOURCE_IGNORE_FILES
"/build/;/test/dict.ocd;/test/dict.txt;/test/dict.bin;/other/;/opencc.xcodeproj/;/.git/;.gitignore;~$;.pyc;/bazel*;/node_modules;/.github;/.pytest_cache;/.vscode;${CPACK_SOURCE_IGNORE_FILES}"
"/build[^/]*/;/test/dict.ocd;/test/dict.txt;/test/dict.bin;/dict.ocd;/.DS_Store;/.zig-[^/]*/;/dist[^/]*/;/other/;/opencc.xcodeproj/;/.git/;.gitignore;~$;.pyc;/bazel*;/node_modules;/.github;/.pytest_cache;/.vscode;/packaging/;${_OPENCC_SOURCE_PACKAGE_IGNORE_FILES};${CPACK_SOURCE_IGNORE_FILES}"
)
include(CPack)

Expand Down Expand Up @@ -283,10 +342,22 @@ endif()
######## Subdirectories

add_subdirectory(src)
add_subdirectory(doc)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/CMakeLists.txt")
add_subdirectory(doc)
elseif(BUILD_DOCUMENTATION)
message(FATAL_ERROR "BUILD_DOCUMENTATION requires the doc source directory.")
endif()
add_subdirectory(data)
add_subdirectory(plugins)
add_subdirectory(test)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugins/CMakeLists.txt")
add_subdirectory(plugins)
elseif(BUILD_OPENCC_JIEBA_PLUGIN)
message(FATAL_ERROR "BUILD_OPENCC_JIEBA_PLUGIN requires the plugins source directory.")
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
elseif(ENABLE_GTEST)
message(FATAL_ERROR "ENABLE_GTEST requires the test source directory.")
endif()

if (ENABLE_BENCHMARK AND TARGET performance AND TARGET opencc_jieba)
target_compile_definitions(performance PRIVATE
Expand All @@ -307,13 +378,19 @@ endif()
######## Testing

if (ENABLE_GTEST)
if(NOT USE_SYSTEM_GTEST AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest-1.15.0/CMakeLists.txt")
message(FATAL_ERROR "ENABLE_GTEST with bundled GoogleTest requires deps/googletest-1.15.0.")
endif()
if(NOT USE_SYSTEM_GTEST)
add_subdirectory(deps/googletest-1.15.0)
endif()
enable_testing()
endif()

if (ENABLE_BENCHMARK)
if(NOT USE_SYSTEM_GOOGLE_BENCHMARK AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/google-benchmark/CMakeLists.txt")
message(FATAL_ERROR "ENABLE_BENCHMARK with bundled Google Benchmark requires deps/google-benchmark.")
endif()
set(BENCHMARK_ENABLE_TESTING OFF)
if(NOT USE_SYSTEM_GOOGLE_BENCHMARK)
add_subdirectory(deps/google-benchmark)
Expand All @@ -327,6 +404,9 @@ if (BUILD_PYTHON)
if(USE_SYSTEM_PYBIND11)
find_package(pybind11 CONFIG)
else()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/pybind11-2.13.1/CMakeLists.txt")
message(FATAL_ERROR "BUILD_PYTHON with bundled pybind11 requires deps/pybind11-2.13.1.")
endif()
add_subdirectory(deps/pybind11-2.13.1)
endif()
pybind11_add_module(opencc_clib src/py_opencc.cpp)
Expand Down
59 changes: 59 additions & 0 deletions packaging/debian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Debian Packaging Patch Mirror

This directory tracks the Debian-specific patch queue for OpenCC so upstream
maintainers can review Debian packaging deltas before a release.

Current baseline:

- Debian source package: `opencc 1.3.1+ds1-3`
- Patch index:
`https://udd.debian.org/patches.cgi?src=opencc&version=1.3.1%2Bds1-3`

Intent:

- Keep Debian packaging deltas visible to upstream maintainers.
- Identify patches that can be replaced by upstream-supported build options.
- Make release-time Debian coordination easier.

This directory is not authoritative Debian packaging. Debian maintainers should
continue to use the Debian Salsa repository and the Debian source package as the
source of truth.

Source package handling:

- `CMakeLists.txt` excludes `/packaging/` from CPack source archives.
- `package.json` uses an npm `files` whitelist, so this directory is not packed
into the npm package.
- GitHub's autogenerated "Source code" archives include all tracked files and
cannot be filtered by repository metadata. Use the CPack-generated source
archive for release assets when this directory must be excluded.

CPack source package profiles:

- The default `OPENCC_SOURCE_PACKAGE_PROFILE=full` keeps the existing source
package behavior.
- `OPENCC_SOURCE_PACKAGE_PROFILE=opencc` produces a C++-focused source archive
named `opencc-<version>-opencc-src.*`. It excludes Node.js, Python, Doxygen
documentation sources, Jieba plugin sources, benchmark-only dependencies, and
packaging metadata. Core C++ tests and bundled GoogleTest are kept so
maintainers can run `ctest` after configuring with `ENABLE_GTEST=ON`.
- `OPENCC_SOURCE_PACKAGE_PROFILE=opencc-jieba` produces a Jieba plugin-focused
source archive named `opencc-jieba-<version>-src.*`. It keeps the OpenCC C++
core and the Jieba plugin sources, but excludes Node.js, Python, Doxygen
documentation sources, benchmark-only dependencies, and packaging metadata.
Core C++ tests, bundled GoogleTest, and Jieba integration tests are kept so
maintainers can run `ctest` after configuring with `ENABLE_GTEST=ON`.

Example:

```sh
cmake -S . -B build-opencc-src -DOPENCC_SOURCE_PACKAGE_PROFILE=opencc
cmake --build build-opencc-src --target package_source

cmake -S . -B build-opencc-jieba-src -DOPENCC_SOURCE_PACKAGE_PROFILE=opencc-jieba
cmake --build build-opencc-jieba-src --target package_source
```

CPack source archives are generated from the filesystem, not from `git archive`.
Create release archives from a clean checkout so untracked local files cannot be
included accidentally.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
Date: Sun, 28 Jul 2024 19:42:55 -0400
Subject: Don't fetch remote images when reading docs on disk

This fixes a privacy breach previously reported as Lintian warnings

Forwarded: not-needed
Reviewed-by: xiao sheng wen <atzlinux@debian.org>
Last-Update: 2026-04-25
---
diff --git a/README.md b/README.md
index 9934199..71ca706 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,7 @@
# Open Chinese Convert 開放中文轉換

-[![CMake](https://github.com/BYVoid/OpenCC/actions/workflows/cmake.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/cmake.yml)
-[![Bazel](https://github.com/BYVoid/OpenCC/actions/workflows/bazel.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/bazel.yml)
-[![MSVC](https://github.com/BYVoid/OpenCC/actions/workflows/msvc.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/msvc.yml)
-[![Node.js CI](https://github.com/BYVoid/OpenCC/actions/workflows/nodejs.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/nodejs.yml)
-[![Python CI](https://github.com/BYVoid/OpenCC/actions/workflows/python.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/python.yml)
-[![AppVeyor](https://img.shields.io/appveyor/ci/Carbo/OpenCC.svg)](https://ci.appveyor.com/project/Carbo/OpenCC)
-
-[![latest packaged version(s)](https://repology.org/badge/latest-versions/opencc.svg)](https://repology.org/project/opencc/versions)
-
## Introduction 介紹

-![OpenCC](https://opencc.byvoid.com/img/opencc.png)

Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for conversions between Traditional Chinese, Simplified Chinese and Japanese Kanji (Shinjitai). It supports character-level and phrase-level conversion, character variant conversion and regional idioms among Mainland China, Taiwan and Hong Kong. This is not translation tool between Mandarin and Cantonese, etc.

23 changes: 23 additions & 0 deletions packaging/debian/patches/0004-Use-system-googletest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From: Shengjing Zhu <zhsj@debian.org>
Date: Sun, 28 Jul 2024 19:44:27 -0400
Subject: Use system googletest

Forwarded: not-needed
Last-Update: 2024-07-28
---
CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fdb13f..0cda6ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -235,6 +235,8 @@ add_subdirectory(test)
if (ENABLE_GTEST)
if(NOT USE_SYSTEM_GTEST)
add_subdirectory(deps/googletest-1.15.0)
+ else()
+ add_subdirectory(/usr/src/googletest/googletest ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
endif()
enable_testing()
endif()
20 changes: 20 additions & 0 deletions packaging/debian/patches/0005-Disable-build-in-setup.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From: Shengjing Zhu <zhsj@debian.org>
Date: Fri, 2 Aug 2024 17:11:08 +0800
Subject: Disable build in setup.py

---
setup.py | 1 +
1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index d6b5b90..5c46dbd 100644
--- a/setup.py
+++ b/setup.py
@@ -63,6 +63,7 @@ def get_long_description():


def build_libopencc(output_path):
+ return
print('building libopencc into %s' % _build_dir)

is_windows = sys.platform == 'win32'
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From: Boyuan Yang <byang@debian.org>
Date: Tue, 13 Jan 2026 18:04:57 -0500
Subject: setup.py: Handle python binding instead of cmake

---
setup.py | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 5c46dbd..ac443db 100644
--- a/setup.py
+++ b/setup.py
@@ -9,6 +9,8 @@ import setuptools
import setuptools.command.build_ext
import wheel.bdist_wheel

+import pybind11
+
_this_dir = os.path.dirname(os.path.abspath(__file__))
_build_dir = os.path.join(_this_dir, 'build', 'python')

@@ -112,10 +114,13 @@ class OpenCCExtension(setuptools.Extension, object):

class BuildExtCommand(setuptools.command.build_ext.build_ext, object):
def build_extension(self, ext):
- if self.inplace:
- output_path = os.path.join(_this_dir, 'python', 'opencc', 'clib')
- else:
- output_path = os.path.abspath(os.path.join(self.build_lib, 'opencc', 'clib'))
+ project_root = os.path.abspath(_this_dir)
+ build_dir = os.environ.get('OPENCC_BUILD_DIR', 'obj-x86_64-linux-gnu')
+ lib_path = os.path.join(project_root, build_dir, 'src')
+ ext.include_dirs.append(pybind11.get_include())
+ ext.include_dirs.append('src')
+ ext.library_dirs = [lib_path]
+ ext.runtime_library_dirs = [lib_path]
if isinstance(ext, OpenCCExtension):
build_libopencc(output_path)
else:
@@ -179,7 +184,14 @@ setuptools.setup(

packages=packages,
package_dir={'opencc': 'python/opencc'},
- ext_modules=[OpenCCExtension('opencc.clib.opencc_clib', 'python')],
+ ext_modules=[
+ setuptools.Extension(
+ 'opencc.clib.opencc_clib',
+ sources=['src/py_opencc.cpp'],
+ libraries=['opencc'],
+ language='c++'
+ )
+ ],
cmdclass={
'build_ext': BuildExtCommand,
'bdist_wheel': BDistWheelCommand,
5 changes: 5 additions & 0 deletions packaging/debian/patches/series
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0003-no-remote-images-when-reading-docs-on-disk.patch
0004-Use-system-googletest.patch
0005-Disable-build-in-setup.py.patch
0009-setup.py-Handle-python-binding-instead-of-cmake.patch

Loading