Skip to content

fix(cmake): build SwiftCompilerPlugin by default so install can find it - #3443

Merged
rintaro merged 3 commits into
swiftlang:mainfrom
bunnysayzz:fix/cmake-install-swiftcompilerplugin-3438
Oct 10, 2026
Merged

rintaro merged 3 commits into
swiftlang:mainfrom
bunnysayzz:fix/cmake-install-swiftcompilerplugin-3438

Conversation

@bunnysayzz

Copy link
Copy Markdown
Contributor

Fixes #3438.

Root cause: Sources/SwiftCompilerPlugin/CMakeLists.txt marked the target EXCLUDE_FROM_ALL, so a plain cmake --build never produced libSwiftCompilerPlugin.a while the generated install rules still referenced it. cmake --install died at Sources/SwiftCompilerPlugin/cmake_install.cmake:41. Every other library under Sources/ builds by default; this one was the outlier.

Fix: drop EXCLUDE_FROM_ALL (one line). Verified on macOS with the Xcode CLT toolchain: fresh Ninja Release configure + build + install to a prefix now completes end to end, and libSwiftCompilerPlugin.a lands in lib/swift/host alongside the rest.

Note: as jcm93 found, the install still only moves bare .a files with no headers or package config, so downstream findability is a possible follow-up. This PR fixes the reported crash; happy to extend if maintainers want the fuller install story here.

The target was EXCLUDE_FROM_ALL, so a plain cmake --build never
produced libSwiftCompilerPlugin.a and cmake --install died at
Sources/SwiftCompilerPlugin/cmake_install.cmake:41. Every other
library in Sources/ builds by default; this one was the outlier.

Verified: fresh configure + build + install to a prefix now
completes, and libSwiftCompilerPlugin.a lands in
lib/swift/host alongside the rest.

Fixes swiftlang#3438

@rintaro rintaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

libSwiftCompilerPlugin.a lands in lib/swift/host alongside the rest.

We do not want libSwiftCompilerPlugin in the toolchain and that is exactly the reason we added EXCLUDE_FROM_ALL iirc.

If the generated install rules including it is the problem, is it possible to fix that instead?

Per review, building SwiftCompilerPlugin by default was the wrong fix:
EXCLUDE_FROM_ALL is intentional to keep it out of the toolchain.
Instead, add_swift_syntax_library() now skips the install and export
rules for targets marked EXCLUDE_FROM_ALL, so cmake --install no
longer references the never-built libSwiftCompilerPlugin.a.

@bunnysayzz bunnysayzz left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point, that was the wrong fix. Reworked it per your suggestion: reverted the EXCLUDE_FROM_ALL removal, and instead add_swift_syntax_library now skips the install/export rules for targets marked EXCLUDE_FROM_ALL. So cmake --install no longer references the never-built lib, and it stays out of the toolchain. Pushed.

@rintaro rintaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Overall looks fine, but I have one suggestion, what do you think?

Comment thread cmake/modules/AddSwiftHostLibrary.cmake Outdated

# Add a new host library with the given name.
function(add_swift_syntax_library name)
cmake_parse_arguments(ASHL "EXCLUDE_FROM_ALL" "" "" ${ARGN})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of parsing ARGN, I think it's cleaner to read the target property after add_library:

i.e.

get_target_property(ASHL_EXCLUDE_FROM_ALL ${target} EXCLUDE_FROM_ALL)
if(NOT ASHL_EXCLUDE_FROM_ALL)
  ....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good call, switched it to get_target_property. pushed.

@rintaro

rintaro commented Oct 9, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

@rintaro

rintaro commented Oct 9, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test Linux

@rintaro
rintaro merged commit 09b1d91 into swiftlang:main Oct 10, 2026
80 of 81 checks passed
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.

Installing swift-syntax with cmake --install fails

2 participants