Skip to content

[SR-1393] [SwiftPM] Enforce Swift module import dependencies #5297

@ddunbar

Description

@ddunbar
Previous ID SR-1393
Radar rdar://problem/23237241
Original Reporter @ddunbar
Type Bug
Status In Progress
Resolution
Additional Detail from JIRA
Votes 9
Component/s Package Manager
Labels Bug
Assignee owenvoorhees (JIRA)
Priority Medium

md5: b673faead2f75706db0bdac53b7b8ef3

is duplicated by:

  • SR-4539 Build executable with modules, without specified dependencies
  • SR-8344 SPM include path is too permissive, leads to link errors that should have been compile errors
  • SR-9359 SwiftPM should have better diagnostics if tests depend on executable target
  • SR-11758 Undefined symbol: static allcases.MyEnum.allCases.getter : [allcases.MyEnum]

relates to:

  • SR-3033 Poor diagnostic when importing executable target module in a test
  • SR-13651 Linker error while linking unit test cases
  • SR-3205 Ability to restrict the import of implicit module dependencies
  • SR-14212 Removing package from Package.swift doesn't result in import error
  • SR-7483 Deserialization Failure

Issue Description:

Currently, SwiftPM passes a -I to the directory containing all built modules, which allows any Swift code to import any module which has been built.

This is unfortunate, as it means code can easily import modules which haven't been explicitly declared as a dependency. That might frequently work but it can be the source of transient build failures or "works for me" type problems.

Instead, we should enforce that Swift code is only allowed to import modules which have been explicitly declared as dependencies. We could also let this include transitive dependencies, but I would actually prefer we require any module explicitly declare all other modules it is allowed to import.

swiftc doesn't expose a mechanism currently we can use to implement this directly. We could:

  • Extend swiftc to explicitly support this.

  • Build symlink trees for each target we want to build, and point the -I at that instead, to enforce what is allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions