libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

Building for iOS

Open jarrodnorwell opened this issue 2 years ago • 9 comments

I'm aware this has been asked before for older versions of libtorrent but having tried the methods for 2.0.6 it doesn't seem to work the same.

How would one go about building libtorrent for iOS, if at all possible?

I'm currently using 1.2.3 as far as I can remember but would like to take advantage of the newer features, etc.

Edit: thank you in advance for any response, even if it only nudges me in the right direction.

jarrodnorwell avatar May 31 '22 14:05 jarrodnorwell

Does this help as it has the steps to compile libtorrent.

https://github.com/qbittorrent/qBittorrent/wiki/Compilation:-macOS-(x86_64,-arm64,-cross-compilation)

https://github.com/qbittorrent/qBittorrent/wiki/Compilation:-macOS

I think the first link might be easier to use though

userdocs avatar May 31 '22 17:05 userdocs

@userdocs I'll look into it in the morning and report back, thanks for reaching out!

jarrodnorwell avatar May 31 '22 18:05 jarrodnorwell

very likely mentioned guides for macOS will NOT help, unfortunately... I'm saying that as its author :) building for iOS using CMake is not a trivial task, it requires some custom (but very likely very well community-supported) configs for environment setup. and furthermore, there are many limitations for library formats on iOS compared to macOS. I can't provide more details, I just "touched" the project which was already set up for building with CMake for iOS. one thing I can recommend is just google for "cmake ios" and follow those guides/recommendations. when you overcome the environment setup step, the rest is trivial and the same as for any other environment. also, I recommend building a static library, because "plain" shared libraries are definitely not supported on iOS (I may be wrong, I'm not an iOS developer, but we faced problems with this on iOS), they must be frameworks, and corresponding rules must be present in CMakeLists.txt to build them (and there are no such rules right now, so static library is the one option). but this is not only the one thing - you also need to build libtorrent' dependencies first: Boost and OpenSSL, this may be even harder rather libtorrent itself, because both of them use their own build systems.

Kolcha avatar Jun 01 '22 11:06 Kolcha

The osx workflow they use does not seem that complicated

https://github.com/qbittorrent/qBittorrent/blob/master/.github/workflows/ci_macos.yaml

But they are using homebrew for dependencies

https://github.com/qbittorrent/qBittorrent/blob/master/.github/workflows/ci_macos.yaml#L32-L37

With the core dependencies installed it should be pretty easy to build libtorrent from just boost source with b2 but I have no idea how you get ggc and stuff on OSX

userdocs avatar Jun 01 '22 16:06 userdocs

I did previously get 2.0.5 working on iOS but as a separate sim/device framework, when using lipo to combine them it broke so wanted to ask and see if my process was different/wrong.

jarrodnorwell avatar Jun 01 '22 18:06 jarrodnorwell

don't know if lipo is suitable to combine binaries for device and emulator and even this is supposed... usually, binaries for device and emulator are separate frameworks bundled into .xcframework (which in turn just a directory with special structure and contains frameworks for each build flavor). I didn't see any "universal" binaries for emulator and device, but again, I'm not an iOS developer, I just worked on a huge project and had to deal with it a lot.

Kolcha avatar Jun 01 '22 18:06 Kolcha

Ended up getting 2.0.6 running on iOS using the official build guide with only a few changes to the user-config.jam.

Edit: useful log is on the 4th line at the bottom

image

jarrodnorwell avatar Jun 04 '22 19:06 jarrodnorwell

@official-antique what official build guide do you mean? this one http://libtorrent.org/building.html ? what changes are required to user-config.jam? and what about OpenSSL dependency?

Kolcha avatar Jun 05 '22 14:06 Kolcha

the CI workflow for iOS could also be helpful: https://github.com/arvidn/libtorrent/blob/RC_2_0/.github/workflows/macos.yml#L110

arvidn avatar Jun 06 '22 11:06 arvidn

@arvidn sorry, may I ask how to use this yml file to build the iOS output? thanks.

jingliancui avatar Sep 01 '23 15:09 jingliancui

I compiled the most recent one some time ago @jingliancui; https://github.com/official-antique/QuixTorrent/releases/tag/1.0.1

jarrodnorwell avatar Sep 01 '23 15:09 jarrodnorwell

@official-antique thank you, do you mind share the way that how you build these output on your repo. I am very very interesting in this.

jingliancui avatar Sep 01 '23 15:09 jingliancui

Absolutely, I'll add a how-to as soon as I can. That repository also contains an SPM for ease of access but requires additional code (more so a wrapper)

jarrodnorwell avatar Sep 01 '23 15:09 jarrodnorwell

Thanks, I'm curious about can we reuse the h files directly in ios? Why need the wrapper.

jingliancui avatar Sep 01 '23 16:09 jingliancui

You can still use the .h/.hpp from libtorrent but to be able to use the .cpp you'll need to either do C++>ObjC++, C++>ObjC++>Swift or C++>Swift interoperability

jarrodnorwell avatar Sep 02 '23 03:09 jarrodnorwell

Thanks for the explanation

jingliancui avatar Sep 02 '23 04:09 jingliancui