swift-corelibs-xctest's build_script.py is able to build the project in either --debug or --release mode: https://github.com/apple/swift-corelibs-xctest/blob/360a13aa99cd15766cda839b28eeeb3034e63715/build_script.py#L236-L249
The Swift build script, utils/build-script, also takes parameters to determine the build mode:
Swift has many build modes: Debug, Release, Release+Assert, etc. This build mode is never reflected in the XCTest build mode, however: https://github.com/apple/swift/blob/e8eba770d58ce512046951b0647941194987525e/utils/build-script-impl#L1937-L1942
It should be! XCTest should be built in release mode (passed the --release flag) when Swift is being built in release mode. It should be built in debug mode when Swift is built in debug mode.
(It might also be worth looking into the other Swift build modes, such as when assertions are turned on, and determine whether we should reflect that in how XCTest is built. But that's outside the scope of this task.)