Skip to content

fix(unrar_sys): add iOS/tvOS/watchOS cross-compilation support - #74

Open
darktasevski wants to merge 9 commits into
muja:masterfrom
darktasevski:fork-extensions
Open

darktasevski wants to merge 9 commits into
muja:masterfrom
darktasevski:fork-extensions

Conversation

@darktasevski

@darktasevski darktasevski commented Jan 9, 2026 •

Copy link
Copy Markdown

Cross-compiling for Apple mobile targets fails with linker errors:

Phase 1 - Missing C++ symbols:

Undefined symbols for architecture arm64:
  "___cxa_allocate_exception", "___cxa_throw", "___gxx_personality_v0"

Phase 2 - After adding -lc++ workaround:

ld: warning: object file was built for newer 'iOS' version (26.1) than being linked (10.0)
Undefined symbols: "___chkstk_darwin"

Two issues in unrar_sys/build.rs:

  1. Line 65: .cpp_link_stdlib(None) disables C++ stdlib linking globally, but iOS requires libc++

  2. No iOS SDK configuration: The cc crate compiles with default macOS SDK settings, producing object files with mismatched iOS version metadata

Solution

  • Detect Apple mobile targets via CARGO_CFG_TARGET_OS environment variable
  • Link libc++ explicitly for iOS/tvOS/watchOS
  • Set deployment target flags (-mios-version-min=12.0, etc.) to match Rust's expectations
  • Only disable cpp_link_stdlib on Windows GNU where it was originally needed

All iOS/tvOS/watchOS targets:

  • aarch64-apple-ios
  • aarch64-apple-ios-sim
  • x86_64-apple-ios
  • aarch64-apple-ios-macabi (Mac Catalyst)
  • x86_64-apple-ios-macabi
  • aarch64-apple-tvos / aarch64-apple-tvos-sim
  • aarch64-apple-watchos / aarch64-apple-watchos-sim

I verified successful compilation for:

  • aarch64-apple-ios (device)
  • aarch64-apple-ios-sim (simulator)

Closes #73 - Unable to cross-compile for iOS (aarch64-apple-ios)

@darktasevski
darktasevski force-pushed the fork-extensions branch 3 times, most recently from 1910b1b to 31732f2 Compare April 6, 2026 06:26
Add StreamingEntry type implementing std::io::Read that bridges the
C library's push-based UCM_PROCESSDATA callbacks with pull-based Rust
Read via a bounded sync_channel(4) and per-entry producer thread.

This closes the transient OOM window where crafted RAR archives with
spoofed unpacked_size headers could cause unbounded memory allocation.
All four archive formats (CBZ, CB7, CBT, CBR) now use the same
.take(limit) pattern for bounded reads.

Key changes in unrar crate:
- StreamingEntry with impl Read, finish(), set_discard()
- Streaming callback with p2 bounds validation and discard mode
- unsafe impl Send for Handle (TLS audit passed for unrar v7.1)
- Drop with mandatory 5s timeout and mem::forget fallback
- Shared volume-change handler extracted from existing callback
- Backported p2 bounds validation to existing callback
- 9 unit tests covering streaming, solid archives, abort, discard

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Formatting only — no semantic change in any hunk. HEAD did not satisfy
cargo fmt --check; this is exactly the diff it produces.
…gerprint-cancellation

Join streaming producers on drop and format the streaming tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to cross-compile for iOS (aarch64-apple-ios)

1 participant