# How to import macros using methods other than SwiftPM

**URL:** <https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645>\
**Category:** Macros\
**Tags:** packagemanager\
**Created:** [August 8, 2023, 3:07am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645 "2023-08-08T03:07:24Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![mjamal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mjamal/32/32367_2.png) [@mjamal](https://forums.swift.org/u/mjamal)\
**Post date:** [October 30, 2023, 12:37pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/24 "2023-10-30T12:37:49Z")

</div>

I'm struggling for 2 days to solve a build error in Microsoft Azure's CI using my local machine (MBP M1 Max, Xcode 15) as a run agent for my project that uses [MetaCodable](https://github.com/SwiftyLab/MetaCodable) macro after adding it as a Swift package, it builds locally without problems, but in the CI I got the error: "External macro implementation couldn't be found"  
I've tried the following 4 flags in Other Swift Flags build setting:  
-plugin-path  
-load-plugin-library  
-load-plugin-executable  
-external-plugin-path (mentioned [here](https://developer.apple.com/forums/thread/734504))

with the following value:  
$(BUILT\_PRODUCTS\_DIR)#MetaCodable

as appears in the screenshot:

 ![Screenshot 2023-10-30 at 3.24.57 PM](https://global.discourse-cdn.com/swift/original/3X/0/2/02f67f160df2482165aa812fede920fa716a9f09.png)

but I still couldn't get the project to compile on CI due to this error.  
Any thoughts on this would be highly appreciated.

P.S. the CI builds without problems if the project doesn't contain the macro, and there are no CocoPods at all in the project.

---

<div class="post-metadata">

**Author:** ![ssly](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ssly/32/34148_2.png) [@ssly](https://forums.swift.org/u/ssly)\
**Post date:** [October 30, 2023, 6:35pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/25 "2023-10-30T18:35:03Z")

</div>

`-load-plugin-executable` should be worked @mjamal  
you can refer to the example above

---

<div class="post-metadata">

**Author:** ![mjamal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mjamal/32/32367_2.png) [@mjamal](https://forums.swift.org/u/mjamal)\
**Post date:** [October 31, 2023, 7:53am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/26 "2023-10-31T07:53:51Z")

</div>

as I mentioned above, I tried `-load-plugin-executable` with the value of:  
`$(BUILT_PRODUCTS_DIR)#MetaCodable`

but the Microsoft Azure's CI log shows the following error and warning:

`error: external macro implementation type 'CodableMacroPlugin.CodedAt' could not be found for macro 'CodedAt'`

`"output": "<unknown>:0: warning: compiler plugin not loaded: '/Users/my_user_name/Library/Developer/Xcode/DerivedData/MyProject/Build/Products/Release/CodableMacroPlugin; failed to initialize /Users/my_user_name/vsts-agent-osx-x64-2.183.1/_work/9/MyProject/Data/Models/SomeModel.swift`

---

<div class="post-metadata">

**Author:** ![Snow](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@Snow](https://forums.swift.org/u/Snow)\
**Post date:** [November 2, 2023, 7:01am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/28 "2023-11-02T07:01:35Z")

</div>

Have you solved this problem? I have the same problem:  
":0: warning: compiler plugin not loaded:

---

<div class="post-metadata">

**Author:** ![mjamal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mjamal/32/32367_2.png) [@mjamal](https://forums.swift.org/u/mjamal)\
**Post date:** [November 2, 2023, 7:19am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/29 "2023-11-02T07:19:04Z")

</div>

I couldn't solve it until now .. I posted SO question [here](https://stackoverflow.com/questions/77386744/swift-macros-external-macro-implementation-type-could-not-be-found/77397312#77397312) to grab some attention.

---

<div class="post-metadata">

**Author:** ![Snow](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@Snow](https://forums.swift.org/u/Snow)\
**Post date:** [November 11, 2023, 6:03am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/30 "2023-11-11T06:03:24Z")

</div>

It may be a sandbox execution problem, You can check the CI log to see if there are "sandbox-exec: sandbox\_apply: Operation not permitted"

---

<div class="post-metadata">

**Author:** ![ssly](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ssly/32/34148_2.png) [@ssly](https://forums.swift.org/u/ssly)\
**Post date:** [November 22, 2023, 10:00am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/32 "2023-11-22T10:00:32Z")

</div>

Perhaps you can confirm if the architecture of the binary file meets the requirements

---

<div class="post-metadata">

**Author:** ![mjamal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mjamal/32/32367_2.png) [@mjamal](https://forums.swift.org/u/mjamal)\
**Post date:** [November 24, 2023, 1:10pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/33 "2023-11-24T13:10:23Z")

</div>

It turned out to be an XCode 15 problem with CI providers (Microsoft Azure and Fastlane) and it's not related to Swift Macros, a Microsoft engineer pointed that out in [this thread](https://developercommunity.visualstudio.com/t/Azure-Pipeline-fails-on-Apples-XCode-15/10507774#T-ND10513411) that I recently opened on their developer community, he also pointed me to a [hot discussion](https://developer.apple.com/forums/thread/737923?login=true&page=3&r_s_legacy=true#771938022) on Apple Developers Forums to keep track of the updates regarding this issue.

---

<div class="post-metadata">

**Author:** ![soumyamahunt](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/soumyamahunt/32/23427_2.png) [@soumyamahunt](https://forums.swift.org/u/soumyamahunt)\
**Post date:** [January 29, 2024, 4:51pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/36 "2024-01-29T16:51:11Z")

</div>

Hi, I have written a step-by-step guide on how you can [distribute macro libraries with CocoaPods](https://soumyamahunt.medium.com/support-swift-macros-with-cocoapods-3911f9317042), hope it helps you achieving your goal.

---

<div class="post-metadata">

**Author:** ![flockoffiles](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/flockoffiles/32/18709_2.png) [@flockoffiles](https://forums.swift.org/u/flockoffiles)\
**Post date:** [June 27, 2024, 8:54am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/37 "2024-06-27T08:54:51Z")

</div>

Please note that if you are using xcframeworks (e.g. link with SwiftSyntax that was built as an xcframework), you also need to specify the option "-disable-sandbox"

---

<div class="post-metadata">

**Author:** ![devturhan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devturhan/32/36994_2.png) [@devturhan](https://forums.swift.org/u/devturhan)\
**Post date:** [August 23, 2024, 10:26am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/38 "2024-08-23T10:26:47Z")

</div>

`-load-plugin-executable` solution was working as expected on Xcode 15 but is not on Xcode 16 - beta 5, does anyone use it on Xcode 16 ?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Soto](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ignacio_soto/32/396_2.png) [@Ignacio\_Soto](https://forums.swift.org/u/Ignacio_Soto)\
**Post date:** [October 3, 2024, 6:59pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/39 "2024-10-03T18:59:09Z")

</div>

I'm unable to get this working on Xcode 16 either.

For context, this is needed because `xcodebuild -exportLocalizations` does not automatically load macros so builds would fail on Xcode 15 without it.

This was working on Xcode 15:

```swift
OTHER_SWIFT_FLAGS="-Xfrontend -load-plugin-executable -Xfrontend .../SourcePackages/checkouts/swift-case-paths/.build/debug/CasePathsMacros#CasePathsMacros -Xfrontend -load-plugin-executable -Xfrontend .../SourcePackages/checkouts/swift-macros/.build/debug/Macros#Macros" xcodebuild -exportLocalizations -exportLanguage en -project X.xcodeproj -localizationPath . -scheme X -sdk macosx ONLY_ACTIVE_ARCH=NO ARCHS="arm64

```

On Xcode 16 it fails to build:

```swift
error: external macro implementation type 'CasePathsMacros.CasePathableMacro' could not be found for macro 'CasePathable()'; No such file or directory

```

---

<div class="post-metadata">

**Author:** ![Ignacio\_Soto](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ignacio_soto/32/396_2.png) [@Ignacio\_Soto](https://forums.swift.org/u/Ignacio_Soto)\
**Post date:** [October 3, 2024, 8:02pm UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/40 "2024-10-03T20:02:34Z")

</div>

Figured out the difference required:

**Xcode 15:**

```swift
-load-plugin-executable <path>#<modulename>

```

**Xcode 16:**

```swift
-load-plugin-executable <path>-tool#<modulename>

```

---

<div class="post-metadata">

**Author:** ![vatsal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vatsal/32/12722_2.png) [@vatsal](https://forums.swift.org/u/vatsal)\
**Post date:** [October 7, 2024, 11:05am UTC](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/41 "2024-10-07T11:05:30Z")

</div>

> [@Ignacio\_Soto](#):
>
> ```swift
> -load-plugin-executable <path>-tool#<modulename>
> 
> ```

@Ignacio_Soto thank you for documenting this, saved us a ton of time!

[Previous page](https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645.md?page=1)
