Link error at bootstrapping stage 1 on Windows

I wonder if there's something wrong with the output of stage 0 compiler? (symbols already demangled)

swiftCompilerModules-bootstrapping1.lib(Optimizer.o) : error LNK2019:  undefined symbol __imp_$s17ExperimentalRegex013libswiftParseB7LiteralyySPys4Int8VGSg_SpyAFGSgSpys6UInt32VGSgSvSgAJtF (`ExperimentalRegex.libswiftParseRegexLiteral(Swift.UnsafePointer<Swift.Int8>?, Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?, Swift.UnsafeMutablePointer<Swift.UInt32>?, Swift.UnsafeMutableRawPointer?, Swift.UInt32) -> ()`), referenced by $s17ExperimentalRegex013libswiftParseB7LiteralyySPys4Int8VGSg_SpyAFGSgSpys6UInt32VGSgSvSgAJtFTo (`@objc ExperimentalRegex.libswiftParseRegexLiteral(Swift.UnsafePointer<Swift.Int8>?, Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?, Swift.UnsafeMutablePointer<Swift.UInt32>?, Swift.UnsafeMutableRawPointer?, Swift.UInt32) -> ()`)

swiftCompilerModules-bootstrapping1.lib(Optimizer.o) : error LNK2019:  undefined symbol __imp_$s17ExperimentalRegex011libswiftLexB7LiteralySbSpySPys4Int8VGSgGSg_AfHtF (`ExperimentalRegex.libswiftLexRegexLiteral(Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?, Swift.UnsafePointer<Swift.Int8>?, Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?) -> Swift.Bool`), referenced by $s17ExperimentalRegex011libswiftLexB7LiteralySbSpySPys4Int8VGSgGSg_AfHtFTo (`@objc ExperimentalRegex.libswiftLexRegexLiteral(Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?, Swift.UnsafePointer<Swift.Int8>?, Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>?) -> Swift.Bool`)

swiftCompilerModules-bootstrapping1.lib(SIL.o) : error LNK2019:  undefined symbol __imp_$sSp5BasicSo18BridgedSwiftObjectVRszlE5getAsyqd__qd__mRld__ClF (`Swift.UnsafeMutablePointer<A where A == __C.BridgedSwiftObject>.getAs<A where A1: AnyObject>(A1.Type) -> A1` extended in `Basic`), referenced by $sSo18BridgedInstructiona3SILE5getAsyxxmAC0B0CRbzlF (`__C.BridgedInstruction.getAs<A where A: SIL.Instruction>(A.Type) -> A`, extended in `SIL`)

bootstrapping1\bin\swift-frontend.exe : fatal error LNK1120: 3 undefined symbols

CMake config pasted below:

cmake -B S:\b\1 ^
  -C S:\swift\cmake\caches\Windows-x86_64.cmake ^
  -D CMAKE_BUILD_TYPE=Release ^
  -D CMAKE_INSTALL_PREFIX=S:\b\toolchain\usr ^

  -D CMAKE_C_COMPILER=cl.exe ^
  -D CMAKE_C_FLAGS="/GS- /Oy /Gw /Gy /source-charset:utf-8 /execution-charset:utf-8" ^
  -D CMAKE_CXX_COMPILER=cl.exe ^
  -D CMAKE_CXX_FLAGS="/GS- /Oy /Gw /Gy /utf-8" ^
  -D CMAKE_MT=mt ^
  -D CMAKE_EXE_LINKER_FLAGS="/INCREMENTAL:NO" ^
  -D CMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO" ^

  -D LLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc ^

  -D LLVM_EXTERNAL_CMARK_SOURCE_DIR=S:\cmark ^
  -D LLVM_EXTERNAL_SWIFT_SOURCE_DIR=S:\swift ^
  -D SWIFT_PATH_TO_LIBDISPATCH_SOURCE=S:\swift-corelibs-libdispatch ^

  -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES ^
  -D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES ^
  -D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES ^

  -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES ^
  -D EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR=S:\swift-experimental-string-processing ^

  -D BOOTSTRAPPING_MODE=BOOTSTRAPPING ^

  -G Ninja ^
  -S S:\llvm-project\llvm

Note that I manually appended -LIBPATH:S:\b\1\bootstrapping0\lib\swift\windows to the linker flags, or it cannot findswiftCore.lib. Would patch later.

libswift build is not currently working. I've had a couple of attempts to enable it, but there is a bug in the optimizer that causes a failure after you work through the build system issues.

driver: add a link against swiftCore by compnerd · Pull Request #40638 · apple/swift (github.com)
libswift: libswift is built as a static library by compnerd · Pull Request #40639 · apple/swift (github.com)

Should get you to the point where you can investigate the optimizer issue(s).

Note that libswift is not required for the compiler. If you are having any issues with the Swift stdlib, you can always turn off linking the Swift compiler against libswift and the Swift stdlib. That is what I did when building the compiler on an Android tablet with memory tagging enabled, so I could actually natively build and test my changes to get Swift working on such an Android device.

I suggest you build the compiler on Windows with libswift disabled first, then run the compiler validation suite and see if you find any tests that fail because of this optimizer issue that Saleem mentioned. Fix that first, then you can enable libswift: that is what I did on Android with that memory tagging issue.

Without bootstrapping everything works well. This is a part of my try on enabling more components of the toolchain on Windows (the other direction is to fix SwiftPM to enable bootstrapping, DocC, etc.).

Will give a try, but I’m afraid compiler stuffs are beyond my knowledge. I’ve been solving build system problems so far.