Swift - 无法导入包

Swift - Can't import packages

我一直在 Ubuntu 20.10 上试用 Swift,但在导入包时遇到问题。 Swift 安装正确。无论我尝试哪个包,我总是得到 error: no such module
这是我的Package.swift(以大使馆为例):

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

import PackageDescription

let package = Package(
        name: "test",
        /* products: [
             .executable(name: "test", targets: ["test"])
         ],*/
        dependencies: [
            // Dependencies declare other packages that this package depends on.
            // .package(url: /* package url */, from: "1.0.0"),
            .package(url: "https://github.com/envoy/Embassy.git",
                    from: "4.1.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.
            .target(
                    name: "test",
                    dependencies: []),
            .testTarget(
                    name: "testTests",
                    dependencies: ["test"]),
        ]
)


main.swift(低于Sources/test

import Foundation
import Embassy
let loop = try! SelectorEventLoop(selector: try! KqueueSelector())
let server = DefaultHTTPServer(eventLoop: loop, port: 8080) {
    (
            environ: [String: Any],
            startResponse: ((String, [(String, String)]) -> Void),
            sendBody: ((Data) -> Void)
    ) in
    // Start HTTP response
    startResponse("200 OK", [])
    let pathInfo = environ["PATH_INFO"]! as! String
    sendBody(Data("the path you're visiting is \(pathInfo.debugDescription)".utf8))
    // send EOF
    sendBody(Data())
}

// Start HTTP server to listen on the port
try! server.start()

// Run event loop
loop.runForever()

在您的 Package.swift 文件中,您将 Embassy 声明为依赖项,但您并未在任何目标中引用该依赖项。在您提供的示例中,您可以像这样更改您的包:

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

import PackageDescription

let package = Package(
    name: "test",
    dependencies: [
        .package(url: "https://github.com/envoy/Embassy.git", from: "4.1.1"),
    ],
    targets: [
        // Reference the 'Embassy' package here.
        .target(name: "test", dependencies: ["Embassy"]),
        .testTarget(name: "testTests", dependencies: ["test", "Embassy"]),
    ]
)