<commit_before>include(ExternalProject)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
  if(CMAKE_C_COMPILER_ID STREQUAL Clang AND
    CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.8
    OR LLVM_USE_SANITIZER)
    set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
    set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
  elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
    if(CMAKE_SYSTEM_NAME STREQUAL Windows)
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR AND
        TARGET clang)
        set(SWIFT_LIBDISPATCH_C_COMPILER
          $<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
        set(SWIFT_LIBDISPATCH_CXX_COMPILER
          $<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
      else()
        set(SWIFT_LIBDISPATCH_C_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
        set(SWIFT_LIBDISPATCH_CXX_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
      endif()
    else()
      set(SWIFT_LIBDISPATCH_C_COMPILER $<TARGET_FILE_DIR:clang>/clang)
      set(SWIFT_LIBDISPATCH_CXX_COMPILER $<TARGET_FILE_DIR:clang>/clang++)
    endif()
  else()
    message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")
  endif()

  if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
    set(LIBDISPATCH_RUNTIME_DIR bin)
  else()
    set(LIBDISPATCH_RUNTIME_DIR lib)
  endif()
endif()

set(DISPATCH_SDKS)

# Build the host libdispatch if needed.
if(SWIFT_BUILD_HOST_DISPATCH)
  if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
    if(NOT "${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_SDKS)
      list(APPEND DISPATCH_SDKS "${SWIFT_HOST_VARIANT_SDK}")
    endif()
  endif()
endif()

# Build any target libdispatch if needed.
foreach(sdk ${SWIFT_SDKS})
  # Apple targets have libdispatch available, do not build it.
  if(NOT "${sdk}" IN_LIST SWIFT_APPLE_PLATFORMS)
    list(APPEND DISPATCH_SDKS "${sdk}")
  endif()
endforeach()

foreach(sdk ${DISPATCH_SDKS})
  set(ARCHS ${SWIFT_SDK_${sdk}_ARCHITECTURES})
  if(${sdk} STREQUAL "${SWIFT_HOST_VARIANT_SDK}")
    if(NOT "${SWIFT_HOST_VARIANT_ARCH}" IN_LIST ARCHS)
      list(APPEND ARCHS "${SWIFT_HOST_VARIANT_ARCH}")
    endif()
  endif()
  
  if(sdk STREQUAL ANDROID)
    set(SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS)
  else()
    set(SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS -DCMAKE_C_COMPILER=${SWIFT_LIBDISPATCH_C_COMPILER};-DCMAKE_CXX_COMPILER=${SWIFT_LIBDISPATCH_CXX_COMPILER})
  endif()

  foreach(arch ${ARCHS})
    set(LIBDISPATCH_VARIANT_NAME "libdispatch-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")

    if(NOT sdk STREQUAL ANDROID)
      set(SWIFT_LIBDISPATCH_SYSTEM_PROCESSOR  -DCMAKE_SYSTEM_PROCESSOR=${arch})
    endif()

    ExternalProject_Add("${LIBDISPATCH_VARIANT_NAME}"
                        SOURCE_DIR
                          "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}"
                        CMAKE_ARGS
                          -DCMAKE_AR=${CMAKE_AR}
                          -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
                          ${SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS}
                          -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
                          -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
                          -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
                          -DCMAKE_INSTALL_LIBDIR=lib
                          -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
                          -DCMAKE_LINKER=${CMAKE_LINKER}
                          -DCMAKE_RANLIB=${CMAKE_RANLIB}
                          -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                          -DCMAKE_SYSTEM_NAME=${SWIFT_SDK_${sdk}_NAME}
                          ${SWIFT_LIBDISPATCH_SYSTEM_PROCESSOR}
                          "-DCMAKE_ANDROID_NDK=${SWIFT_ANDROID_NDK_PATH}"
                          -DCMAKE_ANDROID_ARCH_ABI=${SWIFT_SDK_ANDROID_ARCH_${arch}_ABI}
                          -DCMAKE_ANDROID_API=${SWIFT_ANDROID_API_LEVEL}
                          -DBUILD_SHARED_LIBS=YES
                          -DENABLE_SWIFT=NO
                          -DENABLE_TESTING=NO
                        INSTALL_COMMAND
                          # NOTE(compnerd) provide a custom install command to
                          # ensure that we strip out the DESTDIR environment
                          # from the sub-build
                          ${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install
                        COMMAND<commit_msg>build: repair the build with VS2019 16.10.0<commit_after>include(ExternalProject)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
  if(CMAKE_C_COMPILER_ID STREQUAL Clang AND
    CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.8
    OR LLVM_USE_SANITIZER)
    set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
    set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
  elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
    if(CMAKE_SYSTEM_NAME STREQUAL Windows)
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR AND
        TARGET clang)
        set(SWIFT_LIBDISPATCH_C_COMPILER
          $<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
        set(SWIFT_LIBDISPATCH_CXX_COMPILER
          $<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
      else()
        set(SWIFT_LIBDISPATCH_C_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
        set(SWIFT_LIBDISPATCH_CXX_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
      endif()
    else()
      set(SWIFT_LIBDISPATCH_C_COMPILER $<TARGET_FILE_DIR:clang>/clang)
      set(SWIFT_LIBDISPATCH_CXX_COMPILER $<TARGET_FILE_DIR:clang>/clang++)
    endif()
  else()
    message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")
  endif()

  if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
    set(LIBDISPATCH_RUNTIME_DIR bin)
  else()
    set(LIBDISPATCH_RUNTIME_DIR lib)
  endif()
endif()

set(DISPATCH_SDKS)

# Build the host libdispatch if needed.
if(SWIFT_BUILD_HOST_DISPATCH)
  if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
    if(NOT "${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_SDKS)
      list(APPEND DISPATCH_SDKS "${SWIFT_HOST_VARIANT_SDK}")
    endif()
  endif()
endif()

# Build any target libdispatch if needed.
foreach(sdk ${SWIFT_SDKS})
  # Apple targets have libdispatch available, do not build it.
  if(NOT "${sdk}" IN_LIST SWIFT_APPLE_PLATFORMS)
    list(APPEND DISPATCH_SDKS "${sdk}")
  endif()
endforeach()

foreach(sdk ${DISPATCH_SDKS})
  set(ARCHS ${SWIFT_SDK_${sdk}_ARCHITECTURES})
  if(${sdk} STREQUAL "${SWIFT_HOST_VARIANT_SDK}")
    if(NOT "${SWIFT_HOST_VARIANT_ARCH}" IN_LIST ARCHS)
      list(APPEND ARCHS "${SWIFT_HOST_VARIANT_ARCH}")
    endif()
  endif()
  
  if(sdk STREQUAL ANDROID)
    set(SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS)
  else()
    set(SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS -DCMAKE_C_COMPILER=${SWIFT_LIBDISPATCH_C_COMPILER};-DCMAKE_CXX_COMPILER=${SWIFT_LIBDISPATCH_CXX_COMPILER})
  endif()

  foreach(arch ${ARCHS})
    set(LIBDISPATCH_VARIANT_NAME "libdispatch-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")

    if(NOT sdk STREQUAL ANDROID)
      set(SWIFT_LIBDISPATCH_SYSTEM_PROCESSOR  -DCMAKE_SYSTEM_PROCESSOR=${arch})
    endif()

    ExternalProject_Add("${LIBDISPATCH_VARIANT_NAME}"
                        SOURCE_DIR
                          "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}"
                        CMAKE_ARGS
                          -DCMAKE_AR=${CMAKE_AR}
                          -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
                          ${SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS}
                          -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
                          -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
                          -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
                          -DCMAKE_INSTALL_LIBDIR=lib
                          -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
                          -DCMAKE_LINKER=${CMAKE_LINKER}
                          -DCMAKE_MT=${CMAKE_MT}
                          -DCMAKE_RANLIB=${CMAKE_RANLIB}
                          -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                          -DCMAKE_SYSTEM_NAME=${SWIFT_SDK_${sdk}_NAME}
                          ${SWIFT_LIBDISPATCH_SYSTEM_PROCESSOR}
                          "-DCMAKE_ANDROID_NDK=${SWIFT_ANDROID_NDK_PATH}"
                          -DCMAKE_ANDROID_ARCH_ABI=${SWIFT_SDK_ANDROID_ARCH_${arch}_ABI}
                          -DCMAKE_ANDROID_API=${SWIFT_ANDROID_API_LEVEL}
                          -DBUILD_SHARED_LIBS=YES
                          -DENABLE_SWIFT=NO
                          -DENABLE_TESTING=NO
                        INSTALL_COMMAND
                          # NOTE(compnerd) provide a custom install command to
                          # ensure that we strip out the DESTDIR environment
                          # from the sub-build
                          ${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install
                        COMMAND
{'fraction_non_alphanumeric': 0.08688836636434889, 'fraction_numerical': 0.001903482252827231, 'mean_word_length': 2.6205918119173086, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3373778', 'n_tokens_mistral': 3334, 'n_tokens_neox': 3124, 'n_words': 408}