SwiftPM command line tool: I added the products: param to Package, now where is the executable output?

The project was created with:

swift package init --type tool --name $1

Package.swift:

let package = Package(
    name: "WebGrep",
    platforms: [.macOS(.v14)],
    products: [
      .executable(name: "webgrep", targets: ["WebGrep"])
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.0"),
        .package(url: "https://github.com/scinfu/SwiftSoup.git", .upToNextMajor(from: "2.6.1")),
        .package(url: "https://github.com/pakLebah/ANSITerminal", from: "0.0.3"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "WebGrep",
            dependencies: [
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                .product(name: "SwiftSoup", package: "SwiftSoup"),
                .product(name: "ANSITerminal", package: "ANSITerminal"),
            ]
        ),
    ]
)

After I added the products arg, I can't find the executable. where is it?

I did a find but didn’t find :(

Did you do ls -a and look under .build/x86_64-apple-macosx/debug?

there is no .build dir where Package.swift is

So I did:

xcode-select -swiftch Xcode-beta.app

swift build

now it produce executable in .build

but building from within Xcode, where is the executable?

Go Product/Show Build Folder in Finder

Compile with Xcode doesn't output any executable to where Product/Show Build Folder in Finder

Run inside Xcode now:

Could not launch “WebGrep”
Could not launch “WebGrep”
Domain: IDELaunchErrorDomain
Code: 20
Recovery Suggestion: The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error.

If I comment out products: parameter, I can Run inside Xcode.

So this tells me I should not pass products: parameter. This allows for build/run inside Xcode and swift build on command line.

Is there good tutorial on how to use Package?

I think, the last two products are giving you the grief.

I can run the executable produced by the following Package.swift, from the Terminal and the Xcode.

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

import PackageDescription

let package = Package(
    name: "WebGrep",
    platforms: [.macOS(.v14)],
    dependencies: [
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "WebGrep",
            dependencies: [
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
            ]
        ),
    ]
)

Yes, just don’t pass products: and it works in Xcode and command line.