Skip to content

[CMake] Allow *only* static stdlib to be built #2431

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

modocache
Copy link
Contributor

@modocache modocache commented May 6, 2016

What's in this pull request?

Prior to these changes, it was only possible to build static libraries for the standard library and SDK overlays if also building dynamic libraries. This is problematic if, for example, you wanted to defer the linking of the standard library build products until later.

These changes allow you to build only static libraries, using something like the following command:

$ utils/build-script -R --skip-build-benchmarks \
    -- --build-swift-static-stdlib=1 --build-swift-dynamic-stdlib=0

Resolved bug number: None


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
OS X platform @swift-ci Please test OS X platform
Linux platform @swift-ci Please test Linux platform

Note: Only members of the Apple organization can trigger swift-ci.

@modocache modocache force-pushed the build-just-static-stdlib branch 2 times, most recently from 06b8047 to b2f7d5f Compare May 6, 2016 23:36
@tkremenek
Copy link
Member

@swift-ci test

@tkremenek
Copy link
Member

@modocache On Linux we get this failure:

...swift/stdlib/public/runtime/swift_sections.S:20:2: error: "Define SWIFT_BEGIN or SWIFT_END to compile this file."
#error "Define SWIFT_BEGIN or SWIFT_END to compile this file."
 ^

@modocache modocache force-pushed the build-just-static-stdlib branch from b2f7d5f to aea3c01 Compare May 9, 2016 15:37
@modocache
Copy link
Contributor Author

@swift-ci please test

option(SWIFT_BUILD_STDLIB
"Build the Swift standard library (independent of the SDK headers)"
TRUE)

Copy link
Contributor

@gribozavr gribozavr May 9, 2016

Choose a reason for hiding this comment

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

Sorry, the names are confusing here. This option controls the build of the core standard library (stdlib/public/CMakeLists.txt):

if(SWIFT_BUILD_STDLIB)
  # These must be kept in dependency order so that any referenced targets
  # exist at the time we look for them in add_swift_*.
  add_subdirectory(SwiftShims)
  add_subdirectory(runtime)
  add_subdirectory(stubs)
  add_subdirectory(core)
  add_subdirectory(SwiftOnoneSupport)
  add_subdirectory(Reflection)
  add_subdirectory(SwiftRemoteMirror)
endif()

The variables allow building just the compiler, or the compiler + core library, or just the SDK overlay using an existing compiler.

@jrose-apple
Copy link
Contributor

Shouldn't the SDK overlay also come in both static and non-static variants?

@modocache
Copy link
Contributor Author

Aha, I see... I'll take another look at this. I hadn't looked too closely at the SDK overlay parts. I'll try to address:

  • Building only the SDK overlay. I'm not certain these changes affect that build, but I'll try it out and see.
  • Making sure the dynamic/static distinction makes sense with the SDK overlay taken into account. Perhaps this means adding dynamic/static variants to the SDK overlay as well?

Does that sound reasonable?

@gribozavr
Copy link
Contributor

@modocache Absolutely! I think it would be best if we had orthogonal options for:

  • building the standard library (build-swift-stdlib);
  • building the SDK overlay (build-swift-sdk-overlay);
  • building dynamic variants of the target libraries (build-swift-dynamic-stdlib);
  • building static variants of the target libraries (build-swift-static-stdlib).

@modocache modocache force-pushed the build-just-static-stdlib branch from aea3c01 to 2827d1c Compare May 12, 2016 21:45
@modocache
Copy link
Contributor Author

modocache commented May 13, 2016

Sorry for the lack of updates here. I'm still working on this, but things get tricky since different sets of options work or fail based on whether it's a "clean" build or not.

On master:

  • On master, a clean build with --build-swift-stdlib=0 --build-swift-sdk-overlay=0: ✅
  • On master, a clean build with --build-swift-stdlib=1 --build-swift-sdk-overlay=0: ✅
  • On master, a clean build with --build-swift-stdlib=0 --build-swift-sdk-overlay=1: ❌ (output)
  • On master, a clean build with --build-swift-stdlib=1 --build-swift-sdk-overlay=1: ✅
  • On master, after having build the Swift stdlib, a build with --build-swift-stdlib=0 --build-swift-sdk-overlay=1: ✅

With this pull request:

  • With this pull request, a clean build with --build-swift-{dynamic,static}-stdlib=0 --build-swift-{dynamic,static}-sdk-overlay=0: ✅
  • With this pull request, a clean build with --build-swift-{dynamic,static}-stdlib=1 --build-swift-{dynamic,static}-sdk-overlay=0: ✅
  • With this pull request, a clean build with --build-swift-{dynamic,static}-stdlib=0 --build-swift-{dynamic,static}-sdk-overlay=1: ❌
  • With this pull request, a clean build with --build-swift-{dynamic,static}-stdlib=1 --build-swift-{dynamic,static}-sdk-overlay=1: ✅
  • With this pull request, after having build the Swift {dynamic,static} stdlib, a clean build with --build-swift-{dynamic,static}-stdlib=0 --build-swift-{dynamic,static}-sdk-overlay=1: ❌

The major difference being that these changes don't allow building just the SDK overlay, whereas on master one is able to build just the SDK overlay (provided that the stdlib has already been built). This is because this pull request no longer adds targets for stdlib/SDK libraries that won't be built. For example, the swiftSwiftRemoteMirror target will not be added unless -build-swift-{dynamic,static}-stdlib is specified.

I understand that it's desirable to build just the SDK overlay, so I'm working on that. (I'm still trying to figure out how master works.)

@gribozavr
Copy link
Contributor

On master, a clean build with --build-swift-stdlib=0 --build-swift-sdk-overlay=1: ❌

Sorry, I didn't give you the full information. The way we use this mode is by disabling the compiler build as well, and using the compiler that was built during the time when the standard library was built. Basically, we build in two steps, first is compiler+stdlib, and then SDK overlay that uses the build products from the previous step that are already installed into Xcode.app. For the second step we have a preset that goes like this:

ios-all
tvos-all
watchos-all

dash-dash

install-swift=1
build-llvm=0
build-swift-tools=0
build-swift-stdlib=0
build-swift-sdk-overlay=1
native-llvm-tools-path=%(native_llvm_tools_path)s
native-clang-tools-path=%(native_clang_tools_path)s
native-swift-tools-path=%(native_swift_tools_path)s

swift-install-components=sdk-overlay

@modocache modocache force-pushed the build-just-static-stdlib branch from 2827d1c to 3919f10 Compare May 16, 2016 03:26
Prior to these changes, it was only possible to build static libraries
for the standard library and SDK overlays if *also* building dynamic
libraries. This is problematic if, for example, you wanted to defer the
linking of the standard library build products until later.

These changes allow you to build *only* static libraries, using
something like the following command:

```
$ utils/build-script -R --skip-build-benchmarks \
    -- --build-swift-static-stdlib=1 --build-swift-dynamic-stdlib=0
```
@modocache modocache force-pushed the build-just-static-stdlib branch from 3919f10 to 6a1c981 Compare May 23, 2016 17:41
set(all_library_targets)

# First up, we conditionally add a dynamic library target.
if(SWIFTLIB_IS_STDLIB OR SWIFTLIB_IS_SDK_OVERLAY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be SWIFTLIB_SINGLE_IS_STDLIB OR SWIFTLIB_SINGLE_IS_SDK_OVERLAY?

@gribozavr
Copy link
Contributor

@modocache Just wanted to say that I'm interested in getting this feature 👍

While reviewing the patch, I found some idiosyncrasies in our handling of shared/static libraries, which I have started to fix in #2809. I'm also thinking about changing the add_swift_library function to get an explicit annotation about the library: whether it is only shared, only static, or defers to the general stdlib policy. For example, we want libswiftReflection to always be static, and libswiftRemoteMirror to always be shared, so that libswiftRemoteMirror.dylib does not have other runtime dependencies.

@modocache
Copy link
Contributor Author

Just wanted to say that I'm interested in getting this feature

Oh good! Thanks, this is always good to hear. :)

I'm also thinking about changing the add_swift_library function to get an explicit annotation about the library: whether it is only shared, only static, or defers to the general stdlib policy.

Do you think it'd be simpler to update this pull request after this change is made? You wouldn't happen to have this work on a branch somewhere?

@gribozavr
Copy link
Contributor

gribozavr commented Jun 8, 2016

I'm also thinking about changing the add_swift_library function to get an explicit annotation about the library: whether it is only shared, only static, or defers to the general stdlib policy.

Do you think it'd be simpler to update this pull request after this change is made? You wouldn't happen to have this work on a branch somewhere?

Yes, I think it would be cleaner. The primary issue is that currently the CMake code is not set up around static/shared libraries; it builds a "primary" one (which is usually static for compiler components and shared for the standard library), and then it can build a secondary one, which is static for the standard library.

I have started that work with #2809 but we're not done yet. I'm currently swamped with other things unfortunately, so if you want to pick up the refactoring to clean up shared/static/global default library marking, go for it! Just let me know so that we are not duplicating work.

@modocache
Copy link
Contributor Author

@gribozavr I think I'll try my hand at this beginning today. I created https://bugs.swift.org/browse/SR-1738 to track progress. If you have any tips, I'd really appreciate them!

@modocache
Copy link
Contributor Author

Closing this in favor of #3020, #3027, and #3043. Will probably link back to this discussion often, though -- thanks for the feedback!

@modocache modocache closed this Jun 16, 2016
MaxDesiatov pushed a commit that referenced this pull request Apr 19, 2021
[pull] swiftwasm from main
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.

4 participants