Skip to content

Conversation

kateinoigakukun
Copy link
Member

Serialize the -public-autolink-library <name> option to the moduleinterface file because it can affect the LINK_LIBRARY entries in a swiftmodule file. Without saving the option being saved, specified libraries won't be linked when a module compiled from the moduleinterface is used.

This change marks the -public-autolink-library option as a module interface option and reads it when building a swiftmodule by module loader.

Close swiftwasm#5580

Serialize the `-public-autolink-library <name>` option to the
moduleinterface file because it can affect the LINK_LIBRARY entries in a
swiftmodule file. Without saving the option, the library won't be linked
when a module compiled from the moduleinterface is used.

This change marks the `-public-autolink-library` option as a module
interface option and reads it when building a swiftmodule by module
loader.
@kateinoigakukun
Copy link
Member Author

@swift-ci smoke test

@kateinoigakukun
Copy link
Member Author

@swift-ci build toolchain

@MaxDesiatov
Copy link
Contributor

Should we be concerned about the macOS toolchain failure?

@MaxDesiatov MaxDesiatov requested review from etcwilde and bnbarham June 11, 2024 14:10
@kateinoigakukun
Copy link
Member Author

curl: (55) Send failure: Broken pipe

The macOS failure is just a networking problem, and the toolchain build itself is fine 👍

@MaxDesiatov
Copy link
Contributor

That failure should be intermittent then

@MaxDesiatov
Copy link
Contributor

@swift-ci build toolchain macos

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

We already use -autolink-force-load in .swiftinterface files to indicate that the module corresponds to a library which must be auto-linked by clients. Combined with -module-link-name <name> to set link library name.

Why is this new mechanism required?

@kateinoigakukun
Copy link
Member Author

@artemcm This -public-autolink-library option is usually used to tell transitive public dependencies of private dependencies to module clients when static linking. (Usually not used for dynamic linking cases because a .so/.dylib itself can have their library dependencies.)

For example, we have a dependency relationship: Foundation -> CoreFoundation -> icu4c where:

  • Foundation imports CoreFoundation with @_implementationOnly as a private dependency.
  • libFoundation.a includes all object files of both Foundation and CoreFoundation, but not icu4c.
  • libicu4c.a can be pulled by other libraries, so cannot be merged into libFoundation.a.

In this case, we use -public-autolink-library icu4c to construct Foundation.swiftmodule for static-linking version. Then importing Foundation module emits licu4c auto-link entry into the module client.

https://github.com/apple/swift-corelibs-foundation/blob/ca3669eb9ac282c649e71824d9357dbe140c8251/Sources/Foundation/CMakeLists.txt#L201-L206
swiftlang/swift-corelibs-foundation#2996

module-link-name <name> is something to set a library name of the module itself, but -public-autolink-library is something to set library names of the transitive public dependencies (e.g. libicu4c.a) of private dependencies (e.g. CoreFoundation).

At least, swiftmodules with and without -public-autolink-library are different and it leads pre-compiled swiftmodule installed in a toolchain and swiftmodule re-compiled from swiftinterface can be inconsistent.

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

Makes sense. Thank you for the explanation.

@kateinoigakukun
Copy link
Member Author

Thank you for your review!

@kateinoigakukun kateinoigakukun merged commit 8428b36 into swiftlang:main Jun 11, 2024
@kateinoigakukun kateinoigakukun deleted the katei/save-public-autolink-library-interface branch June 11, 2024 23:21
@MaxDesiatov MaxDesiatov added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jun 12, 2024
kateinoigakukun added a commit to swiftwasm/carton that referenced this pull request Jun 20, 2024
It's fixed in the main branch and cherry-picked to the 6.0 branch.

See swiftlang/swift#74277
kateinoigakukun added a commit to swiftwasm/carton that referenced this pull request Jun 20, 2024
It's fixed in the main branch and cherry-picked to the 6.0 branch.

See swiftlang/swift#74277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined symbols (RegexParser)
3 participants