Skip to content

Commit a264820

Browse files
authored
Merge pull request #13 from DanMeon/build/cargo-test-feature-flag
build: cargo test 실행 가능하도록 PyO3 extension-module feature 분리
2 parents 69e25dd + 3125d7f commit a264820

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,26 @@ jobs:
186186
- run: uv pip install --reinstall dist/*.whl
187187
- run: uv run pytest tests/ -m slow -v
188188

189+
# * Rust unit tests — src/ir.rs 의 #[cfg(test)] 모듈 실행
190+
# Cargo.toml 의 default features 에서 extension-module 이 빠져 있어 libpython 링크 시도 안 함.
191+
# utf16_to_cp / simple_eq_text_alt / field_type_to_str / caption_direction_to_str /
192+
# assert_position_invariant (#[should_panic]) 검증 — Python 측에서 우회 불가능한 Rust 도메인 로직.
193+
cargo-test:
194+
name: Cargo test (Rust unit tests)
195+
needs: changes
196+
if: needs.changes.outputs.code == 'true'
197+
runs-on: ubuntu-latest
198+
steps:
199+
- uses: actions/checkout@v6
200+
with:
201+
submodules: recursive
202+
- uses: dtolnay/rust-toolchain@stable
203+
- uses: Swatinem/rust-cache@v2
204+
with:
205+
save-if: ${{ github.ref == 'refs/heads/main' }}
206+
- name: Run cargo test (default features — extension-module disabled)
207+
run: cargo test --lib
208+
189209
# * extras 미설치 시 langchain 테스트가 importorskip 로 auto-skip 되는지 검증
190210
test-core-only:
191211
name: Test without extras (importorskip auto-skip)
@@ -227,9 +247,9 @@ jobs:
227247
name: All tests passed
228248
if: always()
229249
runs-on: ubuntu-latest
230-
needs: [changes, build-linux-wheel, test, test-other-os, test-slow, test-core-only]
250+
needs: [changes, build-linux-wheel, test, test-other-os, test-slow, test-core-only, cargo-test]
231251
steps:
232252
- uses: re-actors/alls-green@release/v1
233253
with:
234254
jobs: ${{ toJSON(needs) }}
235-
allowed-skips: build-linux-wheel, test, test-other-os, test-slow, test-core-only
255+
allowed-skips: build-linux-wheel, test, test-other-os, test-slow, test-core-only, cargo-test

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ include = [
3434
name = "_rhwp"
3535
crate-type = ["cdylib", "rlib"]
3636

37+
# * extension-module 을 default features 에서 분리한다 — wheel 빌드 시에만 활성화
38+
# cargo test 는 default 로 비활성 → libpython 링크 시도 회피 → Rust unit test 실행 가능
39+
# ([PyO3 FAQ](https://pyo3.rs/main/faq#i-cant-run-cargo-test) 권장 패턴).
40+
# maturin 은 [tool.maturin] features 에서 명시적으로 ["extension-module"] 활성화하므로 wheel 영향 0.
41+
[features]
42+
extension-module = ["pyo3/extension-module"]
43+
3744
[dependencies]
38-
pyo3 = { version = "0.28", features = ["extension-module", "abi3-py310"] }
45+
pyo3 = { version = "0.28", features = ["abi3-py310"] }
3946
rhwp = { path = "external/rhwp" }
4047

4148
[profile.release]

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ all = [
100100
python-source = "python"
101101
module-name = "rhwp._rhwp"
102102
bindings = "pyo3"
103-
features = ["pyo3/extension-module"]
103+
# ^ wheel 빌드 시 자기 crate 의 extension-module feature 를 켠다 (Cargo.toml [features] 정의).
104+
# Cargo.toml 의 default features 에서는 extension-module 이 빠져 있어 cargo test 가 정상 작동.
105+
features = ["extension-module"]
104106
include = [
105107
{ path = "python/rhwp/py.typed", format = "wheel" },
106108
{ path = "python/rhwp/**/*.pyi", format = "wheel" },

0 commit comments

Comments
 (0)