How to generate an Xcode project to build the compiler?

How can I open the Swift open source repo in Xcode and use Xcode to build it?

Checkout the getting started docs which cover this use case swift/GettingStarted.md at main · apple/swift · GitHub

I did read this, however you cannot open swift in Xcode and use Xcode to build it, because the Xcode project they refer to only exists after you do a build not using Xcode—which fails with:

The following tests FAILED:
	  3 - spectest_library (Failed)
	  4 - pathological_tests_library (Failed)
	  5 - roundtriptest_library (Failed)
	  6 - entity_library (Failed)
	  7 - spectest_executable (Failed)
	  8 - smartpuncttest_executable (Failed)
	  9 - regressiontest_executable (Failed)
Errors while running CTest
Output from these tests are in: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
Command PhaseScriptExecution failed with a nonzero exit code

PhaseScriptExecution CMake\ PostBuild\ Rules /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/src/cmark.build/RelWithDebInfo/libcmark.build/Script-C4BD2AB16D2C468B040AB499.sh (in target 'libcmark' from project 'cmark')
    cd /Users/REDACTED/dev/3rdParty/swift_source/cmark
    /bin/sh -c /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/src/cmark.build/RelWithDebInfo/libcmark.build/Script-C4BD2AB16D2C468B040AB499.sh

PhaseScriptExecution Generate\ CMakeFiles/ALL_BUILD /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/cmark.build/RelWithDebInfo/ALL_BUILD.build/Script-0A7591440DD1D9CD0E17D7E7.sh (in target 'ALL_BUILD' from project 'cmark')
    cd /Users/REDACTED/dev/3rdParty/swift_source/cmark
    /bin/sh -c /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/cmark.build/RelWithDebInfo/ALL_BUILD.build/Script-0A7591440DD1D9CD0E17D7E7.sh
Build all projects

** BUILD FAILED **

The LastTest.log has:

Start testing: Nov 09 21:40 PST
----------------------------------------------------------
1/9 Testing: api_test
1/9 Test: api_test
Command: "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/api_test/RelWithDebInfo/api_test"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"api_test" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
539 tests passed, 0 failed, 0 skipped
PASS
<end of output>
Test time =   0.25 sec
----------------------------------------------------------
Test Passed.
"api_test" end time: Nov 09 21:40 PST
"api_test" time elapsed: 00:00:00
----------------------------------------------------------

2/9 Testing: html_normalization
2/9 Test: html_normalization
Command: "/usr/bin/python3" "-m" "doctest" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/normalize.py"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"html_normalization" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
<end of output>
Test time =   0.11 sec
----------------------------------------------------------
Test Passed.
"html_normalization" end time: Nov 09 21:40 PST
"html_normalization" time elapsed: 00:00:00
----------------------------------------------------------

3/9 Testing: spectest_library
3/9 Test: spectest_library
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py" "--no-normalize" "--spec" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec.txt" "--library-dir" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"spectest_library" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 137, in <module>
    converter = CMark(prog=args.program, library_dir=args.library_dir).to_html
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 59, in __init__
    cmark = CDLL(libpath)
UnboundLocalError: local variable 'libpath' referenced before assignment
<end of output>
Test time =   0.04 sec
----------------------------------------------------------
Test Failed.
"spectest_library" end time: Nov 09 21:40 PST
"spectest_library" time elapsed: 00:00:00
----------------------------------------------------------

4/9 Testing: pathological_tests_library
4/9 Test: pathological_tests_library
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/pathological_tests.py" "--library-dir" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"pathological_tests_library" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/pathological_tests.py", line 21, in <module>
    cmark = CMark(prog=args.program, library_dir=args.library_dir)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 59, in __init__
    cmark = CDLL(libpath)
UnboundLocalError: local variable 'libpath' referenced before assignment
<end of output>
Test time =   0.04 sec
----------------------------------------------------------
Test Failed.
"pathological_tests_library" end time: Nov 09 21:40 PST
"pathological_tests_library" time elapsed: 00:00:00
----------------------------------------------------------

5/9 Testing: roundtriptest_library
5/9 Test: roundtriptest_library
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/roundtrip_tests.py" "--spec" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec.txt" "--library-dir" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"roundtriptest_library" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/roundtrip_tests.py", line 44, in <module>
    do_test(converter, test, args.normalize, result_counts)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 41, in do_test
    [retcode, actual_html, err] = converter(test['markdown'])
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/roundtrip_tests.py", line 26, in converter
    cmark = CMark(prog=args.program, library_dir=args.library_dir)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 59, in __init__
    cmark = CDLL(libpath)
UnboundLocalError: local variable 'libpath' referenced before assignment
<end of output>
Test time =   0.04 sec
----------------------------------------------------------
Test Failed.
"roundtriptest_library" end time: Nov 09 21:40 PST
"roundtriptest_library" time elapsed: 00:00:00
----------------------------------------------------------

6/9 Testing: entity_library
6/9 Test: entity_library
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/entity_tests.py" "--library-dir" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"entity_library" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/entity_tests.py", line 29, in <module>
    cmark = CMark(prog=args.program, library_dir=args.library_dir)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 59, in __init__
    cmark = CDLL(libpath)
UnboundLocalError: local variable 'libpath' referenced before assignment
<end of output>
Test time =   0.03 sec
----------------------------------------------------------
Test Failed.
"entity_library" end time: Nov 09 21:40 PST
"entity_library" time elapsed: 00:00:00
----------------------------------------------------------

7/9 Testing: spectest_executable
7/9 Test: spectest_executable
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py" "--no-normalize" "--spec" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec.txt" "--program" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"spectest_executable" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 140, in <module>
    do_test(converter, test, args.normalize, result_counts)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 41, in do_test
    [retcode, actual_html, err] = converter(test['markdown'])
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 42, in <lambda>
    self.to_html = lambda x: pipe_through_prog(prog, x)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 10, in pipe_through_prog
    p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark'
<end of output>
Test time =   0.04 sec
----------------------------------------------------------
Test Failed.
"spectest_executable" end time: Nov 09 21:40 PST
"spectest_executable" time elapsed: 00:00:00
----------------------------------------------------------

8/9 Testing: smartpuncttest_executable
8/9 Test: smartpuncttest_executable
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py" "--no-normalize" "--spec" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/smart_punct.txt" "--program" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark --smart"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"smartpuncttest_executable" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 140, in <module>
    do_test(converter, test, args.normalize, result_counts)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 41, in do_test
    [retcode, actual_html, err] = converter(test['markdown'])
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 42, in <lambda>
    self.to_html = lambda x: pipe_through_prog(prog, x)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 10, in pipe_through_prog
    p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark'
<end of output>
Test time =   0.03 sec
----------------------------------------------------------
Test Failed.
"smartpuncttest_executable" end time: Nov 09 21:40 PST
"smartpuncttest_executable" time elapsed: 00:00:00
----------------------------------------------------------

9/9 Testing: regressiontest_executable
9/9 Test: regressiontest_executable
Command: "/usr/bin/python3" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py" "--no-normalize" "--spec" "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/regression.txt" "--program" "/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark"
Directory: /Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir
"regressiontest_executable" start time: Nov 09 21:40 PST
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 140, in <module>
    do_test(converter, test, args.normalize, result_counts)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/spec_tests.py", line 41, in do_test
    [retcode, actual_html, err] = converter(test['markdown'])
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 42, in <lambda>
    self.to_html = lambda x: pipe_through_prog(prog, x)
  File "/Users/REDACTED/dev/3rdParty/swift_source/cmark/test/cmark.py", line 10, in pipe_through_prog
    p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/REDACTED/dev/3rdParty/swift_source/build/Xcode-RelWithDebInfoAssert/cmark-macosx-arm64/testdir/../src/cmark'
<end of output>
Test time =   0.03 sec
----------------------------------------------------------
Test Failed.
"regressiontest_executable" end time: Nov 09 21:40 PST
"regressiontest_executable" time elapsed: 00:00:00
----------------------------------------------------------

End testing: Nov 09 21:40 PST

You can use the --skip-build flag, if you want to open it in Xcode first before building it.

-S, --skip-build generate build directory only without building

OK, will try that.

Any idea which Xcode target to build in order to build the whole toolchain? Thanks