Skip to content

[Traits] Used package dependency omitted when traits guard some target dependencies #8398

Open
@bripeticca

Description

@bripeticca

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

The computation for trait-guarded dependencies did not consider differentiating between product target dependencies coming from the same package wherein one could be trait-guarded and the other could be enabled, causing it to preemptively omit the package dependency entirely if it encounters a trait guard.

Expected behavior

SwiftPM should ensure that it computes the target dependencies that are being trait-guarded, and assure that a dependency is only guarded if every instance of it appears to be trait-guarded. Otherwise, it should include this dependency if it's being used.

Actual behavior

SwiftPM preemptively omits a package dependency it believes to be trait-guarded when there are existing target dependencies that aren't guarded.

Steps to reproduce

Download the attached example project and run a swift build in the root directory; note that it errors out with:

[0/1] Planning build
Building for debugging...
[0/4] Write swift-version--58304C5D6DBC2206.txt
error: emit-module command failed with exit code 1 (use -v to see invocation)
[2/6] Emitting module root
<unknown>:0: error: missing required module 'bestlowest'
[3/6] Compiling root main.swift
<unknown>:0: error: missing required module 'bestlowest'

packtest.zip

Swift Package Manager version/commit hash

No response

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

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions