Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for building tvOS framework for both simulator and real device #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/cocoapods-packager/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def build_dynamic_framework(platform, defines, output)
clean_directory_for_dynamic_build
if platform.name == :ios
build_dynamic_framework_for_ios(platform, defines, output)
elsif platform.name == :tvos
build_dynamic_framework_for_tvos(platform, defines, output)
else
build_dynamic_framework_for_mac(platform, defines, output)
end
Expand Down Expand Up @@ -109,6 +111,27 @@ def build_dynamic_framework_for_ios(platform, defines, output)
`mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework.dSYM #{platform.name}`
end

def build_dynamic_framework_for_tvos(platform, defines, output)
# Specify frameworks to link and search paths
linker_flags = static_linker_flags_in_sandbox
defines = "#{defines} OTHER_LDFLAGS='$(inherited) #{linker_flags.join(' ')}'"

# Build Target Dynamic Framework for both device and Simulator
device_defines = "#{defines} LIBRARY_SEARCH_PATHS=\"#{Dir.pwd}/#{@static_sandbox_root}/build\""
device_options = tvos_build_options << ' -sdk appletvos'
xcodebuild(device_defines, device_options, 'build', @spec.name.to_s, @dynamic_sandbox_root.to_s)

sim_defines = "#{defines} LIBRARY_SEARCH_PATHS=\"#{Dir.pwd}/#{@static_sandbox_root}/build-sim\" ONLY_ACTIVE_ARCH=NO"
xcodebuild(sim_defines, '-sdk appletvsimulator', 'build-sim', @spec.name.to_s, @dynamic_sandbox_root.to_s)

# Combine architectures
`lipo #{@dynamic_sandbox_root}/build/#{@spec.name}.framework/#{@spec.name} #{@dynamic_sandbox_root}/build-sim/#{@spec.name}.framework/#{@spec.name} -create -output #{output}`

FileUtils.mkdir(platform.name.to_s)
`mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework #{platform.name}`
`mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework.dSYM #{platform.name}`
end

def build_dynamic_framework_for_mac(platform, defines, _output)
# Specify frameworks to link and search paths
linker_flags = static_linker_flags_in_sandbox
Expand All @@ -126,6 +149,8 @@ def build_dynamic_framework_for_mac(platform, defines, _output)
def build_sim_libraries(platform, defines)
if platform.name == :ios
xcodebuild(defines, '-sdk iphonesimulator', 'build-sim')
elsif platform.name == :tvos
xcodebuild(defines, '-sdk appletvsimulator', 'build-sim')
end
end

Expand Down Expand Up @@ -169,6 +194,8 @@ def compile(platform)

if platform.name == :ios
options = ios_build_options
elsif platform == :tvos
options = tvos_build_options
end

xcodebuild(defines, options)
Expand Down Expand Up @@ -275,6 +302,10 @@ def ios_build_options
"ARCHS=\'x86_64 i386 arm64 armv7 armv7s\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
end

def tvos_build_options
"ARCHS=\'x86_64 arm64\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
end

def xcodebuild(defines = '', args = '', build_dir = 'build', target = 'Pods-packager', project_root = @static_sandbox_root, config = @config)
if defined?(Pod::DONT_CODESIGN)
args = "#{args} CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
Expand Down