Class: AppleFrameworks::Fat

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_frameworks/fat.rb

Overview

Creates “fat” or “universal” libraries by combining two builds of the same library with different architectures.

Note: While it’s possible (and used to be recommended) to make a fat library for multiple platforms (iOS simulator and device), it’s no longer recommended to have these mixed in a single fat binary. For mixing platforms, use ‘XCFramework`.

Defined Under Namespace

Classes: CombineUsingLipoFailure

Instance Method Summary collapse

Constructor Details

#initialize(output_path, library_paths) ⇒ Fat

  • parameter output_path: The path of the resulting library.

  • parameter library_paths: An array of paths to the static libraries (‘.a` files).



17
18
19
20
# File 'lib/apple_frameworks/fat.rb', line 17

def initialize(output_path, library_paths)
  @output_path = output_path
  @library_paths = library_paths
end

Instance Method Details

#combine_using_lipoObject

Uses the ‘lipo -create` command to combine two or more libraries into a single fat library.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/apple_frameworks/fat.rb', line 25

def combine_using_lipo
  validations

  path_args = @library_paths.join(" ")

  cmd = "lipo #{path_args} -create -output #{@output_path}"

  logfile = Tempfile.new(['fat', '.log'])

  system("#{cmd} >#{logfile.path} 2>&1") ||
    raise(CombineUsingLipoFailure.new(File.read(logfile).strip.split(/\/.*\/lipo: /).last))
ensure
  if logfile
    logfile.close
    logfile.delete
  end
end