# How to detect if project is being built with a nightly toolchain?

**URL:** <https://forums.swift.org/t/how-to-detect-if-project-is-being-built-with-a-nightly-toolchain/77401>\
**Category:** Using Swift\
**Created:** [January 22, 2025, 11:40pm UTC](https://forums.swift.org/t/how-to-detect-if-project-is-being-built-with-a-nightly-toolchain/77401 "2025-01-22T23:40:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [January 22, 2025, 11:40pm UTC](https://forums.swift.org/t/how-to-detect-if-project-is-being-built-with-a-nightly-toolchain/77401/1 "2025-01-22T23:40:48Z")

</div>

the [swift-bson](https://github.com/tayloraswift/swift-bson) library is currently unbuildable on nightly development snapshots due to a [Swift compiler crash](https://github.com/swiftlang/swift/issues/78802).

i want to `#if` out the code that crashes the compiler on nightly snapshots only, so that i can use the library with [Swift WebAssembly](https://forums.swift.org/t/how-far-can-i-get-with-swift-webassembly-in-30-minutes/77305/15).

if i write `#if compiler(>=6.1)` and tag this as a release, this will change the library in source-breaking ways when the actual Swift 6.1 toolchain is released. (the “midnight” update problem.)

how do i write a compiler conditional that only applies to nightly snapshots?

---

<div class="post-metadata">

**Author:** ![Nan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nan/32/18194_2.png) [@Nan](https://forums.swift.org/u/Nan)\
**Post date:** [January 23, 2025, 2:33am UTC](https://forums.swift.org/t/how-to-detect-if-project-is-being-built-with-a-nightly-toolchain/77401/2 "2025-01-23T02:33:31Z")

</div>

Maybe you can use environment variables. The basic idea is to detect the Swift version and set it as a compilation condition.

In Package.swift, set it up like this:

```swift
let settings: [SwiftSetting] = if ProcessInfo.processInfo.environment["SWIFT_IS_DEV"] != nil {
    [.define("SWIFT_IS_DEV")]
} else { [] }

```

Then, pass it to Swift: `env "SWIFT_IS_DEV=1" swift build`.

I don't know how to check the output of `swift --version` with a simple command, but it should be possible to do.
