From 3125d7f5f972779cd528f5c6ebc596242b9ab1b0 Mon Sep 17 00:00:00 2001 From: DanMeon Date: Sun, 3 May 2026 13:29:15 +0900 Subject: [PATCH] =?UTF-8?q?build:=20cargo=20test=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20PyO3=20extensio?= =?UTF-8?q?n-module=20feature=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 변경사항: - Cargo.toml: pyo3 dependency 의 default features 에서 extension-module 제거 - Cargo.toml: [features] extension-module = ["pyo3/extension-module"] 섹션 추가 — wheel 빌드 시에만 활성화 - pyproject.toml: [tool.maturin] features 를 자기 crate 의 extension-module 가리키도록 변경 (wheel 빌드 동작 동일) - .github/workflows/ci.yml: cargo-test job 추가 (Rust unit test 13개 실행, src/ir.rs 의 #[should_panic] 검증 포함) - .github/workflows/ci.yml: all-tests-passed aggregator 의 needs/allowed-skips 에 cargo-test 등록 Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++-- Cargo.toml | 9 ++++++++- pyproject.toml | 4 +++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37de190..c407ed4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -186,6 +186,26 @@ jobs: - run: uv pip install --reinstall dist/*.whl - run: uv run pytest tests/ -m slow -v + # * Rust unit tests — src/ir.rs 의 #[cfg(test)] 모듈 실행 + # Cargo.toml 의 default features 에서 extension-module 이 빠져 있어 libpython 링크 시도 안 함. + # utf16_to_cp / simple_eq_text_alt / field_type_to_str / caption_direction_to_str / + # assert_position_invariant (#[should_panic]) 검증 — Python 측에서 우회 불가능한 Rust 도메인 로직. + cargo-test: + name: Cargo test (Rust unit tests) + needs: changes + if: needs.changes.outputs.code == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + submodules: recursive + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Run cargo test (default features — extension-module disabled) + run: cargo test --lib + # * extras 미설치 시 langchain 테스트가 importorskip 로 auto-skip 되는지 검증 test-core-only: name: Test without extras (importorskip auto-skip) @@ -227,9 +247,9 @@ jobs: name: All tests passed if: always() runs-on: ubuntu-latest - needs: [changes, build-linux-wheel, test, test-other-os, test-slow, test-core-only] + needs: [changes, build-linux-wheel, test, test-other-os, test-slow, test-core-only, cargo-test] steps: - uses: re-actors/alls-green@release/v1 with: jobs: ${{ toJSON(needs) }} - allowed-skips: build-linux-wheel, test, test-other-os, test-slow, test-core-only + allowed-skips: build-linux-wheel, test, test-other-os, test-slow, test-core-only, cargo-test diff --git a/Cargo.toml b/Cargo.toml index f9cd6ee..8b5fdcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,15 @@ include = [ name = "_rhwp" crate-type = ["cdylib", "rlib"] +# * extension-module 을 default features 에서 분리한다 — wheel 빌드 시에만 활성화 +# cargo test 는 default 로 비활성 → libpython 링크 시도 회피 → Rust unit test 실행 가능 +# ([PyO3 FAQ](https://pyo3.rs/main/faq#i-cant-run-cargo-test) 권장 패턴). +# maturin 은 [tool.maturin] features 에서 명시적으로 ["extension-module"] 활성화하므로 wheel 영향 0. +[features] +extension-module = ["pyo3/extension-module"] + [dependencies] -pyo3 = { version = "0.28", features = ["extension-module", "abi3-py310"] } +pyo3 = { version = "0.28", features = ["abi3-py310"] } rhwp = { path = "external/rhwp" } [profile.release] diff --git a/pyproject.toml b/pyproject.toml index 107aae4..3ed182b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,7 +100,9 @@ all = [ python-source = "python" module-name = "rhwp._rhwp" bindings = "pyo3" -features = ["pyo3/extension-module"] +# ^ wheel 빌드 시 자기 crate 의 extension-module feature 를 켠다 (Cargo.toml [features] 정의). +# Cargo.toml 의 default features 에서는 extension-module 이 빠져 있어 cargo test 가 정상 작동. +features = ["extension-module"] include = [ { path = "python/rhwp/py.typed", format = "wheel" }, { path = "python/rhwp/**/*.pyi", format = "wheel" },