Compiling the JPEG-XL reference for iOS, or, "Is compiling C++ for iOS really this difficult!?"

I'm trying to add JPEG-XL encoding/decoding capabilities to my app and haven't been able to find a trustworthy pre-compiled version. The only one I've found is in https://github.com/awxkee/jxl-coder-swift.

As a result I've been trying to compile my own iOS version from the reference implementation (https://github.com/libjxl/libjxl), having done virtually no compiling before. When I started out, my gut said, "Compiling for a different platform should be easy since it's not like I'm actually writing or modifying the implementation", but the more I research and try, the more doubtful I've become. So far I've figured out it means compiling all the dependencies (brotli, highway, libpng, skcms, etc.) too, but I've also gotten nowhere with them, having tried my hand at modifying cmake toolchains and CMakeList.txt files.

As a novice, am I biting off more than I can chew with this? Is the seemingly simple task, "Compile this C++ library for iOS" actually something that freelancers charge huge amounts for? (If so, this makes the free compiled version mentioned above even more questionable)

Any help or pointers would be greatly appreciated.

Answered by wmk in 792280022

I managed to get JXL working after a lot of angst and grit. I didn't have C++ compilation experience but I managed to get the job done, so this might be encouragement for anyone stuck in a similar situation (no guarantees though).

Anyone interested in JXL for iOS should be able to replicate what I did via this thread:

https://developer.apple.com/forums/thread/757359

Is compiling C++ for iOS really this difficult!?

Yeah, pretty much.

C++ doesn’t have any sort of package manager, so every C++ library uses whatever build system the author preferred. And if you’re trying to use a library with a lot of dependencies, you have to learn the build system for your target library and all of its dependencies.

Moreover, these build systems often assume that you’re building on the machine that you’re targeting, which is not true for iOS (where you build on macOS but target iOS). That further complicates matters because you have to work out how to implement cross compilation in each of those build systems.

Finally, once you get that all sorted out you have to build an XCFramework that you can use in Xcode.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

C++ doesn’t have any sort of package manager

It has vcpkg, but that's not an Apple product so it doesn't exist apparently. You might be able to just vcpkg install libjxl --triplet=arm64-ios, or something.

Not that I use it. The stack of package manager (vcpkg) --> build system (cmake) --> low-level build system (make) --> compiler (clang) tries to make things easier for you by hiding the details of the lower levels behind easier-to-use higher levels. But in my experience, they rarely succeed at that; you inevitably get an error from a lower level that is impossible to relate to the higher-level command that you actually ran. Learning vcpkg doesn't remove the need to understand, and be able to debug, cmake, make and the compiler. The same is true of autotools and to some extent xcode. Package managers, IMO, work well for binaries i.e. homebrew or dpkg, and maybe for interpretted languages, e.g. npm, but not really for compiled languages.

Just knowing something is out of my league makes things so much better. At least I won't be pestering people for help while thinking it's a quick and simple task.

I managed to get JXL working after a lot of angst and grit. I didn't have C++ compilation experience but I managed to get the job done, so this might be encouragement for anyone stuck in a similar situation (no guarantees though).

Anyone interested in JXL for iOS should be able to replicate what I did via this thread:

https://developer.apple.com/forums/thread/757359

It has vcpkg …

OK, let me rephrase that: C++ doesn’t have a single package manager that’s defined by the language. The issue with C++ build systems isn’t that there’s none of them, but that there’s too many of them.

I managed to get JXL working after a lot of angst and grit.

Yay!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Compiling the JPEG-XL reference for iOS, or, "Is compiling C++ for iOS really this difficult!?"
 
 
Q