Skip to content

Commit

Permalink
Add Swift Package Manager Support
Browse files Browse the repository at this point in the history
  • Loading branch information
100mango committed Mar 22, 2021
1 parent 3590d4d commit 3a7aca3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 46 deletions.
24 changes: 24 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version:5.3


import PackageDescription

let package = Package(
name: "Antlr4",
products: [
.library(
name: "Antlr4",
type: .static,
targets: ["Antlr4"]),
],
targets: [
.target(
name: "Antlr4",
dependencies: [],
path: "./runtime/Swift/Sources/Antlr4"),
.testTarget(
name: "Antlr4Tests",
dependencies: ["Antlr4"],
path:"./runtime/Swift/Tests/Antlr4Tests"),
]
)
1 change: 1 addition & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,4 @@ YYYY/MM/DD, github id, Full name, email
2021/02/27, khmarbaise, Karl Heinz Marbaise, [email protected]
2021/03/02, hackeris
2021/03/03, xTachyon, Damian Andrei, [email protected]
2021/03/22, 100mango, Fangqiu Fang, [email protected]
25 changes: 3 additions & 22 deletions doc/swift-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,11 @@ The runtime and generated grammar should now build correctly.

### Swift Package Manager Projects

Since we cannot have a separate repository for Swift target (see issue [#1774](https://github.com/antlr/antlr4/issues/1774)),
and Swift is currently not ABI stable. We currently support support SPM-based
projects by creating temporary local repository.
add Antlr4 as a dependency to your `Package.swift` file. For more information, please see the [Swift Package Manager documentation](https://github.com/apple/swift-package-manager/tree/master/Documentation).

For people using [Swift Package Manager](https://swift.org/package-manager/),
the __boot.py__ script supports generating local repository that can be used
as a dependency to your project. Simply run:

```
python boot.py --gen-spm-module
```swift
.package(name: "Antlr4", url: "https://github.com/antlr/antlr4", from: "4.9.3"
```

The prompt will show something like below:

<img src=images/gen_spm_module.png width="800">

Put the SPM directive that contains the url to temporary repository to your
project's Package.swift. And run `swift build` in your project.

The project is generated in your system's `/tmp/` directory, if you find it
inconvenient, consider copy that generated ANTLR repository to some place
that won't be cleaned automatically and update `url` parameter in your
`Package.swift` file.

## Swift access levels

You may use the `accessLevel` option to control the access levels on generated
Expand Down
24 changes: 0 additions & 24 deletions runtime/Swift/Package.swift

This file was deleted.

1 change: 1 addition & 0 deletions runtime/Swift/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def swift_test():
Run unit tests.
"""
generate_parser()
check_call(["cd","./../.."])
check_call(["swift", "test"])


Expand Down

0 comments on commit 3a7aca3

Please sign in to comment.