Skip to content

Improve iOS Library Linking #22

@tinyjin

Description

@tinyjin

Current Issues

1. Dynamic Library Limitations

  • Currently using .dylib for iOS which causes App Store submission issues
  • Dynamic libraries are restricted in iOS App Store distribution
  • Complex code signing requirements for dynamic libraries
  • Runtime loading overhead

2. Architecture Support Gaps

  • Missing ARM64 simulator support (Apple Silicon Macs)
  • Manual architecture management through lipo
  • Duplicate binaries for different architectures

Target Architecture Support Matrix

Architecture Device/Simulator Current Support With Source Inclusion
arm64 iOS Devices ✅ Supported ✅ Supported
x86_64 iOS Simulator (Intel Mac) ✅ Supported ✅ Supported
arm64 iOS Simulator (Apple Silicon) ❌ Not Supported ✅ Supported

Proposed Solution: Source Code Inclusion Approach

Overview

Instead of using dynamic libraries, we propose switching to direct source code inclusion through CocoaPods, which is the standard approach in the iOS ecosystem.

Benefits

  • ✅ Full App Store compliance
  • ✅ Automatic architecture support (including ARM64 simulator)
  • ✅ Simplified build process
  • ✅ Better performance (compile-time optimization)
  • ✅ Reduced app size (only needed code is included)

Implementation Details

1. Podspec Configuration

Pod::Spec.new do |s|
  s.name = 'thorvg'
  s.version = '1.0.0'
  
  # Selective source inclusion
  s.source_files = [
    'Classes/**/*',
    '../src/tvgFlutterLottieAnimation.{h,cpp}',
    '../thorvg/inc/thorvg.h',
    '../thorvg/src/common/**/*.{h,cpp}',
    '../thorvg/src/renderer/sw_engine/**/*.{h,cpp}',
    '../thorvg/src/loaders/lottie/**/*.{h,cpp}',
    '../thorvg/src/renderer/*.{h,cpp}'
  ]
  
  # Exclude unnecessary components
  s.exclude_files = [
    '../thorvg/src/renderer/gl_engine/**/*',
    '../thorvg/src/renderer/wg_engine/**/*',
    '../thorvg/src/bindings/**/*'
  ]
  
  # iOS build configuration
  s.pod_target_xcconfig = {
    'GCC_PREPROCESSOR_DEFINITIONS' => [
      'THORVG_STATIC=1',
      'THORVG_SW_RASTER_SUPPORT=1',
      'THORVG_LOTTIE_LOADER_SUPPORT=1'
    ].join(' '),
    'HEADER_SEARCH_PATHS' => [
      '$(PODS_TARGET_SRCROOT)/../thorvg/inc',
      '$(PODS_TARGET_SRCROOT)/../thorvg/src'
    ].join(' '),
    'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14',
    'VALID_ARCHS' => 'arm64 x86_64'
  }
  
  s.libraries = ['c++']
  s.platform = :ios, '11.0'
end

2. Update FFI Loading

final DynamicLibrary _dylib = () {
  if (Platform.isIOS) {
    return DynamicLibrary.process();  // Switch to process() for static linking
  }
  if (Platform.isAndroid) {
    return DynamicLibrary.open('libthorvg.so');  // Keep dynamic loading for Android
  }
  throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();

3. Architecture Support

This approach automatically supports all Apple architectures:

  • ✅ arm64 (iOS devices)
  • ✅ x86_64 (Intel Mac Simulator)
  • ✅ arm64 (Apple Silicon Mac Simulator)

4. Build Process Simplification

  • Removes need for manual architecture management
  • Eliminates complex build scripts
  • Leverages Xcode's native build system

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions