@@ -451,12 +451,21 @@ function(_compile_swift_files
451451
452452 # Then we can compile both the object files and the swiftmodule files
453453 # in parallel in this target for the object file, and ...
454+
455+ # Windows doesn't support long command line paths, of 8191 chars or over.
456+ # We need to work around this by avoiding long command line arguments. This can be
457+ # achieved by writing the list of file paths to a file, then reading that list
458+ # in the Python script.
459+ string (RANDOM file_name)
460+ set (file_path "${CMAKE_CURRENT_BINARY_DIR} /${file_name} .txt" )
461+ file (WRITE "${file_path} " "${source_files} " )
462+
454463 add_custom_command_target(
455464 dependency_target
456465 COMMAND
457- "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "${source_files } " --
466+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@ ${file_path } " --
458467 "${swift_compiler_tool} " "${main_command} " ${swift_flags}
459- ${output_option} ${embed_bitcode_option} "${source_files } "
468+ ${output_option} ${embed_bitcode_option} "@ ${file_path } "
460469 ${command_touch_standard_outputs}
461470 OUTPUT ${standard_outputs}
462471 DEPENDS
@@ -485,9 +494,9 @@ function(_compile_swift_files
485494 add_custom_command_target(
486495 module_dependency_target
487496 COMMAND
488- "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "${source_files } " --
497+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@ ${file_path } " --
489498 "${swift_compiler_tool} " "-emit-module" "-o" "${module_file} " ${swift_flags}
490- "${source_files } "
499+ "@ ${file_path } "
491500 ${command_touch_module_outputs}
492501 OUTPUT ${module_outputs}
493502 DEPENDS
@@ -502,9 +511,9 @@ function(_compile_swift_files
502511 add_custom_command_target(
503512 sib_dependency_target
504513 COMMAND
505- "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "${source_files } " --
514+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@ ${file_path } " --
506515 "${swift_compiler_tool} " "-emit-sib" "-o" "${sib_file} " ${swift_flags} -Onone
507- "${source_files } "
516+ "@ ${file_path } "
508517 ${command_touch_sib_outputs}
509518 OUTPUT ${sib_outputs}
510519 DEPENDS
@@ -518,9 +527,9 @@ function(_compile_swift_files
518527 add_custom_command_target(
519528 sibopt_dependency_target
520529 COMMAND
521- "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "${source_files } " --
530+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@ ${file_path } " --
522531 "${swift_compiler_tool} " "-emit-sib" "-o" "${sibopt_file} " ${swift_flags} -O
523- "${source_files } "
532+ "@ ${file_path } "
524533 ${command_touch_sibopt_outputs}
525534 OUTPUT ${sibopt_outputs}
526535 DEPENDS
@@ -535,9 +544,9 @@ function(_compile_swift_files
535544 add_custom_command_target(
536545 sibgen_dependency_target
537546 COMMAND
538- "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "${source_files } " --
547+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@ ${file_path } " --
539548 "${swift_compiler_tool} " "-emit-sibgen" "-o" "${sibgen_file} " ${swift_flags}
540- "${source_files } "
549+ "@ ${file_path } "
541550 ${command_touch_sibgen_outputs}
542551 OUTPUT ${sibgen_outputs}
543552 DEPENDS
0 commit comments