Skip to content

Commit 97812db

Browse files
committed
Update readme
1 parent 01a4732 commit 97812db

File tree

2 files changed

+90
-53
lines changed

2 files changed

+90
-53
lines changed

README.md

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ Its API is designed for performance-critical applications. It uses value types a
1313
## Usage
1414

1515
### Declare SwiftPM dependency with release tag
16+
1617
Add this repository to the `Package.swift` manifest of your project:
1718

1819
```swift
19-
// swift-tools-version:5.2
20+
// swift-tools-version:5.3
2021
import PackageDescription
2122

2223
let package = Package(
@@ -32,46 +33,42 @@ let package = Package(
3233

3334
Replace `<#Specify Release tag#>` by the version of SwiftSyntax that you want to use (see the following table for mapping details).
3435

35-
3636
| Xcode Release | Swift Release Tag | SwiftSyntax Release Tag |
3737
|:-------------------:|:-------------------:|:-------------------------:|
3838
| Xcode 13.0 | swift-5.5-RELEASE | 0.50500.0 |
3939
| Xcode 12.5 | swift-5.4-RELEASE | 0.50400.0 |
4040
| Xcode 12.0 | swift-5.3-RELEASE | 0.50300.0 |
4141
| Xcode 11.4 | swift-5.2-RELEASE | 0.50200.0 |
4242

43-
4443
Then, import `SwiftSyntax` in your Swift code.
4544

46-
4745
### Declare SwiftPM dependency with nightly build
4846

4947
1. Download and install the latest Trunk Development [toolchain](https://swift.org/download/#snapshots).
5048

5149
2. Define the `TOOLCHAINS` environment variable as below to have the `swift` command point inside the toolchain:
52-
53-
```
54-
$ export TOOLCHAINS=swift
55-
```
50+
```bash
51+
$ export TOOLCHAINS=swift
52+
```
5653

5754
3. To make sure everything is set up correctly, check the result of `xcrun --find swift`. It should point inside the OSS toolchain.
5855

5956
4. Add this entry to the `Package.swift` manifest of your project:
6057

61-
```swift
62-
// swift-tools-version:4.2
63-
import PackageDescription
64-
65-
let package = Package(
66-
name: "MyTool",
67-
dependencies: [
68-
.package(url: "https://github.com/apple/swift-syntax.git", .revision("swift-DEVELOPMENT-SNAPSHOT-2019-02-26")),
69-
],
70-
targets: [
71-
.target(name: "MyTool", dependencies: ["SwiftSyntax"]),
72-
]
73-
)
74-
```
58+
```swift
59+
// swift-tools-version:5.3
60+
import PackageDescription
61+
62+
let package = Package(
63+
name: "MyTool",
64+
dependencies: [
65+
.package(url: "https://github.com/apple/swift-syntax.git", .revision("swift-DEVELOPMENT-SNAPSHOT-2019-02-26")),
66+
],
67+
targets: [
68+
.target(name: "MyTool", dependencies: ["SwiftSyntax"]),
69+
]
70+
)
71+
```
7572

7673
Tags will be created for every nightly build in the form of `swift-DEVELOPMENT-SNAPSHOT-<DATE>`. The revision field
7774
should be specified with the intended tag.
@@ -85,7 +82,7 @@ SwiftSyntax depends on the `lib_InternalSwiftSyntaxParser.dylib/.so` library whi
8582

8683
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:
8784

88-
```
85+
```bash
8986
git clone https://github.com/apple/swift.git
9087
./swift/utils/update-checkout --clone
9188
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build
@@ -95,7 +92,7 @@ git clone https://github.com/apple/swift.git
9592

9693
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-parser-lib` accordingly:
9794

98-
```
95+
```bash
9996
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build-iossim --host iphonesimulator --architectures x86_64
10097
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build-ios --host iphoneos --architectures arm64
10198
```
@@ -143,28 +140,26 @@ Since SwiftSyntax relies on definitions in the main Swift repository to generate
143140
To build the `main` branch of SwiftSyntax, follow the following instructions:
144141

145142
1. Check `swift-syntax` and `swift` out side by side:
146-
147-
```
148-
- (enclosing directory)
149-
- swift
150-
- swift-syntax
151-
```
143+
```
144+
- (enclosing directory)
145+
- swift
146+
- swift-syntax
147+
```
152148

153149
2. Make sure you have a recent [Trunk Swift Toolchain](https://swift.org/download/#snapshots) installed.
154150
3. Define the `TOOLCHAINS` environment variable as below to have the `swift` command point inside the toolchain:
155151

156-
```
157-
$ export TOOLCHAINS=swift
158-
```
152+
```bash
153+
$ export TOOLCHAINS=swift
154+
```
159155

160156
4. To make sure everything is set up correctly, check the return statement of `xcrun --find swift`. It should point inside the latest installed trunk development toolchain. If it points inside an Xcode toolchain, check that you exported the `TOOLCHAINS` environment variable correctly. If it points inside a version-specific toolchain (like Swift 5.0-dev), you'll need to remove that toolchain.
161157
5. Run `swift-syntax/build-script.py`.
158+
If despite following those instructions, you get compiler errors, the Swift toolchain might be too old to contain recent changes in Swift's SwiftSyntaxParser C library. In that case, you'll have to build the compiler and SwiftSyntax together with the following command:
162159
163-
If despite following those instructions, you get compiler errors, the Swift toolchain might be too old to contain recent changes in Swift's SwiftSyntaxParser C library. In that case, you'll have to build the compiler and SwiftSyntax together with the following command:
164-
165-
```
166-
$ swift/utils/build-script --swiftsyntax --swiftpm --llbuild
167-
```
160+
```bash
161+
$ swift/utils/build-script --swiftsyntax --swiftpm --llbuild
162+
```
168163
169164
Swift-CI will automatically run the code generation step whenever a new toolchain (development snapshot or release) is published. It should thus almost never be necessary to perform the above build yourself.
170165
@@ -173,12 +168,15 @@ Afterward, SwiftPM can also generate an Xcode project to develop SwiftSyntax by
173168
If you also want to run tests locally, read the section below as testing has additional requirements.
174169
175170
### Local Testing
171+
176172
SwiftSyntax uses some test utilities that need to be built as part of the Swift compiler project. To build the most recent version of SwiftSyntax and test it, follow the steps in [swift/README.md](https://github.com/apple/swift/blob/main/README.md) and pass `--llbuild --swiftpm --swiftsyntax` to the build script invocation to build SwiftSyntax and all its dependencies using the current trunk (`main`) compiler.
177173
178174
SwiftSyntax can then be tested using the build script in `apple/swift` by running
179-
```
175+
176+
```bash
180177
swift/utils/build-script --swiftsyntax --swiftpm --llbuild -t --skip-test-cmark --skip-test-swift --skip-test-llbuild --skip-test-swiftpm
181178
```
179+
182180
This command will build SwiftSyntax and all its dependencies, tell the build script to run tests, but skip all tests but the SwiftSyntax tests.
183181
184182
Note that it is not currently supported by SwiftSyntax while building the Swift compiler using Xcode.
@@ -244,5 +242,4 @@ let y = 3001
244242
245243
## License
246244
247-
Please see [LICENSE](LICENSE.txt) for more information.
248-
245+
Please see [LICENSE](LICENSE.txt) for more information.

Sources/SwiftSyntaxBuilder/README.md

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,70 @@
1-
# SwiftSyntaxBuilder
1+
# Swift Syntax Builder
22

3-
Declarative and type-safe wrapper around SwiftSyntax.
3+
**Swift Syntax Builder** is an open-source package for generating Swift code in a declarative way.
44

5-
## Example Usage
5+
> Note: SwiftSyntaxBuilder is still in development, and the API is not guaranteed to
6+
> be stable. It's subject to change without warning.
67
78
```swift
8-
let sourceFile = SourceFile {
9-
Import("SwiftSyntax")
9+
import SwiftSyntaxParser
1010

11-
Struct("ExampleStruct") {
12-
Let("syntax", of: "Syntax")
13-
}
11+
let source = SourceFile {
12+
ImportDecl(path: "Foundation")
13+
ImportDecl(path: "UIKit")
14+
ClassDecl(classOrActorKeyword: .class, identifier: "SomeViewController", membersBuilder: {
15+
VariableDecl(.let, name: "tableView", type: "UITableView")
16+
})
1417
}
1518

16-
let syntax = sourceFile.buildSyntax(format: format, leadingTrivia: .zero)
19+
let syntax = source.buildSyntax(format: Format())
1720

1821
var text = ""
1922
syntax.write(to: &text)
23+
2024
print(text)
2125
```
2226

2327
prints:
2428

2529
```swift
26-
import SwiftSyntax
27-
struct ExampleStruct {
28-
let syntax: Syntax
30+
import Foundation
31+
import UIKit
32+
class SomeViewController{
33+
let tableView: UITableView
2934
}
3035
```
36+
37+
## Usage
38+
39+
### Declare SwiftPM dependency with release tag
40+
41+
Add this repository to the `Package.swift` manifest of your project:
42+
43+
```swift
44+
// swift-tools-version:5.3
45+
import PackageDescription
46+
47+
let package = Package(
48+
name: "MyTool",
49+
dependencies: [
50+
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .exact("<#Specify Release tag#>")),
51+
],
52+
targets: [
53+
.target(name: "MyTool", dependencies: ["SwiftSyntaxBuilder"]),
54+
]
55+
)
56+
```
57+
58+
Replace `<#Specify Release tag#>` by the version of SwiftSyntaxBuilder that you want to use. See this following [table](https://github.com/apple/swift-syntax#declare-swiftpm-dependency-with-release-tag) for mapping details.
59+
60+
Then, import `SwiftSyntaxBuilder` in your Swift code.
61+
62+
Note that SwiftSyntaxBuilder has limited support for pretty-printing code. We generally suggest running a formatter like [swift-format](https://github.com/apple/swift-format) on the generated code.
63+
64+
### Reporting Issues
65+
66+
If you should hit any issues while using SwiftSyntaxBuilder, we appreciate bug reports on [bugs.swift.org](https://bugs.swift.org) in the [SwiftSyntax component](https://bugs.swift.org/issues/?jql=component%20%3D%20SwiftSyntax).
67+
68+
## License
69+
70+
Please see [LICENSE](https://github.com/apple/swift-syntax#license) for more information.

0 commit comments

Comments
 (0)