Skip to content

Allow cross-compile Android while compiling libicu in Linux. #20083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

drodriguez
Copy link
Contributor

Before this commit, if one used the --libicu parameter of the build script to compile ICU in Linux, the variable SWIFT_PATH_TO_LIBICU_BUILD is set. While evaluating which link flags to use in stdlib/public/core/CMakeLists.txt, the presence of that variable will set all the SDKs to use -licuuc style link libraries, which will not work while cross-compiling Android (since Android libraries have a swift suffix, and they are not in the library search path).

This commit delays the selection of -licuuc style or full paths to later in the process, where the current SDK is already know, and the script can distinguish between the Android SDK case and other SDKs.

This change will become more important if #19860 is merged. It might need to be modified slightly to always use the swift suffixes, though.

/cc @spevans

@drodriguez drodriguez force-pushed the android-and-linux-libicu branch from b0fbfaa to 646e030 Compare October 30, 2018 23:55
else()
list(APPEND swift_core_private_link_libraries -licui18n -licuuc -licudata)
endif()
list(APPEND swift_core_private_link_libraries ICU_UC ICU_I18N)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ICU_UC and ICU_I18N are actually the correct variables I think it should be ICU_UC_LIBRARIES and ICU_I18N_LIBRARIES

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my explanation above, this is just following the previous code. The code uses those values (they are not variables) as sigils for linking the ICU libraries. When those sigils are found in AddSwift.cmake, the right thing is done: for most SDKs ${SWIFT_${sdk}_${arch}_ICU_UC} and similar are used, but if one provided ${SWIFT_PATH_TO_LIBICU_BUILD}, the normal -licuuc flags are used (since the path will be in the library search path).

list(APPEND swiftlib_private_link_libraries_targets
"${SWIFT_${sdk}_${arch}_ICU_UC}")
else()
list(APPEND swiftlib_private_link_libraries_targets -licuuc -licudata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding the library names here, -licuuc and -licudata. When the libicu is compiled as part of the swift build, the names are libicuucswift and libicudataswift. I think we should be able to use some ICU_ variable names instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this will have to change if libicu gets more integrated into the build system, but for the moment, this change only moves code that was in stdlib/public/core/CMakeLists.txt into here. The code has been moved as similar as possible, and that’s why I kept using -licuuc and -licudata here.

@spevans
Copy link
Contributor

spevans commented Nov 4, 2018

Just to note to say that swift/cmake/modules/FindICU.cmake and
swift-corelibs-foundation/cmake/modules/FindICU.cmake are completely different using different methods to find ICU. I think we should make them both the same, probably using the one from swift/cmake/modules/FindICU.cmake in both places. This means that the -DICU_... variables set in build-script-impl are actually used differently for swift v swift-corelibs-foundation.

I think they each use a different subset of the variables presented. So a followup PR would be required to fix up swift-corelibs-foundation after this one is done.

@gottesmm
Copy link
Contributor

gottesmm commented Nov 4, 2018

@spevans we can include that in the cmake distribution for swift. Then Foundation can just import it itself from swift.

@drodriguez
Copy link
Contributor Author

I’m aware that the way ICU is linked in swift and in swift-corelibs-foundation is different. And it will probably will have to keep changing if ICU is integrated more in the swift build system. I don’t like the special support for Linux, and the weird setup for Android (but I like more the weird setup for Android than the special support for Linux, since it is more flexible and works with any SDK).

Anyway, this change was a minimal change to allow compiling both Linux and Android, Linux with a self-compiled ICU, Android with a pre-compiled ICU (which should be the typical setup for many Linux distributions).

I didn’t noticed that you finally merged #19860, but this one will probably have to change now. From the recommended scripts to build ICU for Android (SwiftAndroid/libiconv-libicu-android), I don’t think it would be easy to self-compile ICU for Android, but I will see if there’s a way of modifying the scripts to build something that works with FindICU.cmake

@drodriguez drodriguez force-pushed the android-and-linux-libicu branch from 646e030 to f08ebf9 Compare November 5, 2018 21:10
@drodriguez drodriguez closed this Jul 16, 2019
@drodriguez drodriguez deleted the android-and-linux-libicu branch July 16, 2019 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants