apple_frameworks 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88a784f4579a6fe0d1c01d20cee23743ff51987026fe70102a34f3b2a568e6ff
4
- data.tar.gz: b98904da83eb50018c769c6443d7149da20ac759d551ab6f83b4c8259742e53d
3
+ metadata.gz: 2458b11ac8aa7472cacff84481f16d4b7ea95f6231353de7ae3faa0b33bc9a38
4
+ data.tar.gz: c77c610834c38fd433b16e89083e589d13fb44c92ac1adf9d710c0b9077ddd39
5
5
  SHA512:
6
- metadata.gz: 60ddf21feb22a51447f0f22c11b820783424716037047737c13f400f6fc096ac2a15a6dafb69f2acceb10bba7957b828420c45adb40613c634996c7706d6ad1e
7
- data.tar.gz: aeebac5804a5d7d08df84018c1fb1073cdf9ce226e76d87a3cb80a43137e8578613eecef1f119e0929ae44cac923490878e9bb5cde36d451023094b88264c4cd
6
+ metadata.gz: c23401f609cd5e7395eefdb38a132c21103adef7e603638028874a8e965628ecdb8fd5a45c364f20d4fd107ea28149c44e7dcc2e2f0b16353cd9270e5197828d
7
+ data.tar.gz: 89328d4e21ceba6ad978353a162a5a1802d734d66d905f009f73a001d20f858a91c2d110df89ce985beac5a341e730fb3cf6c141a251b049da27b626e7523324
@@ -0,0 +1,56 @@
1
+ module AppleFrameworks
2
+ # Creates "fat" or "universal" libraries by combining two builds of the same
3
+ # library with different architectures.
4
+ #
5
+ # Note: While it's possible (and used to be recommended) to make a fat library
6
+ # for multiple platforms (iOS simulator and device), it's no longer
7
+ # recommended to have these mixed in a single fat binary. For mixing
8
+ # platforms, use `XCFramework`.
9
+ #
10
+ class Fat
11
+ class CombineUsingLipoFailure < StandardError; end
12
+
13
+ # - parameter output_path: The path of the resulting library.
14
+ # - parameter library_paths: An array of paths to the static libraries
15
+ # (`.a` files).
16
+ #
17
+ def initialize(output_path, library_paths)
18
+ @output_path = output_path
19
+ @library_paths = library_paths
20
+ end
21
+
22
+ # Uses the `lipo -create` command to combine two or more libraries into a
23
+ # single fat library.
24
+ #
25
+ def combine_using_lipo
26
+ validations
27
+
28
+ path_args = @library_paths.join(" ")
29
+
30
+ cmd = "lipo #{path_args} -create -output #{@output_path}"
31
+
32
+ logfile = Tempfile.new(['fat', '.log'])
33
+
34
+ system("#{cmd} >#{logfile.path} 2>&1") ||
35
+ raise(CombineUsingLipoFailure.new(File.read(logfile).strip.split(/\/.*\/lipo: /).last))
36
+ ensure
37
+ if logfile
38
+ logfile.close
39
+ logfile.delete
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+
46
+ def validations
47
+ if File.directory?(@output_path)
48
+ raise "Directory already exists at Fat library output_path"
49
+ end
50
+
51
+ if File.file?(@output_path)
52
+ raise "File already exists at Fat library output_path"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -7,7 +7,7 @@ module AppleFrameworks
7
7
  # ```
8
8
  # LibraryName.Framework
9
9
  # Info.plist
10
- # library_name (the actual dynamic lib)
10
+ # library_name (the actual static lib)
11
11
  # Headers
12
12
  # library_name
13
13
  # (all the headers)
@@ -1,3 +1,3 @@
1
1
  module AppleFrameworks
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -26,8 +26,6 @@ module AppleFrameworks
26
26
  # LibraryName.framework
27
27
  # ```
28
28
  #
29
- # Note: Binaries with multiple platforms are not supported by Xcode.
30
- #
31
29
  class XCFramework
32
30
  class BuildUsingXcodeFailure < StandardError; end
33
31
 
@@ -51,7 +49,15 @@ module AppleFrameworks
51
49
  # Uses the `xcodebuild -create-xcframework` command to create the
52
50
  # XCFramework.
53
51
  #
54
- # Note: this will require Xcode and its command line tools to be installed.
52
+ # This will require Xcode and its command line tools to be installed.
53
+ #
54
+ # Xcode has a couple of notable annoyances:
55
+ #
56
+ # * Fat binaries with multiple platforms (e.g. a single binary containing
57
+ # iOS simulator x64 and iOS arm64) are not supported.
58
+ # * To include multiple architectures of the same platform (e.g. iOS
59
+ # simulator x64 and arm64), they first need to be combined as a Fat
60
+ # binary.
55
61
  #
56
62
  def build_using_xcode
57
63
  validations
@@ -2,5 +2,6 @@ require "digest"
2
2
  require "tempfile"
3
3
 
4
4
  require "apple_frameworks/version"
5
+ require "apple_frameworks/fat"
5
6
  require "apple_frameworks/framework"
6
7
  require "apple_frameworks/xcframework"
data/spec/fat_spec.rb ADDED
@@ -0,0 +1,79 @@
1
+ RSpec.describe AppleFrameworks::Fat do
2
+ let(:output_path) { Bundler.root.join("tmp", "fat") }
3
+ let(:library_paths) do
4
+ [
5
+ Bundler.root.join("spec", "fixtures", "fake.a"),
6
+ Bundler.root.join("spec", "fixtures", "fake-x64.a")
7
+ ]
8
+ end
9
+ let(:described_instance) { described_class.new(output_path, library_paths) }
10
+
11
+ describe "#combine_using_lipo" do
12
+ subject { described_instance.combine_using_lipo }
13
+ before { FileUtils.rm_rf(output_path) }
14
+ after { FileUtils.rm_rf(output_path) }
15
+
16
+ context "when there is already a directory in the parent_directory" do
17
+ before do
18
+ FileUtils.mkdir_p(File.join(output_path))
19
+
20
+ expect(File.directory?(output_path))
21
+ .to eq(true)
22
+ end
23
+
24
+ it "raises an error" do
25
+ expect { subject }
26
+ .to raise_error("Directory already exists at Fat library output_path")
27
+ end
28
+ end
29
+
30
+ context "when there is a file at the target parent_directory" do
31
+ before do
32
+ FileUtils.mkdir_p(Bundler.root.join("tmp"))
33
+ FileUtils.touch(output_path)
34
+
35
+ expect(File.file?(output_path))
36
+ .to eq(true)
37
+ end
38
+
39
+ it "raises an error" do
40
+ expect { subject }
41
+ .to raise_error("File already exists at Fat library output_path")
42
+ end
43
+ end
44
+
45
+ context "when there is an error from lipo" do
46
+ let(:library_paths) do
47
+ ["doesnt_exist"]
48
+ end
49
+
50
+ it "raises an error" do
51
+ expect { subject }
52
+ .to raise_error(
53
+ AppleFrameworks::Fat::CombineUsingLipoFailure,
54
+ "can't open input file: doesnt_exist (No such file or directory)"
55
+ )
56
+ end
57
+ end
58
+
59
+ context "when there isn't a file or directory at output_path" do
60
+ before do
61
+ expect(File.directory?(output_path))
62
+ .to eq(false)
63
+
64
+ expect(File.file?(output_path))
65
+ .to eq(false)
66
+ end
67
+
68
+ it "creates the fat library" do
69
+ subject
70
+
71
+ expect(File.file?(output_path))
72
+ .to eq(true)
73
+
74
+ expect(`lipo -info #{output_path}`.strip)
75
+ .to end_with("are: x86_64 arm64")
76
+ end
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_frameworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Inkpen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-02 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -32,9 +32,11 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - lib/apple_frameworks.rb
35
+ - lib/apple_frameworks/fat.rb
35
36
  - lib/apple_frameworks/framework.rb
36
37
  - lib/apple_frameworks/version.rb
37
38
  - lib/apple_frameworks/xcframework.rb
39
+ - spec/fat_spec.rb
38
40
  - spec/framework_spec.rb
39
41
  - spec/spec_helper.rb
40
42
  - spec/xcframework_spec.rb