NOTE: This article relates to using dylibs with iOS simulator only. If you’re building your app for iOS device, you should link against the static libraries. See this link.
Firstly, a couple of thanks: To Doron Adler, who created a fork of a script, of which mine is based on, and who gave some very helpful tips. Also to Jeremy Huddleston from Apple, who also gave some helpful advice.
If you’re like me, you still like to use Indy components for your network connectivity. They cover a wide range of protocols, and they work on Windows, OSX, iOS and Android.
I’m in the process of rebuilding a cross-platform newsreader I started some time ago, and as part of that process, I’m testing functionality on all platforms. For iOS, I prefer to test on simulator first, since I don’t have to have a physical device connected, and I can see how things look on any iOS device.
Somewhere along the line (perhaps when Xcode 7 was released), Apple stopped shipping OpenSSL dylibs that work on iOS simulator. This presents a problem as Indy uses OpenSSL for SSL connections. To add to the woes, the compiler for iOS simulator does not bind statically to .a files (think of them like .DCUs, but for OSX/iOS), so the only choice when using SSL and Indy became to test on the actual device.
Not satisfied with this situation, I set about finding out how to build dylibs for OpenSSL for iOS simulator. To cut a long story short, however many agonising hours later, I managed to come up with relatively painless solution.
Firstly, you should create a working folder somewhere on your Mac, eg /Users/<username>/Source/OpenSSLiOS, where <username> is the username you log into your Mac with.
Into it, copy the script that you can download from here:
Download the OpenSSL source from here, or for older versions: here, and put it in the same folder as the script. Expand the OpenSSL .gz file, so now you will have a script file, the .gz file and a folder with the OpenSSL source.
For the modifications that follow, I find Sublime Text is an excellent editor. You can just use TextEdit, if you so choose.
If you’re using a different version of OpenSSL from that which the script is built for, you’ll need to modify the OPENSSL_VERSION= line in the script to match.
NOTE: Some servers have not had their SSL updated (to protect against Logjam attacks <link>), and connecting to them using later versions of OpenSSL may fail. e.g. the SSL on Embarcadero’s news server (this may change after this article is published). In order to successfully connect to these I used version 1.0.2a of OpenSSL. The latest version (1.0.2g at time of writing) may work on other servers.
Next, modify the Makefile.shared file that’s in the root of the folder which contains the OpenSSL source.
The line that needs to be modified looks like this:
SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \
Replace $(INSTALLTOP)/$(LIBDIR)/ with @executable_path, so that the line looks like this:
SHAREDFLAGS="$$SHAREDFLAGS -install_name @executable_path/$$SHLIB$(SHLIB_EXT)"; \
The @executable_path value means that the system will expect the dylib to be in the same location as the executable. We’ll see why this is important when deployment is covered.
Next, the script needs to have its properties changed so that it can be executed. Using the Terminal app,
change folder to the one created earlier to put the script in, e.g:
where <username> is the username you log into your Mac with, then use the following command:
chmod +x openssl-build-shared.sh
..and execute the script:
This will take about 5-10 minutes depending on your machine. When it has finished successfully, the resulting dylibs will be in the lib/iOS folder, which is off of the folder where the script is located.
If necessary, copy/move these files to a location where they can be included in your Delphi project to be deployed with your app. In my setup, I have a folder shared to a VirtualBox VM that has Delphi 10 Seattle installed, so I can share files between my Mac and the VM.
In your Delphi project, bring up the deployment manager. Click the Add files button
Navigate to the folder containing the dylibs, select both of them and click OK
The remote path (.\) is the same folder as the application, so this does not need to be changed (same as the @executable_path in the makefile, described earlier)
In your code, somewhere before it attempts to make an SSL connection you will need to set the OpenSSL search path for Indy, when compiling for the iOS simulator:
This sets the path to the dylibs as the executable directory.
I hope this has been of some use. It was certainly satisfying for me to finally make this work, and I wanted to share it with others.