Skip to content

Dependencies Unavailable to Plugins #5574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
filip-sakel opened this issue Jun 8, 2022 · 2 comments
Open

Dependencies Unavailable to Plugins #5574

filip-sakel opened this issue Jun 8, 2022 · 2 comments
Assignees

Comments

@filip-sakel
Copy link

Description

Adding local target dependencies or external dependencies to my plugin doesn't result in an error when declared in the package manifest. However, importing these dependencies in the plugin code makes SwiftPM complain that it can't find these modules.

Expected behavior

I'd expect to declare dependencies and be able to actually import them.

Actual behavior

An error is emitted when importing a module that was declared as a dependency in the plugin code. This is the case for both build tools and command tools.

Steps to reproduce

  1. Create a TestPackage directory, cd into it, and run swift package init.
  2. Add the following target in the package manifest:
     .plugin(name: "MyPlugin", capability: .buildTool(), dependencies: [.target(name: "TestPackage")]),
  3. Create a Plugins/MyPlugin/Plugin.swift containing:
    import TestPackage
    import PackagePlugin
    
    @main
    struct Plugin: BuildToolPlugin {
        func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
            []
        }
    }

Swift Package Manager version/commit hash

Swift Package Manager - Swift 5.7.0

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.55.1 Apple Swift version 5.7 (swiftlang-5.7.0.113.202 clang-1400.0.16.2)
Target: arm64-apple-macosx13.0
Darwin Filip-MacBook-Air.local 22.0.0 Darwin Kernel Version 22.0.0: Tue May 24 20:30:32 PDT 2022; root:xnu-8792.0.50.111.3~5/RELEASE_ARM64_T8103 arm64

@tomerd
Copy link
Contributor

tomerd commented Jun 8, 2022

@abertelrud are missing validation here?

@tomerd tomerd added the plugins label Jun 15, 2022
@abertelrud
Copy link
Contributor

Yes, I think so. This isn't currently supported and thus there should be up-front validation. In the long run we should make it work, but that will require some build system changes (we either have to be able to do parts of the build before plugins run, or interleave running plugins are part of the build).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants