Skip to content

Conversation

compnerd
Copy link
Member

In preparation for supporting static library linking on Windows, we are adjusting the library naming convention for static Swift libraries, preferring to use lib<name>.lib to differentiate them from the import library for a dynamic variant of the same library. This mechanism is already known to be used by Microsoft for ucrt (ucrt.lib vs libucrt.lib), and was previously used in Swift as well for the C++ interop libraries.

In preparation for supporting static library linking on Windows, we are
adjusting the library naming convention for static Swift libraries,
preferring to use `lib<name>.lib` to differentiate them from the import
library for a dynamic variant of the same library. This mechanism is
already known to be used by Microsoft for ucrt (`ucrt.lib` vs
`libucrt.lib`), and was previously used in Swift as well for the C++
interop libraries.
@compnerd
Copy link
Member Author

@swift-ci please test

@@ -96,7 +96,7 @@ if(NOT BUILD_SHARED_LIBS)
target_compile_options(FoundationEssentials PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _FoundationCShims>")
target_compile_options(FoundationEssentials PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _FoundationCollections>")
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend $<$<PLATFORM_ID:Windows>:${CMAKE_STATIC_LIBRARY_PREFIX_Swift}>_FoundationCollections>")
Copy link
Contributor

Choose a reason for hiding this comment

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

Two quick questions about these variables:

  1. Where is CMAKE_STATIC_LIBRARY_PREFIX_Swift set? Is that a known variable by CMake, or is that set somewhere else in the build script (in which case it might need a default set here for the standalone CMake build)?
  2. How does PLATFORM_ID:Windows compare to the other "windows platform" checks we have elsewhere in CMake via CMAKE_HOST_SYSTEM_NAME STREQUAL Windows or CMAKE_SYSTEM_NAME STREQUAL Windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. It is expected to be set by the user. It will eventually be defaulted to lib, but the current default is "". The variable is known by CMake, (CMAKE_* variables are meant to be CMake known variables). The current default is correct until further compiler changes are merged, but this allows testing to ensure that we cover all the cases with those changes.
  2. $<PLATFORM_ID:Windows> is a generator expression that is basically checking CMAKE_SYSTEM_NAME STREQUAL Windows in concept - are you building code meant to run on Windows? CMAKE_HOST_SYSTEM_NAME STREQUAL Windows is different in that it checks if you are building on Windows rather than building code that will run on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, makes sense! One more thing that I just realized: Should _FoundationCShims be treated the same way? It's also a static library that's statically linked into FoundationEssentials (and into FoundationInternationalization for that matter)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, _FoundationCShims is a C library and we aren't using a prefix there. We are using it in the Swift case to help allow us to merge the static and dynamic SDKs.

@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

1 similar comment
@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

@jmschonfeld
Copy link
Contributor

@swift-ci please test macOS platform

macOS CI is known to not be working right now and isn't a required check for merging (@shahmishal and team are working on upgrading the OS run by CI to fix that) so no need to test macOS. Also none of the CI on this repo will test the CMake build (yet - @shahmishal and team also working on that), if we want to truly test the CMake build the way to do that for right now is a cross-repo CI run from the swift repo which can build a toolchain / run full toolchain tests

@compnerd
Copy link
Member Author

Ah, okay, in that case, we should be good to go I think. The actual test will come later, right now this is just staging for additional testing and experimentation.

@jmschonfeld jmschonfeld merged commit d963e0b into swiftlang:main Jan 29, 2025
2 of 3 checks passed
@compnerd compnerd deleted the prefix branch January 29, 2025 20:44
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.

2 participants