[swift-dev] SwiftAndroid: Statically linking libicu and/or the stdlib?
geojay at gmail.com
Mon Dec 21 20:13:53 CST 2015
Hi, I’m still working on the deployment and JNI side of SwiftAndroid (github.com/SwiftAndroid). After success with some basic tests I’ve started fleshing out a “Swifty” JNI interface and connected to some existing Swift library code I want to try out. Now I’m stuck and I hope someone with more experience can lend some wisdom on the matter:
libicu doesn’t come packaged for Android, so the source needs to be downloaded, compiled and then icui18n and icuuc linked into libswiftCore and libswiftRuntime during the stdlib build process. After that, if I copy the libicui18n and libicuuc.so files into the system library path on the Android emulator, the Swift code links with swiftCore and executes fine there.
What I haven’t yet figured out is how to get these icu libraries dynamically linking at runtime on a non-rooted device. For some reason, and seemingly no matter what I do the runtime linker complains of missing symbols.
I’ve tried loading the libraries in various ways with no luck: the same way I’m loading everything else (my own program's swift module, the stdlib, etc.), as an explicit dependency of libswiftCore (in Android.mk), and at runtime in Java via System.loadLibrary(). All of these result in the same fatal error: that a certain libicu symbol is missing (nm tells me it’s present in icui18n) and therefore libswiftCore couldn’t be loaded.
a) the above issues,
b) the fact that the icu libraries are large (as big as the swift stdlib itself), and that seemingly only a very small amount of them is actually used,
c) the fact that the swift ABI is not yet set in stone anyway (I understand swiftCore is still packaged alongside every Swift iOS app, for example, which as far as I understand negates any benefit of dynamic linking for now)
.. it would make sense to me to just statically link the libicu dependencies into the stdlib for Android, or even just forego dynamic linking altogether on Android, except for the system libs.
Assuming static linking makes sense for Android (please correct me if my reasoning so far is wrong - this is all very new for me), here’s where I’m stuck at the moment. I’ve tried building swift via
./utils/build-script -R --no-assertions -b -p --extra-swift-args build-swift-static-stdlib=1
but changing this static-stdlib flag seems to have no effect at all on the build output. As more of a longshot I also tried adding
to stdlib/public/runtime/CMakeLists.txt just before add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE. Neither of these seemed to do anything whatsoever. I wish it would at least break so I don’t get my hopes up waiting for the stdlib to recompile :)
I’m a bit lost in all the different components of the build system to be honest, so any input on these issues would be greatly appreciated!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-dev