Unable to pass arguments to swift package manager

I’ve started experimenting with some conditional compilation. I have this working fine from xcode, but I’d like to get it working from the command line using the swift package manager.

I’m able to run swift build or swift test from the command line without issue. However, if I try:

swift -D DEBUG build

or even

swift -Onone build

I receive: :0: error: no such file or directory: 'build’

I only have the one version of swift installed. xcrun shows it pointing to the following toolchain:


Ideas on what I may be doing wrong here?

Your options are in the wrong position, and each compiler or linker flag must use one of the -X options. See swift build --help for details.

swift build -Xswiftc -D -Xswiftc DEBUG

For conditional compilation flags, the space appears to be optional.

swift build -Xswiftc -DDEBUG