Search code examples
swiftantlr4swift-package-manager

Why is my Antlr4 (4.11.1) project failing to build with Swift Package Manager?


My new Swift project is not building with the latest version of Antlr4.
I have created projects similar projects before (with Antlr 4.10), but I am only getting issues with Antlr 4.11 and 4.11.1 . I get the following error

https://github.com/antlr/antlr4 @ 4.11.1: error: /Package.swift has no Package.swift manifest for version 4.11.1 in https://github.com/antlr/antlr4

Below is my Package.swift file

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "spl-swift",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
        //.package(url: "/private/tmp/Antlr4-tmp-1663142993", from: "4.0.0")
        .package(url: "https://github.com/antlr/antlr4", from: "4.11.1")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .executableTarget(
            name: "spl-swift",
            dependencies: [
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                "Antlr4"
            ]),
        .testTarget(
            name: "spl-swiftTests",
            dependencies: ["spl-swift"]),
    ]
)

Solution

  • I don't know why I was getting this problem with 4.11.1 but I was able to get it working by downloading release 4.10.1 and using it as a local dependency

    // swift-tools-version:5.7
    // The swift-tools-version declares the minimum version of Swift required to build this package.
    
    import PackageDescription
    
    let package = Package(
        name: "spl-swift",
        dependencies: [
            .package(name: "Antlr4", path: "~/Downloads/antlr4-4.10.1"),
            .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
            //.package(url: "https://github.com/antlr/antlr4", from: "4.11.1")
        ],
        targets: [
            // Targets are the basic building blocks of a package. A target can define a module or a test suite.
            // Targets can depend on other targets in this package, and on products in packages this package depends on.
            .executableTarget(
                name: "spl-swift",
                dependencies: [
                    .product(name: "ArgumentParser", package: "swift-argument-parser"),
                    "Antlr4"
                ],
                exclude: [
                "Lang.tokens",
                "LangLexer.interp",
                "LangLexer.tokens",
                "Lang.interp"
            ]),
            .testTarget(
                name: "spl-swiftTests",
                dependencies: ["spl-swift"]),
        ]
    )