Add minimal HWP writer path for Swift#879
Closed
ubermensch1218 wants to merge 2 commits into
Closed
Conversation
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
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>
Owner
|
Cherry-picked into What was merged
Verification
Good step-by-step progression from read (#845) to write. Keep it up! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.hwpoutput from an editable blank documentrhwp_write_text(output_path, text)in the native FFIRhwp.writeText(_:outputFile:)andRhwpWriteResultin the Swift packagewrite_text_ffi.swiftexample and README usage notesTests
cargo test --lib hwp_writer_contract -- --nocapturecargo test --manifest-path bindings/Native/Cargo.toml write_text_to_file_creates_reloadable_hwpcargo build --manifest-path bindings/Native/Cargo.tomlswift test -Xlinker -L../../bindings/Native/target/debugcargo 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.shnm -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_textgit diff --checkNotes
.hwpfiles from plain text; richer document-building APIs can layer on top later.