Skip to content

[core] Update CMake to use TARGET_SDKS for Android #5095

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

Conversation

modocache
Copy link
Contributor

The add_swift_library CMake function takes an optional TARGET_SDKS parameter. When used, only CMake targets for the specified SDKs are added.

Change stdlib/public/core to use this parameter for Android, which prevents link flags intended for macOS/iOS targets from being used when building for Android.

This pull request was split out of #4972, which addresses SR-1362.

@jrose-apple
Copy link
Contributor

I think there are still more things that are similar than different here. I'd prefer you conditionalize the existing variables instead.

@modocache
Copy link
Contributor Author

Variables like swift_core_private_link_libraries are conditionalized based on CMAKE_SYSTEM_NAME, a technique that doesn't work when cross-compiling from macOS to Android. Is there a better approach I could use here?

@jrose-apple
Copy link
Contributor

It seems like a lot of those conditionals really want to be asking questions about the target platform, not the host platform.

@modocache
Copy link
Contributor Author

modocache commented Oct 3, 2016

Absolutely. add_swift_library and its TARGET_SDKS parameter work really well in that sense, since the function loops over each specified target, removing the ones that aren't being built.

I'll try to think of a different way to accomplish this, but I wonder if it'll involve duplicating some of that logic.

@modocache
Copy link
Contributor Author

@jrose-apple Just to clarify: are you saying that the conditionals using CMAKE_SYSTEM_NAME in this file should be changed? Or just the ones that affect Android?

@jrose-apple
Copy link
Contributor

Well, let's see:

  • This one is about both the linker being used and the target system (what to link against).
  • This one is about the target system, but depends on a Cygwin toolchain.
  • This one is only about the target system.
  • The actual change to what libraries are linked looks a lot like the earlier check that adds ICU for Linux.

The `add_swift_library` CMake function takes an optional `TARGET_SDKS`
parameter. When used, only CMake targets for the specified SDKs are
added.

Change `stdlib/public/core` to use this parameter for Android,
which prevents link flags intended for macOS/iOS targets from being
used when building for Android.
@modocache modocache force-pushed the stdlib-core-cmake-android-target-sdks branch from 8545ee0 to 4fb977f Compare October 5, 2016 18:08
@modocache
Copy link
Contributor Author

I took another look at what part of these changes were really necessary to get things building. Some of the linker flags, like -all_load, would be nice to exclude, but the Android linker simply ignores them, so we get off with a warning.

The one important thing to get the Android runtime building on macOS is to prevent framework dependencies on Foundation and CoreFoundation. I amended the pull request to share all parameters across the two target sets, but not set FRAMEWORK_DEPENDS for non-Darwin targets.

This is based on @gottesmm's comment in #5004, advising I reduce the scope of the changes.

@jrose-apple, is this closer to what you had in mind?

@jrose-apple
Copy link
Contributor

That new version doesn't handle ICU the way you wanted, correct?

I really just want one call to add_swift_library. At this point the only difference is the FRAMEWORK_DEPENDS, and those are definitely based on the target SDK.

@modocache
Copy link
Contributor Author

modocache commented Oct 5, 2016

Ah, OK, thanks! So basically we want this, but without using TARGET_SDKS and two calls to add_swift_library, right?

@modocache
Copy link
Contributor Author

I really just want one call to add_swift_library.

Just for the record, #5002 and #5003 make multiple calls to add_swift_library. 😅

@jrose-apple
Copy link
Contributor

Well then I'm not happy about those either. :-)

I'm not sure what the right answer is in general. I mostly like the SWIFT_MODULE_DEPENDS model, where we ended up adding variants for all the Apple platforms, but that has to be done manually for every argument and every platform variant right now. (And it doesn't allow groups like "all Apple platforms".)

@jrose-apple
Copy link
Contributor

I feel like options should be added to all libraries by default, though, and that you should have to stop and think when it turns out they're only applicable to some.

@modocache
Copy link
Contributor Author

One option would be adding FRAMEWORK_DEPENDS_OSX, FRAMEWORK_DEPENDS_IOS, and so on. These could work similarly to how SWIFT_MODULE_DEPENDS works.

@gottesmm
Copy link
Contributor

gottesmm commented Oct 9, 2016

@modocache @jrose-apple I think that sounds like a reasonable solution. In general, I dislike declaring the same library multiple times.

It feels like it is screaming to be refactored.

@gottesmm
Copy link
Contributor

gottesmm commented Oct 9, 2016

It may be good to look into the other cases where we used the TARGET_SDKS for Android and see if we can do similar refactoring.

@modocache
Copy link
Contributor Author

I don't need this for building static libraries, so I'll close this for now. After #4972 is merged, I'll send another pull request with a different approach for dynamic libraries.

@modocache modocache closed this Oct 10, 2016
@modocache
Copy link
Contributor Author

Thanks for the reviews, though! Very much appreciated!

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