# Methods for conditionally restricting a package for Apple Silicon?

**URL:** <https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056>\
**Category:** Using Swift\
**Tags:** packagemanager, applesilicon, m1\
**Created:** [February 2, 2022, 7:16pm UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056 "2022-02-02T19:16:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdrelling](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bdrelling/32/2711_2.png) [@bdrelling](https://forums.swift.org/u/bdrelling)\
**Post date:** [February 2, 2022, 7:16pm UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056/1 "2022-02-02T19:16:58Z")

</div>

Simply put, there are SPM libraries that are not yet compatible with Apple Silicon. I'm wondering if there's any method (including workarounds or otherwise) that others have explored for conditionally including a library only if the architecture is `arm64` and so on.

In CocoaPods, I simply grab the architecture directly from the environment and put an `if` check around the pod definition I'm looking to restrict/allow based on architecture.

I'm about to explore something similar in SPM, eg. detecting the architecture and simply stripping the dependency if it's not included, but was curious if there was any cleaner / safer / more preferred method of achieving this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![bdrelling](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bdrelling/32/2711_2.png) [@bdrelling](https://forums.swift.org/u/bdrelling)\
**Post date:** [February 3, 2022, 11:35pm UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056/2 "2022-02-03T23:35:48Z")

</div>

Well, in case anyone stumbles upon this in the future, here's a workaround I came up with. (Edited to use `arch(arm64)` thanks to @Peter-Schorn's answer below.)

The file below is an example `Package.swift`:

```swift
// swift-tools-version:5.5

import PackageDescription

#if arch(arm64)

let architectureSpecificPackageDependencies: [Package.Dependency] = []
let architectureSpecificTargetDependencies: [Target.Dependency] = []

#else

let architectureSpecificPackageDependencies: [Package.Dependency] = [
    // Your Apple Silicon-incompatible Package dependencies.
    // .package(name: "IntelPackage", url: "https://github.com/example/intel-package", .upToNextMajor(from: "1.0.0")),
]

let architectureSpecificTargetDependencies: [Target.Dependency] = [
    // Your Apple Silicon-incompatible Target dependencies.
    // .product(name: "IntelModule", package: "IntelPackage")
]

#endif

let package = Package(
    name: "MainPackage",
    products: [
        .library(name: "MainModule", targets: ["MainModule"]),
    ],
    dependencies: [
        // Your universal Package dependencies.
    ] + architectureSpecificPackageDependencies,
    targets: [
        .target(
            name: "MainModule",
            dependencies: [
                // Your universal Target dependencies.
            ] + architectureSpecificTargetDependencies
        ),
    ]
)

```

---

<div class="post-metadata">

**Author:** ![Peter-Schorn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/peter-schorn/32/11183_2.png) [@Peter-Schorn](https://forums.swift.org/u/Peter-Schorn)\
**Post date:** [February 4, 2022, 1:59am UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056/3 "2022-02-04T01:59:50Z")

</div>

Why not just use the `#if arch(arm64)` compilation condition?

---

<div class="post-metadata">

**Author:** ![bdrelling](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bdrelling/32/2711_2.png) [@bdrelling](https://forums.swift.org/u/bdrelling)\
**Post date:** [February 8, 2022, 1:58am UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056/4 "2022-02-08T01:58:28Z")

</div>

Only because I didn't know about it, this is precisely the kind of thing I was looking for.

Is there a good resource for all of these preprocessor macros?

---

<div class="post-metadata">

**Author:** ![Peter-Schorn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/peter-schorn/32/11183_2.png) [@Peter-Schorn](https://forums.swift.org/u/Peter-Schorn)\
**Post date:** [February 8, 2022, 4:59am UTC](https://forums.swift.org/t/methods-for-conditionally-restricting-a-package-for-apple-silicon/55056/5 "2022-02-08T04:59:08Z")

</div>

See [Statements — The Swift Programming Language (Swift 5.7)](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#ID538)
