Skip to content

Standardize Python packaging and isolate bundled MLIR - #561

Draft
mouliangyu wants to merge 19 commits into
feature-vmifrom
codex/standardize-python-packaging
Draft

Standardize Python packaging and isolate bundled MLIR#561
mouliangyu wants to merge 19 commits into
feature-vmifrom
codex/standardize-python-packaging

Conversation

@mouliangyu

@mouliangyu mouliangyu commented Jul 22, 2026

Copy link
Copy Markdown
Owner

背景

PTOAS 原先通过自定义 PEP 517 backend、setup.py、wheel bootstrap、运行时路径扫描和多套发布脚本维护 Python 包。这些代码重复承担了标准打包工具已有的 metadata、editable install、console script、wheel 组装和 native dependency repair,也使 CLI、PTODSL、CI、wheel 和 standalone archive 显式依赖源码树、LLVM build tree 或旧 install tree 的内部布局。

同时,直接发布顶层 mlir 包会与进程中其他 MLIR Python distribution 冲突。PTOAS 需要拥有一套自洽的 MLIR Python runtime,并与自己的 compiler native module 共享同一个 MLIR CAPI。

本 PR 将 Python 构建与发布链路收敛到 scikit-build-core、AddMLIRPython 和标准平台 repair 工具,并把 PTOAS 自带的 MLIR runtime 隔离到 ptoas.mlir

修改内容

  • 使用 scikit-build-core 作为标准 PEP 517/660 backend:
    • 根项目发布 ptoas
    • packaging/ptoas-vmi 发布 ptoas-vmi
    • 两个 distribution 共享 CMake 构建图、Python package 和 console script;
    • 支持标准 wheel 与 editable install,不再维护自定义 backend、setup.py 或 wheel bootstrap。
  • 将 PTOAS 自带的 MLIR Python runtime 放到项目命名空间:
    • public import 改为 ptoas.mlirptoas.mlir.dialects.pto
    • 设置 MLIR_PYTHON_PACKAGE_PREFIX=ptoas.mlir.
    • 使用独立 nanobind domain ptoas_mlir
    • 不再安装或兼容 alias 到顶层 mlir
  • 使用 AddMLIRPython 的声明式 source graph 构建 MLIR Python package:
    • 显式选择 PTOAS/PTODSL 使用的 upstream dialect;
    • 使用标准 site initializer 注册 PTO dialect 依赖;
    • 保留一个 package-owned PTOASPythonCAPI
    • 上游 MLIR/nanobind 生成源码局部免除 -Werror,PTOAS 自有 binding 和 compiler 代码继续保持 -Werror
  • 将 native compiler 统一为 ptoas._core
    • LLVM driver sources 作为 object library 保持 LLVM 的 RTTI/exception 编译模式;
    • Python binding translation units 保持 pybind11 所需的 RTTI/exception;
    • CLI 和 PTODSL 通过正常 Python import 使用 _core,不再扫描 native library 路径。
  • 统一 CLI 与运行时路径契约:
    • wheel console script 使用 ptoas._cli:main
    • build/install/archive wrapper 只添加各自 tree 对应的 Python root;
    • PTODSL 查找编译器时只接受显式 PTOAS_BIN,否则使用标准 PATH
    • 删除 _bootstrap.py_launcher_runtime_entry 和跨仓库/build/install tree 的路径猜测。
  • 标准化 wheel 和开发环境:
    • quick_install.sh 使用标准 editable install;
    • CI 与 simulator CI 使用 workflow-owned venv 和 editable install;
    • lit 从 CMake 获取匹配的 MLIR Python package;
    • Linux wheel 使用 auditwheel repair,macOS wheel 使用 delocate-wheel
    • wheel payload、isolated install、import、CLI 和编译流程由 workflow 验证。
  • 重构 standalone compiler archive:
    • PTOAS_PythonPTOAS_CompilerArchive 两个 CMake component 组装受控 install tree;
    • 普通 Python/resource/ABI marker 由标准 install rules 管理;
    • install-time deployment script 使用 CMake target 元数据确定 _corePTOASPythonCAPI,仅在 AddMLIRPython 的 _mlir_libs 边界扫描自动生成 modules;
    • 使用 file(GET_RUNTIME_DEPENDENCIES) 收集外部依赖,检测 unresolved 和同名 ABI 冲突;
    • Linux 根据实际目录关系生成 $ORIGIN RPATH,macOS 使用 delocate-path
    • 删除原有 Linux/macOS shell collectors,workflow 只安装 component、归档 install tree 并 smoke test。
  • 同步更新 README、构建文档、设计文档、PTODSL/TileLang imports、samples 和测试。

验证

  • CMake/native build 成功。
  • Build-tree import:
    • from ptoas.mlir import ir 通过;
    • from ptoas.mlir.dialects import pto 通过;
    • import ptodsl 通过;
    • 顶层 import mlir 不再由 PTOAS 提供。
  • PTODSL/TileLang CTest:25/25 通过。
  • check-pto:1384/1388 通过;剩余 4 个 A3 tadd FileCheck failure 为本分支已有问题,与 Python packaging 无关。
  • 完整 CTest 除已有 ptobc_stage9_e2e 外通过。
  • raw wheel 构建、payload 校验、隔离 venv 安装、import 和 CLI 通过。
  • standalone archive Linux staging 与 relocation 通过:
    • archive 中 242 个 ELF 文件无 unresolved dependency;
    • 所有 native RPATH 均为 archive-relative,无源码树、build tree 或 LLVM absolute path;
    • 清除 PYTHONPATHLD_LIBRARY_PATHDYLD_LIBRARY_PATH 后,ptoas --version 和代表性 .pto 编译通过。
  • workflow YAML 解析、skill 校验和 git diff --check 通过。

验证范围说明

  • 本地 auditwheel repair --plat manylinux_2_34 受本机编译器生成的新版本 glibc/libstdc++ symbols 限制;manylinux runner 上的实际 repair、wheel install 和 smoke test由 build_wheel.yml 覆盖。
  • macOS wheel/archive 的 delocate、安装和 smoke test由 build_wheel_mac.yml 覆盖,本地 Linux 环境未执行 macOS runtime 验证。
  • ptobc_stage9_e2e 和上述 4 个 A3 tadd failure 未在本 PR 中扩展范围处理。

@mouliangyu
mouliangyu force-pushed the codex/standardize-python-packaging branch from 85332a3 to 1373186 Compare July 23, 2026 06:36
@mouliangyu
mouliangyu force-pushed the feature-vmi branch 2 times, most recently from 84a34b5 to 04d95b2 Compare July 23, 2026 09:32
@mouliangyu
mouliangyu force-pushed the codex/standardize-python-packaging branch from 1373186 to e4f3672 Compare July 23, 2026 10:44
@mouliangyu mouliangyu changed the title Refactor Python packaging with scikit-build-core Standardize Python packaging and isolate bundled MLIR Jul 27, 2026
@mouliangyu
mouliangyu force-pushed the codex/standardize-python-packaging branch from f8c139c to 4b86886 Compare July 27, 2026 14:17
@mouliangyu
mouliangyu force-pushed the codex/standardize-python-packaging branch from 376ff6e to fa9b629 Compare July 28, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant