Skip to content

Commit ce11d7a

Browse files
authored
Merge pull request #1041 from CodaFi/manticore
Recore deprecated SwiftSyntaxParser on top of SwiftParser
2 parents 0a67557 + 3c1148c commit ce11d7a

20 files changed

+48
-1059
lines changed

Changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Note: This is in reverse chronological order, so newer entries are added to the
44

55
## `main`
66

7+
* With the introduction of the new `SwiftParser`, the existing `SwiftSyntaxParser` is deprecated and will be removed. The module and it's API surface still exists as a thin wrapper over `SwiftParser`, which no longer requires a matching toolchain or `_InternalSwiftSyntaxParser` shared library to work.
8+
9+
## Swift 5.6
10+
711
* To clarify that the edits passed to `IncrementalParseTransition` are applied concurrently, introduce a new `ConcurrentEdit` type that provides the guarantee and allows translation of sequentially applied edits to the expected concurrent form.
812
* The `SwiftSyntaxParser` type and a few related types now live in their own module (also named `SwiftSyntaxParser`). This allows using `SwiftSyntax` for code generation purposes without having a compatible `_InternalSwiftSyntaxParser.dylib` around.
913

@@ -86,7 +90,7 @@ Note: This is in reverse chronological order, so newer entries are added to the
8690
/* ... */
8791
}
8892
```
89-
93+
9094

9195
### Modelling syntax nodes as structs
9296

Documentation/Create SwiftSyntax Release.md

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,11 @@
22

33
## Create release tag
44
1. Check out the tag you want to release in the SwiftSyntax repository
5-
2. Download the matching Swift release from <https://swift.org> and install it
6-
3. Create an `.xcframework` by running
7-
```bash
8-
xcodebuild -create-xcframework -library /Library/Developer/Toolchains/<toolchain-name>.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib -output _InternalSwiftSyntaxParser.xcframework
9-
```
10-
4. Zip up the framework
11-
```bash
12-
zip -r _InternalSwiftSyntaxParser.xcframework.zip _InternalSwiftSyntaxParser.xcframework
13-
```
14-
5. Compute the checksum for the generated `.xcframework.zip`
15-
```bash
16-
/Library/Developer/Toolchains/<toolchain-name>.xctoolchain/usr/bin/swift package --package-path /path/to/swift-syntax/ compute-checksum _InternalSwiftSyntaxParser.xcframework.zip
17-
```
18-
6. Apply the following diff to `Package.swift`, adjusting `<release tag>` and `<checksum>`
19-
```diff
20-
diff --git a/Package.swift b/Package.swift
21-
index 4c6db83a..7a953fc6 100644
22-
--- a/Package.swift
23-
+++ b/Package.swift
24-
@@ -23,6 +23,21 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil
25-
swiftSyntaxSwiftSettings = []
26-
}
27-
28-
+// Include the parser library as a binary dependency if both the host and the target are macOS.
29-
+// - We need to require that the host is macOS (checked by `#if os(macOS)`) because package resolve will download and unzip the referenced framework, which requires `unzip` to be installed. Only macOS guarantees that `unzip` is installed, the Swift Docker images don’t have unzip installed, so package resolve would fail.
30-
+// - We need to require that the target is macOS (checked by `.when`) because binary dependencies are only supported by SwiftPM on macOS.
31-
+#if os(macOS)
32-
+let parserLibraryTarget: [Target] = [.binaryTarget(
33-
+ name: "_InternalSwiftSyntaxParser",
34-
+ url: "https://github.com/apple/swift-syntax/releases/download/<release tag>/_InternalSwiftSyntaxParser.xcframework.zip",
35-
+ checksum: "<checksum>"
36-
+)]
37-
+let parserLibraryDependency: [Target.Dependency] = [.target(name: "_InternalSwiftSyntaxParser", condition: .when(platforms: [.macOS]))]
38-
+#else
39-
+let parserLibraryTarget: [Target] = []
40-
+let parserLibraryDependency: [Target.Dependency] = []
41-
+#endif
42-
+
43-
let package = Package(
44-
name: "SwiftSyntax",
45-
products: [
46-
@@ -65,7 +80,7 @@ let package = Package(
47-
"Tokens.swift.gyb",
48-
]
49-
),
50-
- .target(name: "SwiftSyntaxParser", dependencies: ["SwiftSyntax"], exclude: [
51-
+ .target(name: "SwiftSyntaxParser", dependencies: ["SwiftSyntax"] + parserLibraryDependency, exclude: [
52-
"NodeDeclarationHash.swift.gyb"
53-
]),
54-
.target(
55-
@@ -90,5 +105,5 @@ let package = Package(
56-
dependencies: ["SwiftSyntax", "SwiftSyntaxParser"],
57-
exclude: ["Inputs"]
58-
),
59-
- ]
60-
+ ] + parserLibraryTarget
61-
)
62-
```
63-
7. Commit the changes
64-
8. Create a tag and push it to your personal GitHub repository
65-
9. On your personal GitHub repo create new release, select the tag, name it and upload `_InternalSwiftSyntaxParser.xcframework.zip`
66-
675
## Smoke test on macOS
686

697
1. Change the binary target in `Package.swift` to point to your personal GitHub repo
70-
2. Open the SwiftSyntax package with an Xcode version that contains no or an incompatible parser library
71-
3. Update to Latest Package Versions in Xcode
72-
4. Run tests
8+
2. Update to Latest Package Versions in Xcode
9+
3. Run tests
7310

7411
## Smoke test on Linux
7512

@@ -83,7 +20,7 @@ index 4c6db83a..7a953fc6 100644
8320
## Publish Release
8421

8522
1. Push tag to apple/swift-syntax
86-
2. On apple/swift-syntax create a new release using the just-pushed tag and upload the parser library as `_InternalSwiftSyntaxParser.xcframework.zip`
23+
2. On apple/swift-syntax create a new release using the just-pushed tag
8724
3. If this is a snapshot release, check “This is a pre-release”
8825
4. Publish 🎉
8926
5. Add the new release to README.md

Documentation/README.md

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,20 @@
22

33
## Usage
44

5-
### Declare SwiftPM dependency with nightly build
6-
7-
1. Download and install the latest Trunk Development [toolchain](https://swift.org/download/#snapshots).
8-
9-
2. Define the `TOOLCHAINS` environment variable as below to have the `swift` command point inside the toolchain:
10-
```bash
11-
$ export TOOLCHAINS=swift
12-
```
13-
14-
3. To make sure everything is set up correctly, check the result of `xcrun --find swift`. It should point inside the OSS toolchain.
15-
16-
4. Add this entry to the `Package.swift` manifest of your project:
17-
18-
```swift
19-
// swift-tools-version:5.3
20-
import PackageDescription
21-
22-
let package = Package(
23-
name: "MyTool",
24-
dependencies: [
25-
.package(url: "https://github.com/apple/swift-syntax.git", .revision("swift-DEVELOPMENT-SNAPSHOT-2019-02-26")),
26-
],
27-
targets: [
28-
.target(name: "MyTool", dependencies: ["SwiftSyntax"]),
29-
]
30-
)
31-
```
32-
33-
Tags will be created for every nightly build in the form of `swift-DEVELOPMENT-SNAPSHOT-<DATE>`. The revision field
34-
should be specified with the intended tag.
35-
36-
Different from building SwiftSyntax from source, declaring SwiftSyntax as a SwiftPM dependency doesn't require
37-
the Swift compiler source because we always push gyb-generated files to a tag.
38-
39-
### Embedding SwiftSyntax in an Application
40-
41-
SwiftSyntax depends on the `lib_InternalSwiftSyntaxParser.dylib/.so` library which provides a C interface to the underlying Swift C++ parser. When you do `swift build` SwiftSyntax links and uses the library included in the Swift toolchain. If you are building an application make sure to embed `_InternalSwiftSyntaxParser` as part of your application's libraries.
42-
43-
You can either copy `lib_InternalSwiftSyntaxParser.dylib/.so` directly from the toolchain or even build it yourself from the [Swift repository](https://github.com/apple/swift), as long as you are matching the same tags or branches in both the SwiftSyntax and Swift repositories. To build it for the host os (macOS/linux) use the following steps:
44-
45-
```bash
46-
git clone https://github.com/apple/swift.git
47-
./swift/utils/update-checkout --clone
48-
./swift/utils/build-tooling-libs --release --no-assertions --build-dir /tmp/tooling-libs-build
49-
```
50-
51-
If you see an error similar to the following:
52-
53-
```
54-
Outdated Swift compiler: building with host tools requires Swift 5.8 or
55-
newer. Please update your Swift toolchain or switch BOOTSTRAPPING_MODE to
56-
BOOTSTRAPPING(-WITH-HOSTLIBS)? or OFF.
5+
Add this entry to the `Package.swift` manifest of your project:
6+
7+
```swift
8+
// swift-tools-version:5.3
9+
import PackageDescription
10+
11+
let package = Package(
12+
name: "MyTool",
13+
dependencies: [
14+
.package(url: "https://github.com/apple/swift-syntax.git", .branch("main")),
15+
],
16+
targets: [
17+
.target(name: "MyTool", dependencies: ["SwiftSyntax"]),
18+
]
19+
)
5720
```
5821

59-
then you will need to build a newer compiler from source or download a more recent development snapshot from https://swift.org and pass its path to the script using the `--swiftc` flag:
60-
61-
```bash
62-
./swift/utils/build-tooling-libs --release --no-assertions --build-dir /tmp/tooling-libs-build --swiftc /path/to/newer/swiftc
63-
```
64-
65-
### Embedding in an iOS Application
66-
67-
You need to build `lib_InternalSwiftSyntaxParser.dylib` yourself, you cannot copy it from the toolchain. Follow the instructions above and change the invocation of `build-tooling-libs` accordingly:
68-
69-
```bash
70-
./swift/utils/build-tooling-libs --release --no-assertions --build-dir /tmp/tooling-libs-build-iossim --host iphonesimulator --architectures x86_64
71-
./swift/utils/build-tooling-libs --release --no-assertions --build-dir /tmp/tooling-libs-build-ios --host iphoneos --architectures arm64
72-
```

Package.swift

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil
2222
swiftSyntaxSwiftSettings = []
2323
}
2424

25-
/// If the `lib_InternalSwiftSyntaxParser.dylib` is not in the standard search
26-
/// paths (which is the standard case on macOS),
27-
/// `SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH` can be used to add a rpath at which
28-
/// the parser lib should be searched.
29-
let swiftSyntaxParserLinkerSettings: [LinkerSetting]
30-
if let parserLibSearchPath = ProcessInfo.processInfo.environment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] {
31-
swiftSyntaxParserLinkerSettings = [.unsafeFlags([
32-
"-Xlinker", "-rpath", "-Xlinker", parserLibSearchPath
33-
])]
34-
} else {
35-
swiftSyntaxParserLinkerSettings = []
36-
}
37-
3825
let package = Package(
3926
name: "SwiftSyntax",
4027
platforms: [
@@ -105,12 +92,7 @@ let package = Package(
10592
),
10693
.target(
10794
name: "SwiftSyntaxParser",
108-
dependencies: ["SwiftSyntax"],
109-
exclude: [
110-
"NodeDeclarationHash.swift.gyb",
111-
"Serialization.swift.gyb",
112-
],
113-
linkerSettings: swiftSyntaxParserLinkerSettings
95+
dependencies: ["SwiftSyntax", "SwiftParser"]
11496
),
11597
.target(
11698
name: "_SwiftSyntaxTestSupport",

Sources/SwiftSyntaxParser/CNodes.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

Sources/SwiftSyntaxParser/NodeDeclarationHash.swift.gyb

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)