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

the swift-bson library is currently unbuildable on nightly development snapshots due to a Swift compiler crash.

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.

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?

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:

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.