diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 6ed769d48..5afe0d3d3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,7 +28,7 @@ jobs: key: libs-windows-latest-${{ hashFiles('make.ps1', 'CMakeLists.txt', 'lib/CMakeLists.txt', 'lib/llvm/patches/*') }} - name: Build Libs if: steps.restore-libs.outputs.cache-hit != 'true' - run: .\make.ps1 -Command libs + run: .\make.ps1 -Command libs -LibsExtraCmakeDefines "-DPONYC_DOWNLOAD_PREBUILT_LLVM=On" - name: Save Libs Cache if: steps.restore-libs.outputs.cache-hit != 'true' uses: actions/cache/save@v4 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5dccd87db..129e14cc5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -52,96 +52,110 @@ install(TARGETS blake2 COMPONENT library ) -find_package(Git) - -set(LLVM_DESIRED_HASH "4434dabb69916856b824f68a64b029c67175e532") -set(PATCHES_DESIRED_HASH "3e16c097794cb669a8f6a0bd7600b440205ac5c29a6135750c2e83263eb16a95") - -if(GIT_FOUND) - if(EXISTS "${PROJECT_SOURCE_DIR}/../.git") - # Update submodules as needed - option(GIT_SUBMODULE "Check submodules during build" ON) - if(GIT_SUBMODULE) - message(STATUS "Updating submodules...") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE git_submod_result) - #message("git_submod_result ${git_submod_result}") - if(NOT git_submod_result EQUAL "0") - message(FATAL_ERROR "git submodule update --init --recursive --depth 1 failed with ${git_submod_result}, please checkout submodules") - endif() - - # we check to make sure the submodule hash matches - # the reason the submodule hash is in this file is to be able to use this file as a key for caching the libs in CI - execute_process(COMMAND ${GIT_EXECUTABLE} submodule status - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE git_submod_output) - #message("git_submod_output ${git_submod_output}") - string(FIND "${git_submod_output}" "${LLVM_DESIRED_HASH}" LLVM_SUBMOD_POS) - if(LLVM_SUBMOD_POS EQUAL "-1") - message(FATAL_ERROR "Expecting the lib/llvm/src submodule to be at hash '${LLVM_DESIRED_HASH}'; found '${git_submod_output}'; update the LLVM_DESIRED_HASH variable in lib/CMakeLists.txt if you've updated the submodule.") - endif() - endif() - endif() - - # Apply patches - message("Applying patches...") - file(GLOB PONY_LLVM_PATCHES "${PROJECT_SOURCE_DIR}/llvm/patches/*.diff") - - # check to see if the patch hashes match - message("Checking patches ${PONY_LLVM_PATCHES}") - set(PATCHES_ACTUAL_HASH "needed_if_no_patches") - foreach (PATCH ${PONY_LLVM_PATCHES}) - file(STRINGS ${PATCH} patch_file NEWLINE_CONSUME) - string(REPLACE "\n" " " patch_file "${patch_file}") - string(SHA256 patch_file_hash "${patch_file}") - string(CONCAT PATCHES_ACTUAL_HASH ${PATCHES_ACTUAL_HASH} ${patch_file_hash}) - endforeach() - string(SHA256 PATCHES_ACTUAL_HASH ${PATCHES_ACTUAL_HASH}) - if(NOT PATCHES_ACTUAL_HASH MATCHES "${PATCHES_DESIRED_HASH}") - message(FATAL_ERROR "Patch hash actual '${PATCHES_ACTUAL_HASH}' does not match desired '${PATCHES_DESIRED_HASH}'") - endif() - - foreach (PATCH ${PONY_LLVM_PATCHES}) - message(" Checking ${PATCH}") - execute_process(COMMAND ${GIT_EXECUTABLE} apply --check -p 1 --ignore-whitespace --whitespace=nowarn ${PATCH} - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/llvm/src" - ERROR_VARIABLE _err_out - RESULT_VARIABLE git_apply_check_result) - if(git_apply_check_result EQUAL "0") - message(" Applying ${PATCH}") - execute_process(COMMAND ${GIT_EXECUTABLE} apply -p 1 --ignore-whitespace --whitespace=nowarn ${PATCH} - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/llvm/src" - RESULT_VARIABLE git_apply_result) - if(NOT git_apply_result EQUAL "0") - message(FATAL_ERROR "Unable to apply ${PATCH}") - endif() - else() - message(" Already applied ${PATCH}") - endif() - endforeach() +if(PONYC_DOWNLOAD_PREBUILT_LLVM) + set(PONYC_LLVM_DOWNLOAD_URL https://github.com/llvm/llvm-project/releases/download/llvmorg-22.1.0/clang+llvm-22.1.0-x86_64-pc-windows-msvc.tar.xz) + + ExternalProject_Add( + LLVM_Downloaded + URL ${PONYC_LLVM_DOWNLOAD_URL} + SOURCE_DIR ${CMAKE_INSTALL_PREFIX} + BUILD_COMMAND "" + INSTALL_COMMAND "" + CONFIGURE_COMMAND "" + UPDATE_COMMAND "" + ) else() - message(FATAL_ERROR "Git not found!") -endif() - -message("Building targets: ${LLVM_TARGETS_TO_BUILD}") - -set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_OCAMLDOC OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_PIC OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_TOOL_REMARKS_SHLIB_BUILD OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "ponyc specific override of LLVM cache entry") -set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "ponyc specific override of LLVM cache entry") - -if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.14 -DUSE_SCHEDULER_SCALING_PTHREADS") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -mmacosx-version-min=10.14") -endif() - -add_subdirectory(llvm/src/llvm) + find_package(Git) + + set(LLVM_DESIRED_HASH "4434dabb69916856b824f68a64b029c67175e532") + set(PATCHES_DESIRED_HASH "3e16c097794cb669a8f6a0bd7600b440205ac5c29a6135750c2e83263eb16a95") + + if(GIT_FOUND) + if(EXISTS "${PROJECT_SOURCE_DIR}/../.git") + # Update submodules as needed + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Updating submodules...") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE git_submod_result) + #message("git_submod_result ${git_submod_result}") + if(NOT git_submod_result EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive --depth 1 failed with ${git_submod_result}, please checkout submodules") + endif() + + # we check to make sure the submodule hash matches + # the reason the submodule hash is in this file is to be able to use this file as a key for caching the libs in CI + execute_process(COMMAND ${GIT_EXECUTABLE} submodule status + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE git_submod_output) + #message("git_submod_output ${git_submod_output}") + string(FIND "${git_submod_output}" "${LLVM_DESIRED_HASH}" LLVM_SUBMOD_POS) + if(LLVM_SUBMOD_POS EQUAL "-1") + message(FATAL_ERROR "Expecting the lib/llvm/src submodule to be at hash '${LLVM_DESIRED_HASH}'; found '${git_submod_output}'; update the LLVM_DESIRED_HASH variable in lib/CMakeLists.txt if you've updated the submodule.") + endif() + endif() + endif() + + # Apply patches + message("Applying patches...") + file(GLOB PONY_LLVM_PATCHES "${PROJECT_SOURCE_DIR}/llvm/patches/*.diff") + + # check to see if the patch hashes match + message("Checking patches ${PONY_LLVM_PATCHES}") + set(PATCHES_ACTUAL_HASH "needed_if_no_patches") + foreach (PATCH ${PONY_LLVM_PATCHES}) + file(STRINGS ${PATCH} patch_file NEWLINE_CONSUME) + string(REPLACE "\n" " " patch_file "${patch_file}") + string(SHA256 patch_file_hash "${patch_file}") + string(CONCAT PATCHES_ACTUAL_HASH ${PATCHES_ACTUAL_HASH} ${patch_file_hash}) + endforeach() + string(SHA256 PATCHES_ACTUAL_HASH ${PATCHES_ACTUAL_HASH}) + if(NOT PATCHES_ACTUAL_HASH MATCHES "${PATCHES_DESIRED_HASH}") + message(FATAL_ERROR "Patch hash actual '${PATCHES_ACTUAL_HASH}' does not match desired '${PATCHES_DESIRED_HASH}'") + endif() + + foreach (PATCH ${PONY_LLVM_PATCHES}) + message(" Checking ${PATCH}") + execute_process(COMMAND ${GIT_EXECUTABLE} apply --check -p 1 --ignore-whitespace --whitespace=nowarn ${PATCH} + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/llvm/src" + ERROR_VARIABLE _err_out + RESULT_VARIABLE git_apply_check_result) + if(git_apply_check_result EQUAL "0") + message(" Applying ${PATCH}") + execute_process(COMMAND ${GIT_EXECUTABLE} apply -p 1 --ignore-whitespace --whitespace=nowarn ${PATCH} + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/llvm/src" + RESULT_VARIABLE git_apply_result) + if(NOT git_apply_result EQUAL "0") + message(FATAL_ERROR "Unable to apply ${PATCH}") + endif() + else() + message(" Already applied ${PATCH}") + endif() + endforeach() + else() + message(FATAL_ERROR "Git not found!") + endif() + + message("Building targets: ${LLVM_TARGETS_TO_BUILD}") + + set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_OCAMLDOC OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_PIC OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_TOOL_REMARKS_SHLIB_BUILD OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "ponyc specific override of LLVM cache entry") + + if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.14 -DUSE_SCHEDULER_SCALING_PTHREADS") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -mmacosx-version-min=10.14") + endif() + + add_subdirectory(llvm/src/llvm) +endif() \ No newline at end of file diff --git a/make.ps1 b/make.ps1 index 47da668f3..34208c121 100644 --- a/make.ps1 +++ b/make.ps1 @@ -37,7 +37,11 @@ [Parameter(HelpMessage="CITests to run")] [string] - $CiTestsToRun = 'libponyrt.tests,libponyc.tests,libponyc.run.tests.debug,libponyc.run.tests.release,stdlib-debug,stdlib-release,pony-doc-tests' # ,grammar' do not run grammar for now as there is work on th + $CiTestsToRun = 'libponyrt.tests,libponyc.tests,libponyc.run.tests.debug,libponyc.run.tests.release,stdlib-debug,stdlib-release,pony-doc-tests', # ,grammar' do not run grammar for now as there is work on the parser. Reenable later. + + [Parameter(HelpMessage="Extra CMake defines for LLVM")] + [string] + $LibsExtraCmakeDefines = '' ) # Function to extract process exit code from LLDB output @@ -174,12 +178,12 @@ switch ($Command.ToLower()) Write-Output "Configuring libraries..." if ($Arch.Length -gt 0) { - & cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -A $Arch -Thost="$Thost" -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV" -DCMAKE_BUILD_PARALLEL_LEVEL=$numCpus + & cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -A $Arch -Thost="$Thost" -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV" -DCMAKE_BUILD_PARALLEL_LEVEL=$numCpus $LibsExtraCmakeDefines $err = $LastExitCode } else { - & cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -Thost="$Thost" -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV" -DCMAKE_BUILD_PARALLEL_LEVEL=$numCpus + & cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -Thost="$Thost" -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV" -DCMAKE_BUILD_PARALLEL_LEVEL=$numCpus $LibsExtraCmakeDefines $err = $LastExitCode } if ($err -ne 0) { throw "Error: exit code $err" }