Utility to package and distribute Djinni libraries easily.
Project description
cpm-build
一个用于跨平台构建和打包 Djinni 库的 Python 命令行工具。
简介
cpm-build 是一个构建编排工具,旨在简化 Djinni 跨平台库的编译、构建和打包流程。通过统一的命令行接口,开发者可以轻松地为 Android、iOS、macOS、Windows 和 Linux 等多个平台构建原生库,并自动生成对应平台的分发包。
功能特性
- 多平台支持 — 支持 Android、iOS、macOS、Windows、Linux 五大平台
- 多架构编译 — 支持 x86_64、x86、armv8、armv7 等多种 CPU 架构
- 自动打包 — 自动生成平台专属分发包:
- AAR(Android Archive)— 用于 Android 项目集成
- XCFramework — 用于 iOS / macOS 项目集成
- Swift Package — 用于 Swift 包管理器集成
- NuGet — 用于 Windows / .NET 项目集成
- Conan 集成 — 基于 Conan 2.0+ 进行依赖管理和构建配置
- 灵活配置 — 支持 Debug / Release 构建模式,可自定义构建目录和 Conan Profile
系统要求
- Python >= 3.10
- Conan >= 2.0
- Git(用于自动版本号提取)
- 各平台工具链:
- Android: Android NDK(需设置
ANDROID_NDK_HOME环境变量) - iOS / macOS: Xcode
- Windows: Visual Studio 2022
- Linux: GCC 11+
- Android: Android NDK(需设置
安装
通过 pip 安装
pip install cpm-build
从源码安装
git clone https://github.com/goudantongxue/cpm-build.git
cd cpm-build
pip install .
快速开始
基本用法
在你的 Djinni 项目中创建构建脚本:
from cpm_build import DjinniBuild
djinni_build = DjinniBuild(lib_name='my_library')
djinni_build.main()
然后通过命令行参数指定目标平台和架构:
# 构建 Android (armv8 + x86_64) 并打包为 AAR
python build.py --android armv8 x86_64 --package aar
# 构建 iOS + macOS 并打包为 XCFramework
python build.py --iphoneos armv8 --iphonesimulator armv8 x86_64 --macos armv8 x86_64 --package xcframework
# 构建 XCFramework 并生成 Swift Package
python build.py --iphoneos armv8 --iphonesimulator armv8 x86_64 --macos armv8 x86_64 --package xcframework swiftpackage
# 构建 Windows (x64) 并打包为 NuGet
python build.py --windows x86_64 --package nuget
# 构建 Linux (x86_64)
python build.py --linux x86_64
# 使用 Debug 模式构建
python build.py --android armv8 --configuration debug
命令行参数
| 参数 | 说明 | 默认值 |
|---|---|---|
--configuration {release,debug} |
构建配置(Release 或 Debug) | release |
--android [ARCH ...] |
构建 Android 平台,可指定架构 | — |
--iphoneos [ARCH ...] |
构建 iOS 真机平台,可指定架构 | — |
--iphonesimulator [ARCH ...] |
构建 iOS 模拟器平台,可指定架构 | — |
--macos [ARCH ...] |
构建 macOS 平台,可指定架构 | — |
--windows [ARCH ...] |
构建 Windows 平台,可指定架构 | — |
--linux [ARCH ...] |
构建 Linux 平台,可指定架构 | — |
--build-directory PATH |
构建输出目录 | build/ |
--build-profile PROFILE |
Conan 构建 Profile 名称 | default |
--package [TYPE ...] |
打包类型:xcframework、swiftpackage、aar、nuget |
— |
支持的架构
| 架构 | Conan 名称 | Android 名称 | Windows 名称 |
|---|---|---|---|
x86_64 |
x86_64 | x86_64 | win10-x64 |
x86 |
x86 | x86 | win10-x86 |
armv8 |
armv8 | arm64-v8a | win10-arm64 |
armv7 |
armv7 | armeabi-v7a | win10-arm |
项目结构
cpm-build/
├── profiles/ # Conan 构建 Profile(各平台配置)
│ ├── android # Android NDK Profile
│ ├── ios # iOS SDK Profile
│ ├── macos # macOS Profile
│ ├── windows # Windows MSVC Profile
│ └── linux # Linux GCC Profile
├── cpm_build/ # Python 主包
│ ├── __init__.py # 包入口,导出 DjinniBuild
│ ├── djinni_build.py # 主编排类,CLI 入口
│ ├── build_context.py # 构建上下文基类
│ ├── android_build_context.py # Android 构建逻辑
│ ├── darwin_build_context.py # iOS / macOS 构建逻辑
│ ├── windows_build_context.py # Windows 构建逻辑
│ ├── linux_build_context.py # Linux 构建逻辑
│ ├── argparse_enums.py # CLI 枚举定义
│ └── print_prefixed.py # 日志输出工具
├── .github/workflows/publish.yml # CI/CD:自动发布到 PyPI
├── setup.py # 包安装配置
├── requirements.txt # 开发依赖
├── LICENSE # MIT 许可证
└── README.md # 项目文档
DjinniBuild 配置参数
DjinniBuild 类支持以下初始化参数,用于自定义构建行为:
| 参数 | 类型 | 说明 | 默认值 |
|---|---|---|---|
lib_name |
str |
库名称(必填) | — |
default_build_dir |
Path |
默认构建输出目录 | build/ |
default_conan_build_profile |
str | Path |
默认 Conan 构建 Profile | default |
working_directory |
Path |
项目根目录 | 当前工作目录 |
darwin_target_dir |
Path |
Darwin 平台目标定义路径 | lib/platform/darwin |
android_target_dir |
Path |
Android 平台目标定义路径 | lib/platform/android |
windows_target_dir |
Path |
Windows 平台目标定义路径 | lib/platform/windows |
android_profile |
str | Path |
Android Conan Profile 路径 | 内置 Profile |
macos_profile |
str | Path |
macOS Conan Profile 路径 | 内置 Profile |
ios_profile |
str | Path |
iOS Conan Profile 路径 | 内置 Profile |
windows_profile |
str | Path |
Windows Conan Profile 路径 | 内置 Profile |
linux_profile |
str | Path |
Linux Conan Profile 路径 | 内置 Profile |
nupkg_dir |
Path |
NuGet 包模板目录 | lib/platform/windows/package |
android_project_dir |
Path |
Android 项目目录(用于 AAR 构建) | lib/platform/android/package |
swiftpackage_dir |
Path |
Swift Package 目录 | lib/platform/darwin/package |
许可证
本项目基于 MIT 许可证 开源。
Copyright (c) 2025 pyoneer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpm_build-0.1.0.tar.gz.
File metadata
- Download URL: cpm_build-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.33.1 requests-toolbelt/1.0.0 urllib3/2.6.3 tqdm/4.67.3 importlib-metadata/9.0.0 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb08007ff67fbc0b0935ab235ffa50e7c466eae3b57f0eac1a1b20b56e5a142
|
|
| MD5 |
068d29fc54654fca88bac47ff959ae09
|
|
| BLAKE2b-256 |
758234e52f23e943bea3a65f5d2c3294535fae4b309e64954066bf9a9429c30c
|
File details
Details for the file cpm_build-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cpm_build-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.33.1 requests-toolbelt/1.0.0 urllib3/2.6.3 tqdm/4.67.3 importlib-metadata/9.0.0 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74beb140c11d29f99fec488ca2406c37e30a4588ce8c113c2071059a8c36134d
|
|
| MD5 |
e042ed9e7928254dda08c573464255ea
|
|
| BLAKE2b-256 |
aece15bb95b5fce2c96359e310a3b3c2690b284456bbaeea5cd9b8ad5683f30b
|