Skip to main content

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(用于自动版本号提取)
  • 各平台工具链:

安装

通过 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 —

Android C++ Runtime

Android Profile 默认使用 compiler.libcxx=c++_shared。这会让生成的 Android native library 动态依赖同一个 libc++_shared.so,避免 Djinni wrapper 把 C++ runtime 静态链接进自身并导出 std::__ndk1 / __cxa_* 符号。集成多个 AAR 时,应由最终 App 统一决定打包哪一个 libc++_shared.so。

支持的架构

架构 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

Metadata

Release files for cpm-build 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpm-build 0.2.2
File Size Uploaded Provenance Actions
cpm_build-0.2.2.tar.gz 15.1 kB Without provenance Details for cpm_build-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cpm-build 0.2.2
File Interpreter ABI Platform Actions
cpm_build-0.2.2-py3-none-any.whl Python 3 none any Details for cpm_build-0.2.2-py3-none-any.whl

Total release size: 30.8 kB

Release files / cpm_build-0.2.2.tar.gz

Download URL cpm_build-0.2.2.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
958d2d90608b2a8190b3b4b26a3c302d1a0d1071f7a1d1d34b86603b874398cb
BLAKE2b-256 checksum
How to use checksums
43edf8f71f3a6bbbe98775ab07dba592dc242a76a5d9914313d4c47353353b2c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / cpm_build-0.2.2-py3-none-any.whl

Download URL cpm_build-0.2.2-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a7e6df26bd7f1d27babcb024a7eb451a288bdc627546570271de78006e0766f
BLAKE2b-256 checksum
How to use checksums
5d71ca42fe0700eaafdb99f816eda1c0f6105cc52552dba6d94d3e6f33fd44d1
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for cpm-build 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page