Path referenced target relative to some base folder

In other build systems like Bazel and Buck, you can reference other build targets by using a notation that indicates a path to target describing file relative to some base folder. E.g. in Buck, you'd do

//libraries/core/log:log

Which will look for BUCK file at libraries/core/log/BUCK and then use log target from it as dependency. This works relative to .buckconfig file which is usually added to the root of the repo.

In SPM, there is a path based target dependency present, but in order to use it, you have to use relative paths which is annoying a bit.

    dependencies: [
        .package(
            path: "../../../../Printer"
        ),
    ],

Are there any plans to introduce a syntax to reference the targets in local Package.swift files in a cleaner way? Perhaps, something like

    dependencies: [
        .package(
            pathRelativeToRepositoryRoot: "Libraries/Printer"
        ),
    ],
2 Likes

The general idea seems reasonable to me. I'd prefer to configure this using the existing path: parameter though. Maybe something like path: .repositoryRoot("Libraries/Printer"). The existing semantics and .repositoryRoot will be equivalent when the package is already at the repo root so maybe SwiftPM should allow only one of them in that case.

The existing semantics and .repositoryRoot will be equivalent when the package is already at the repo root so maybe SwiftPM should allow only one of them in that case.

Didn’t get you, could you elaborate with a sample case please?

Oh, I just meant if you have a layout like this where the package is already the top-level:

.
├── .git
├── .gitignore
├── MyOtherPackage
├── Package.swift
├── README.md
├── Sources
└── Tests

then, .package(path: "MyOtherPackage") is equivalent to .package(path: .repositoryRoot("MyOtherPackage")).