2019-09-23 18:19:08 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
require 'xcodeproj'
|
|
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
|
option_parser = OptionParser.new do |opts|
|
2019-10-10 03:05:54 +00:00
|
|
|
opts.banner = 'Tools for building PyTorch iOS framework on MacOS'
|
|
|
|
|
opts.on('-i', '--install_path ', 'path to the cmake install folder') { |value|
|
2019-09-23 18:19:08 +00:00
|
|
|
options[:install] = value
|
|
|
|
|
}
|
2019-10-10 03:05:54 +00:00
|
|
|
opts.on('-x', '--xcodeproj_path ', 'path to the XCode project file') { |value|
|
2019-09-23 18:19:08 +00:00
|
|
|
options[:xcodeproj] = value
|
|
|
|
|
}
|
2019-10-10 03:05:54 +00:00
|
|
|
opts.on('-p', '--platform ', 'platform for the current build, OS or SIMULATOR') { |value|
|
2019-10-04 03:06:17 +00:00
|
|
|
options[:platform] = value
|
|
|
|
|
}
|
2019-10-10 03:05:54 +00:00
|
|
|
opts.on('-c', '--provisioning_profile ', 'provisioning profile for code signing') { |value|
|
|
|
|
|
options[:profile] = value
|
|
|
|
|
}
|
2020-01-18 00:01:29 +00:00
|
|
|
opts.on('-t', '--team_id ', 'development team ID') { |value|
|
2019-10-10 03:05:54 +00:00
|
|
|
options[:team_id] = value
|
|
|
|
|
}
|
2019-09-23 18:19:08 +00:00
|
|
|
end.parse!
|
|
|
|
|
puts options.inspect
|
|
|
|
|
|
|
|
|
|
install_path = File.expand_path(options[:install])
|
|
|
|
|
if not Dir.exist? (install_path)
|
2019-10-10 03:05:54 +00:00
|
|
|
raise "path don't exist:#{install_path}!"
|
2019-09-23 18:19:08 +00:00
|
|
|
end
|
|
|
|
|
xcodeproj_path = File.expand_path(options[:xcodeproj])
|
|
|
|
|
if not File.exist? (xcodeproj_path)
|
2019-10-10 03:05:54 +00:00
|
|
|
raise "path don't exist:#{xcodeproj_path}!"
|
2019-09-23 18:19:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
project = Xcodeproj::Project.open(xcodeproj_path)
|
2019-10-10 03:05:54 +00:00
|
|
|
target = project.targets.first #TestApp
|
2019-09-23 18:19:08 +00:00
|
|
|
header_search_path = ['$(inherited)', "#{install_path}/include"]
|
|
|
|
|
libraries_search_path = ['$(inherited)', "#{install_path}/lib"]
|
|
|
|
|
other_linker_flags = ['$(inherited)', "-all_load"]
|
|
|
|
|
|
|
|
|
|
target.build_configurations.each do |config|
|
|
|
|
|
config.build_settings['HEADER_SEARCH_PATHS'] = header_search_path
|
|
|
|
|
config.build_settings['LIBRARY_SEARCH_PATHS'] = libraries_search_path
|
2019-10-22 19:48:44 +00:00
|
|
|
config.build_settings['OTHER_LDFLAGS'] = other_linker_flags
|
2019-10-04 03:06:17 +00:00
|
|
|
config.build_settings['ENABLE_BITCODE'] = 'No'
|
2019-10-10 03:05:54 +00:00
|
|
|
dev_team_id = options[:team_id]
|
|
|
|
|
if not dev_team_id
|
|
|
|
|
raise "Please sepecify a valid development team id for code signing"
|
|
|
|
|
end
|
|
|
|
|
config.build_settings['DEVELOPMENT_TEAM'] = dev_team_id
|
2019-09-23 18:19:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# link static libraries
|
|
|
|
|
target.frameworks_build_phases.clear
|
Split libtorch.so back into libtorch_{cpu,cuda,hip} (#30315)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30315
The new structure is that libtorch_cpu contains the bulk of our
code, and libtorch depends on libtorch_cpu and libtorch_cuda.
This is a reland of https://github.com/pytorch/pytorch/pull/29731 but
I've extracted all of the prep work into separate PRs which can be
landed before this one.
Some things of note:
* torch/csrc/cuda/nccl.cpp was added to the wrong list of SRCS, now fixed (this didn't matter before because previously they were all in the same library)
* The dummy file for libtorch was brought back from the dead; it was previously deleted in #20774
In an initial version of the patch, I forgot to make torch_cuda explicitly depend on torch_cpu. This lead to some very odd errors, most notably "bin/blob_test: hidden symbol `_ZNK6google8protobuf5Arena17OnArenaAllocationEPKSt9type_infom' in lib/libprotobuf.a(arena.cc.o) is referenced by DSO"
* A number of places in Android/iOS builds have to add torch_cuda explicitly as a library, as they do not have transitive dependency calculation working correctly
* I had to torch_cpu/torch_cuda caffe2_interface_library so that they get whole-archived linked into torch when you statically link. And I had to do this in an *exported* fashion because torch needs to depend on torch_cpu_library. In the end I exported everything and removed the redefinition in the Caffe2Config.cmake. However, I am not too sure why the old code did it in this way in the first place; however, it doesn't seem to have broken anything to switch it this way.
* There's some uses of `__HIP_PLATFORM_HCC__` still in `torch_cpu` code, so I had to apply it to that library too (UGH). This manifests as a failer when trying to run the CUDA fuser. This doesn't really matter substantively right now because we still in-place HIPify, but it would be good to fix eventually. This was a bit difficult to debug because of an unrelated HIP bug, see https://github.com/ROCm-Developer-Tools/HIP/issues/1706
Fixes #27215 (as our libraries are smaller), and executes on
part of the plan in #29235.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Test Plan: Imported from OSS
Differential Revision: D18790941
Pulled By: ezyang
fbshipit-source-id: 01296f6089d3de5e8365251b490c51e694f2d6c7
2019-12-04 16:03:10 +00:00
|
|
|
libs = ['libc10.a', 'libclog.a', 'libnnpack.a', 'libeigen_blas.a', 'libcpuinfo.a', 'libpytorch_qnnpack.a', 'libtorch_cpu.a', 'libtorch.a']
|
2019-09-23 18:19:08 +00:00
|
|
|
for lib in libs do
|
|
|
|
|
path = "#{install_path}/lib/#{lib}"
|
2019-10-22 19:48:44 +00:00
|
|
|
if File.exist?(path)
|
|
|
|
|
libref = project.frameworks_group.new_file(path)
|
|
|
|
|
target.frameworks_build_phases.add_file_reference(libref)
|
|
|
|
|
end
|
2019-09-23 18:19:08 +00:00
|
|
|
end
|
|
|
|
|
project.save
|
|
|
|
|
|
2019-10-04 03:06:17 +00:00
|
|
|
sdk = nil
|
|
|
|
|
if options[:platform] == 'SIMULATOR'
|
|
|
|
|
sdk = 'iphonesimulator'
|
|
|
|
|
elsif options[:platform] == 'OS'
|
|
|
|
|
sdk = 'iphoneos'
|
|
|
|
|
else
|
2019-10-10 03:05:54 +00:00
|
|
|
raise "unsupported platform #{options[:platform]}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
profile = options[:profile]
|
|
|
|
|
if not profile
|
|
|
|
|
raise "no provisioning profile found!"
|
2019-10-04 03:06:17 +00:00
|
|
|
end
|
|
|
|
|
|
2019-09-23 18:19:08 +00:00
|
|
|
# run xcodebuild
|
2019-10-10 03:05:54 +00:00
|
|
|
exec "xcodebuild clean build -project #{xcodeproj_path} -target #{target.name} -sdk #{sdk} -configuration Release PROVISIONING_PROFILE_SPECIFIER=#{profile}"
|