layouttk 0.1.0

Integer-grid GDSII and OASIS layout processing with hierarchy-aware extraction
Documentation
# 发布 layouttk

Cargo 和 Python 的发布版本都取自 `Cargo.toml` 的 `package.version`。推送与该版本完全匹配的标签,例如 `v0.1.0`,会启动两个注册表的正式发布。Python 发行物包含一个 sdist,以及以下三个常规 CPython 3.11+ 的 `abi3` wheel。

| 平台 | 架构 | CI 安装测试 |
| --- | --- | --- |
| Linux,glibc 2.28 及以上 | x86_64 | CPython 3.11 |
| macOS | arm64 | CPython 3.13 |
| Windows | x64 | CPython 3.13 |

每个平台都会执行 gdstk、KLayout、NumPy 和 PyTorch 测试。测试范围、运行摘要和下载步骤见[三平台 wheel 验证](ci.md)。

## 发布前验证

1. 更新 `Cargo.toml` 和 `Cargo.lock`。依赖有变化时运行 `python scripts/license_notices.py`,将更新后的许可证汇编一起提交。
2. 在准备发布的提交上运行 GitHub Actions 的 **CI**。`main` 分支推送和拉取请求会自动运行,也可在 Actions 中点 **Run workflow**。CI 使用 Rust 1.100.1 构建发行包,并在最低支持版本 Rust 1.95 上独立运行测试。检查项还包括格式、Clippy、Rust 与 CLI 测试、RustSec 依赖公告、许可证汇编以及 `cargo publish --locked --dry-run`。它还会从 sdist 构建并导入扩展,在三个目标平台安装各自产出的 wheel,用 gdstk 和 KLayout 做双向互读,并检查 Python 元数据、平台标签及发行包内的许可证文件。运行产物可从 Actions 下载。[Cargo 发布检查](https://doc.rust-lang.org/cargo/commands/cargo-publish.html)
3. 本地可用 `python3 scripts/release.py tag v0.1.0` 核对标签。将示例版本替换为待发布版本。Python 需要 3.11 或以上。

Dependabot 每周检查 Cargo 依赖和已固定提交的 GitHub Actions。合入依赖更新前,按第一步刷新许可证汇编。RustSec 检查在每次 CI 运行时读取最新公告库;升级其 CLI 时,应同步更新工作流中的版本和官方 Linux 归档的 SHA-256。[Dependabot 配置](https://docs.github.com/en/code-security/reference/supply-chain-security/dependabot-options-reference) · [RustSec cargo-audit](https://github.com/rustsec/rustsec/releases/tag/cargo-audit%2Fv0.23.0)

## 两个注册表的首次设置

在 GitHub 仓库 Settings → Environments 创建 `pypi` 和 `crates-io`。为这两个环境选择允许部署的标签模式 `v*`。仓库规则集可以限制谁有权创建、修改及删除这些标签。[GitHub 环境设置](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments)

| 字段 | PyPI | crates.io |
| --- | --- | --- |
| 项目 | `layouttk` | `layouttk` |
| GitHub 仓库 | `zwh42/layouttk` | `zwh42/layouttk` |
| 工作流文件名 | `release.yml` | `release.yml` |
| GitHub 环境名 | `pypi` | `crates-io` |

**PyPI** 在账户的 Publishing 页面为新项目添加上表中的 pending publisher。首次通过 OIDC 上传后,PyPI 自动创建项目并启用后续发布。登记和首次上传之间,项目名仍可被他人注册。已有项目则从项目的 Publishing 页面添加发布者。[PyPI 首次发布](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/) · [已有项目的发布设置](https://docs.pypi.org/trusted-publishers/adding-a-publisher/)

**crates.io** 先验证维护者账户的邮箱。新 crate 的首次上传需要一次性使用账户 API token。在 CI 已通过的精确提交上,用干净检出和与 CI 相同的 Cargo 版本执行以下命令。运行 `cargo login` 时在交互提示中输入 token。正式上传前可将本机生成的 `.crate` 与该提交 CI 的 `rust-crate` 产物按 SHA-256 核对。[Cargo 首发说明](https://doc.rust-lang.org/cargo/reference/publishing.html) · [crates.io 官方首发要求](https://blog.rust-lang.org/2025/07/11/crates-io-development-update-2025-07/)

```sh
rustup toolchain install 1.100.1 --profile minimal
cargo +1.100.1 publish --locked --dry-run
cargo +1.100.1 package --locked --no-verify
cargo +1.100.1 login
cargo +1.100.1 publish --locked
cargo +1.100.1 logout
```

首次上传成功后,撤销这枚 token,进入该 crate 的 Trusted Publishing 设置,登记上表中的仓库、工作流和环境。可进一步启用仅允许 Trusted Publishing。之后所有版本都由发布任务换取短时凭据。[crates.io Trusted Publishing](https://crates.io/docs/trusted-publishing) · [短时凭据 Action](https://github.com/rust-lang/crates-io-auth-action)

## 推送标签与恢复中断

确认上述发布条件就绪后,从通过 CI 的提交推送标签。以下命令会触发正式发布。

```sh
git tag -a v0.1.0 -m "layouttk 0.1.0"
git push origin v0.1.0
```

Release 工作流会在标签提交上重新运行完整 CI。两个注册表随后独立发布。PyPI 直接使用该次 CI 测过的 wheel 和 sdist;crates.io 任务用同一工具链重新打包,逐字节比对 CI 的 `.crate` 后上传。两个发布任务分别在各自的 GitHub 环境中取得 OIDC 权限。[PyPI 发布 Action](https://github.com/pypa/gh-action-pypi-publish)

某一端失败时,修复环境或注册表配置,然后在**原运行**选择 **Re-run failed jobs**。这样会使用同一标签提交和已成功构建的文件。crates.io 已有相同版本时,工作流要求已发布归档与本地 SHA-256 相同。PyPI 支持补传缺失文件,随后逐一比对发布件的 SHA-256。任何已撤回的同名文件或校验和冲突都会报错。调查确认需要更换公开内容时,递增版本并创建新标签。[GitHub 重跑语义](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/re-run-workflows-and-jobs) · [PyPI 文件摘要 API](https://docs.pypi.org/api/json/)