# Circular package dependency: it works but is it OK?

**URL:** <https://forums.swift.org/t/circular-package-dependency-it-works-but-is-it-ok/68912>\
**Category:** Using Swift\
**Tags:** packagemanager\
**Created:** [December 10, 2023, 12:36pm UTC](https://forums.swift.org/t/circular-package-dependency-it-works-but-is-it-ok/68912 "2023-12-10T12:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [December 10, 2023, 12:36pm UTC](https://forums.swift.org/t/circular-package-dependency-it-works-but-is-it-ok/68912/1 "2023-12-10T12:36:16Z")

</div>

I have a scenario where there are three modules which have simple dependencies but their packages have circular dependencies (it's caused by one of their test modules. More on this later). The project compiles. I wonder if it's OK to keep using it this way?

More details. The three modules are utils module, custom protocol module, and macros module.

- Utils is the basic module. It doesn't depend on other modules.
- Custom protocol module uses the types defined in utils module, so it depends on utils module.
- Macros module have extension macro which expand extensions for protocols defined in custom protocol module, so it depends on custom protocol module.

The dependency is simple, as illustrated in the diagram.

![screenshot-2023-12-10_20-26-47](https://global.discourse-cdn.com/swift/original/3X/8/a/8af29e3e4c1211b9346fb65a7836656b86c35606.png)

Ideally their package should have the same dependency. However, as I use macro to implement tests for Utils, Utils package depends on macros package. That caused circular dependency among these three packages.

As Xcode compiles my project successfully, I didn't realize there was circular dependency at first. After I found it, I think I can get rid of the circular dependency by split macros package into two packages, but I'm not sure if it's worth the effort since circular dependency works fine in practice. Does anyone know if it's by design or by accident? Thanks.

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [December 10, 2023, 1:01pm UTC](https://forums.swift.org/t/circular-package-dependency-it-works-but-is-it-ok/68912/2 "2023-12-10T13:01:29Z")

</div>

UPDATE: it's weird. I believe my project have had circular package dependency for quite a while and it always worked fine. But shortly after I posted the question, I found one package failed to compile with the following error:

> cyclic dependency declaration found: Utils -\> Macro -\> EntityProtocol -\> Utils

I'm still able to compile the other two packages, although they are in the circular dependency too.

I think I should split macro package. I'll leave the post in case anyone has comments or suggestions.

---

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [December 11, 2023, 2:09am UTC](https://forums.swift.org/t/circular-package-dependency-it-works-but-is-it-ok/68912/3 "2023-12-11T02:09:20Z")

</div>

> [@rayx](#):
>
> I believe my project have had circular package dependency for quite a while and it always worked fine. But shortly after I posted the question, I found one package failed to compile with the following error:

Classic _schrödinbug_

> **schroedinbug** , n.
> 
> [MIT: from the Schroedinger's Cat thought-experiment in quantum physics]
> 
> A design or implementation bug in a program that doesn't manifest until someone reading source or using the program in an unusual way notices that it never should have worked, at which point the program promptly stops working for everybody until fixed. Though (like _bit rot_) this sounds impossible, it happens; some programs have harbored latent schroedinbugs for years.
