Skip to content

Add minimal HWP writer path for Swift#879

Closed
ubermensch1218 wants to merge 2 commits into
edwardkim:ios/develfrom
ubermensch1218:hwp-writer-red-tests
Closed

Add minimal HWP writer path for Swift#879
ubermensch1218 wants to merge 2 commits into
edwardkim:ios/develfrom
ubermensch1218:hwp-writer-red-tests

Conversation

@ubermensch1218
Copy link
Copy Markdown

@ubermensch1218 ubermensch1218 commented May 13, 2026

Summary

  • Add Rust writer contract tests for .hwp output from an editable blank document
  • Expose rhwp_write_text(output_path, text) in the native FFI
  • Add Rhwp.writeText(_:outputFile:) and RhwpWriteResult in the Swift package
  • Add a direct write_text_ffi.swift example and README usage notes

Tests

  • cargo test --lib hwp_writer_contract -- --nocapture
  • cargo test --manifest-path bindings/Native/Cargo.toml write_text_to_file_creates_reloadable_hwp
  • cargo build --manifest-path bindings/Native/Cargo.toml
  • swift test -Xlinker -L../../bindings/Native/target/debug
  • cargo build --manifest-path bindings/Native/Cargo.toml --release && swift bindings/swift/Examples/write_text_ffi.swift output/ffi-created.hwp "한글 English 123" && swift bindings/swift/Examples/read_text_ffi.swift output/ffi-created.hwp 0
  • ./scripts/package-swift-xcframework.sh
  • nm -g dist/swift/build/RhwpNative.xcframework/{macos-arm64_x86_64/librhwp_native_ffi-macos.a,ios-arm64-simulator/librhwp_native_ffi-ios-simulator.a,ios-arm64/librhwp_native_ffi.a} | rg rhwp_write_text
  • git diff --check

Notes

  • The first writer API is intentionally file-based to match the existing JSON FFI pattern and avoid introducing a byte-buffer ownership ABI in this patch.
  • This creates single-paragraph .hwp files from plain text; richer document-building APIs can layer on top later.

The writer path already has a native export entry point, but it lacked a small public-facing contract that proves a blank editable HWP can serialize, reload, and preserve mixed text after insertion. This adds that seam at the WASM/native wrapper level without expanding writer implementation scope.

Constraint: Follow-on writer work should target .hwp output first and keep Swift/iOS work on top of a stable Rust writer contract.

Rejected: Use HWPX generation as the first contract | the current milestone is HWP writer introduction, not HWPX export.

Confidence: high

Scope-risk: narrow

Directive: Do not weaken the FileHeader, DocInfo, and BodyText/Section0 assertions without replacing them with an equivalent HWP validity check.

Tested: cargo test --lib hwp_writer_contract -- --nocapture

Tested: cargo test --lib test_export_hwp_empty -- --nocapture

Tested: git diff --check
The Apple binding now needs a creation path, not only read/export extraction. This adds the smallest writer surface: create a blank editable HWP, insert one text body, serialize .hwp bytes, write them to a caller-provided file, and verify the bytes reload before reporting success.

Constraint: Keep the first writer API file-based to match the existing JSON FFI pattern and avoid introducing byte-buffer ownership rules in this patch.

Rejected: Return raw HWP bytes over FFI | would require a new allocator/free contract and larger Swift ownership surface.

Rejected: Start with HWPX output | the active writer milestone is .hwp generation first.

Confidence: high

Scope-risk: moderate

Directive: Preserve rhwp_write_text as the minimal compatibility path when adding richer document-building APIs.

Tested: cargo test --manifest-path bindings/Native/Cargo.toml write_text_to_file_creates_reloadable_hwp

Tested: cargo build --manifest-path bindings/Native/Cargo.toml

Tested: swift test -Xlinker -L../../bindings/Native/target/debug

Tested: cargo build --manifest-path bindings/Native/Cargo.toml --release && swift bindings/swift/Examples/write_text_ffi.swift output/ffi-created.hwp "한글 English 123" && swift bindings/swift/Examples/read_text_ffi.swift output/ffi-created.hwp 0

Tested: ./scripts/package-swift-xcframework.sh

Tested: nm -g dist/swift/build/RhwpNative.xcframework/{macos-arm64_x86_64/librhwp_native_ffi-macos.a,ios-arm64-simulator/librhwp_native_ffi-ios-simulator.a,ios-arm64/librhwp_native_ffi.a} | rg rhwp_write_text

Tested: cargo test --lib hwp_writer_contract -- --nocapture

Tested: git diff --check
@ubermensch1218 ubermensch1218 changed the title Add HWP writer contract tests Add minimal HWP writer path for Swift May 13, 2026
@edwardkim edwardkim self-requested a review May 14, 2026 08:45
@edwardkim edwardkim added the enhancement New feature or request label May 14, 2026
edwardkim pushed a commit that referenced this pull request May 14, 2026
… API

PR #879 (@ubermensch1218) cherry-pick.

- src/wasm_api/tests.rs — HWP writer contract 테스트 2건 (blank roundtrip + text roundtrip)
- bindings/Native/src/lib.rs — rhwp_write_text FFI (blank editable HWP + text insert + serialize)
- bindings/swift — Rhwp.writeText + RhwpWriteResult + write_text_ffi.swift 예제 + 테스트

검증:
- cargo test --release --lib hwp_writer_contract: 2 passed
- swift test: 5 passed (+1 신규 write)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@edwardkim
Copy link
Copy Markdown
Owner

Cherry-picked into ios/devel. Thanks!

What was merged

  • HWP writer contract tests (blank + text roundtrip)
  • rhwp_write_text FFI function
  • Rhwp.writeText Swift API + RhwpWriteResult
  • write_text_ffi.swift example
  • Swift test (+1 write)

Verification

Test Result
cargo test hwp_writer_contract 2 passed
swift test 5 passed (+1 new)

Good step-by-step progression from read (#845) to write. Keep it up!

@edwardkim edwardkim closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants