swiftlang / swiftlang/swift-syntax

Compiling using cmake with `SWIFTSYNTAX_EMIT_MODULE=ON` fails on clean builds

Open
#3,444 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

### Description

Building with `SWIFTSYNTAX_EMIT_MODULE=ON` results in the following error messages:
```
:0: error: error opening '/Users/candy/Desktop/swift-syntax/build/lib/swift/host/SwiftSyntax.swiftmodule/arm64-apple-macos.swiftinterface' for output:
/Users/candy/Desktop/swift-syntax/build/lib/swift/host/SwiftSyntax.swiftmodule/arm64-apple-macos.swiftinterface: Not a directory
```
The issue only appears to occur when building from a build directory that has not yet successfully built a version with `SWIFTSYNTAX_EMIT_MODULE` enabled.

After some investigation, it appears that this issue started occurring after f00e7ae. Modifying the CMakeLists.txt file on `main` to set `cmake_minimum_required` back to `3.19.6` seems to work around the issue.

### Steps to Reproduce

1. Delete your current build directory
2. `mkdir build && cd build`
3. `cmake .. -GNinja -DSWIFTSYNTAX_EMIT_MODULE=ON`
4. `cmake --build . --target all --target SwiftCompilerPlugin`
5. Notice the error message.

Now, edit `CMakeLists.txt` to say `cmake_minimum_required(VERSION 3.19.6)`, and repeat the steps above. The build should complete successfully. Note that if you update `cmake_minimum_required` back to `3.29`, builds will succeed until you delete your build folder.

Contributor guide

Open the contributing guide

Research direction

Start with CMakeLists.txt and reproduce the failure from a clean build directory using Ninja and SWIFTSYNTAX_EMIT_MODULE=ON. Compare the behavior with cmake_minimum_required set to 3.19.6 and 3.29, and inspect the change after f00e7ae. Done means the clean build completes successfully without the Not a directory error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, swift
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.