From e9669bedeb7ff6ed1eae50ce16971d89706571cd Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 13 Oct 2023 16:37:39 -0400 Subject: [PATCH 1/4] Moving to CPM. --- CMakeLists.txt | 22 ++++++++++---- benchmarks/CMakeLists.txt | 62 +++++++++++++++++++++++---------------- cmake/import.cmake | 52 -------------------------------- tools/cli/CMakeLists.txt | 11 +++---- 4 files changed, 59 insertions(+), 88 deletions(-) delete mode 100644 cmake/import.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8303dd4d7..738ce539a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,23 @@ option(ADA_BENCHMARKS "Build benchmarks" OFF) # We use Google Benchmark, but it does not build under several 32-bit systems. if((BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) - include(${PROJECT_SOURCE_DIR}/cmake/import.cmake) - import_dependency(simdjson simdjson/simdjson 14d927128ba14e13913fc0e7c2cf538790bd1622) - add_dependency(simdjson) - import_dependency(gtest google/googletest 797b0ad2a3a45608ecf5c67e6e289d377a3521ca) - add_dependency(gtest) + include(cmake/CPM.cmake) + CPMAddPackage("gh:simdjson/simdjson@3.3.0") + CPMAddPackage( + NAME GTest + GITHUB_REPOSITORY google/googletest + VERSION 1.14.0 + OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF" + ) + CPMAddPackage( + NAME benchmark + GITHUB_REPOSITORY google/benchmark + GIT_TAG f91b6b4 + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" + "BENCHMARK_ENABLE_INSTALL OFF" + "BENCHMARK_ENABLE_WERROR OFF" + + ) endif() if (BUILD_TESTING AND NOT EMSCRIPTEN) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b25122c42..48ce05875 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(bench PUBLIC "$") # Benchdata -import_dependency(url-dataset ada-url/url-dataset 9749b92c13e970e70409948fa862461191504ccc) +CPMAddPackage("gh:ada-url/url-dataset#9749b92c13e970e70409948fa862461191504ccc") add_executable(benchdata bench.cpp) target_link_libraries(benchdata PRIVATE ada) target_include_directories(benchdata PUBLIC "$") @@ -45,14 +45,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") target_compile_definitions(model_bench PRIVATE ADA_URL_FILE="${url-dataset_SOURCE_DIR}/out.txt") endif() -include(${PROJECT_SOURCE_DIR}/cmake/import.cmake) - -set_off(BENCHMARK_ENABLE_TESTING) -set_off(BENCHMARK_ENABLE_INSTALL) -set_off(BENCHMARK_ENABLE_WERROR) - -import_dependency(google_benchmarks google/benchmark f91b6b4) -add_dependency(google_benchmarks) target_link_libraries(wpt_bench PRIVATE benchmark::benchmark) target_link_libraries(bench PRIVATE benchmark::benchmark) target_link_libraries(benchdata PRIVATE benchmark::benchmark) @@ -96,10 +88,12 @@ if(NOT ICU_FOUND) endif(NOT ICU_FOUND) if(ICU_FOUND) - set_off(URL_BUILD_TESTS) - set_off(URL_USE_LIBS) - import_dependency(url_whatwg rmisev/url_whatwg cbcf3043eccb380cb4bef7486465ac3b02d2f674) - add_dependency(url_whatwg) + CPMAddPackage( + NAME url_whatwg + GITHUB_REPOSITORY rmisev/url_whatwg + GIT_TAG cbcf3043eccb380cb4bef7486465ac3b02d2f674 + OPTIONS "URL_BUILD_TESTS OFF" "URL_USE_LIBS OFF" + ) add_library(url_whatwg_lib STATIC "${url_whatwg_SOURCE_DIR}/src/url.cpp" "${url_whatwg_SOURCE_DIR}/src/url_idna.cpp" "${url_whatwg_SOURCE_DIR}/src/url_ip.cpp" @@ -129,22 +123,31 @@ endif(ICU_FOUND) if(ADA_COMPETITION) # URI Parser - set_off(URIPARSER_BUILD_TESTS) - set_off(URIPARSER_BUILD_DOCS) - import_dependency(uriparser uriparser/uriparser 634b678) - add_dependency(uriparser) + CPMAddPackage( + NAME uriparser + GITHUB_REPOSITORY uriparser/uriparser + GIT_TAG 634b678 + OPTIONS "URIPARSER_BUILD_TESTS OFF" "URIPARSER_BUILD_DOCS OFF" + ) target_link_libraries(bench PRIVATE uriparser) target_link_libraries(bbc_bench PRIVATE uriparser) - # URL Parser - import_dependency(urlparser netmindms/urlparser 69c09ed) + CPMAddPackage( + NAME urlparser + GITHUB_REPOSITORY netmindms/urlparser + GIT_TAG 69c09ed + ) add_library(urlparser STATIC "${urlparser_SOURCE_DIR}/src/EdUrlParser.cpp") target_include_directories(urlparser PUBLIC "${urlparser_SOURCE_DIR}/src") target_link_libraries(bench PRIVATE urlparser) target_link_libraries(bbc_bench PRIVATE urlparser) # HTTP Parser - import_dependency(httpparser nodejs/http-parser v2.9.4) + CPMAddPackage( + NAME httpparser + GITHUB_REPOSITORY nodejs/http-parser + VERSION 2.9.4 + ) add_library(httpparser STATIC "${httpparser_SOURCE_DIR}/http_parser.c") set_source_files_properties("${httpparser_SOURCE_DIR}/http_parser.c" PROPERTIES LANGUAGE C) target_include_directories(httpparser PUBLIC "${httpparser_SOURCE_DIR}") @@ -203,7 +206,11 @@ find_package( endif(ADA_BOOST_URL) if(Boost_FOUND) - import_dependency(boost_url boostorg/url boost-1.81.0) + CPMAddPackage( + NAME boost_url + GITHUB_REPOSITORY boostorg/url + GIT_TAG boost-1.81.0 + ) add_library(boost_url INTERFACE) target_include_directories(boost_url INTERFACE "${boost_url_SOURCE_DIR}/include") @@ -241,16 +248,19 @@ endif(ZURI_FOUND) # We want the check whether Rust is available before trying to build a crate. -set(Rust_FIND_QUIETLY ON) # No need to alarm the user if rust is not available. -import_dependency(corrosion corrosion-rs/corrosion v0.3.4) +CPMAddPackage( + NAME corrosion + GITHUB_REPOSITORY corrosion-rs/corrosion + VERSION 0.4.4 + DOWNLOAD_ONLY ON + OPTIONS "Rust_FIND_QUIETLY OFF" +) include("${corrosion_SOURCE_DIR}/cmake/FindRust.cmake") if(RUST_FOUND) message(STATUS "Rust found: " ${Rust_VERSION} ) - # Important: we only want to include corrosion *if* rust is available. - # Otherwise, it is impossible to run ada benchmarks without rust. - add_dependency(corrosion) + add_subdirectory("${corrosion_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/corrosion" EXCLUDE_FROM_ALL) # Important: we want to build in release mode! corrosion_import_crate(MANIFEST_PATH "competitors/servo-url/Cargo.toml" NO_LINKER_OVERRIDE PROFILE release) diff --git a/cmake/import.cmake b/cmake/import.cmake deleted file mode 100644 index 9d1493fca..000000000 --- a/cmake/import.cmake +++ /dev/null @@ -1,52 +0,0 @@ -set(dep_root "${ada_SOURCE_DIR}/dependencies/.cache") -if(DEFINED ENV{ada_DEPENDENCY_CACHE_DIR}) - set(dep_root "$ENV{ada_DEPENDENCY_CACHE_DIR}") -endif() - -function(import_dependency NAME GITHUB_REPO COMMIT) - message(STATUS "Importing ${NAME} (${GITHUB_REPO}@${COMMIT})") - set(target "${dep_root}/${NAME}") - - # If the folder exists in the cache, then we assume that everything is as - # should be and do nothing - if(EXISTS "${target}") - set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE) - return() - endif() - - set(zip_url "https://github.com/${GITHUB_REPO}/archive/${COMMIT}.zip") - set(archive "${dep_root}/archive.zip") - set(dest "${dep_root}/_extract") - - file(DOWNLOAD "${zip_url}" "${archive}") - file(MAKE_DIRECTORY "${dest}") - execute_process( - WORKING_DIRECTORY "${dest}" - COMMAND "${CMAKE_COMMAND}" -E tar xf "${archive}") - file(REMOVE "${archive}") - - # GitHub archives only ever have one folder component at the root, so this - # will always match that single folder - file(GLOB dir LIST_DIRECTORIES YES "${dest}/*") - - file(RENAME "${dir}" "${target}") - - set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE) -endfunction() - -# Delegates to the dependency -macro(add_dependency NAME) - if(NOT DEFINED "${NAME}_SOURCE_DIR") - message(FATAL_ERROR "Missing ${NAME}_SOURCE_DIR variable") - endif() - - add_subdirectory("${${NAME}_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/${NAME}" EXCLUDE_FROM_ALL) -endmacro() - -function(set_off NAME) - set("${NAME}" OFF CACHE INTERNAL "") -endfunction() - -function(set_on NAME) - set("${NAME}" ON CACHE INTERNAL "") -endfunction() diff --git a/tools/cli/CMakeLists.txt b/tools/cli/CMakeLists.txt index a770557a4..5d0ca8029 100644 --- a/tools/cli/CMakeLists.txt +++ b/tools/cli/CMakeLists.txt @@ -2,11 +2,12 @@ add_executable(adaparse adaparse.cpp line_iterator.h) target_link_libraries(adaparse PRIVATE ada) target_include_directories(adaparse PUBLIC "$") -include(${PROJECT_SOURCE_DIR}/cmake/import.cmake) -import_dependency(cxxopts jarro2783/cxxopts eb78730) -add_dependency(cxxopts) -import_dependency(fmt fmtlib/fmt a337011) -add_dependency(fmt) +CPMAddPackage("gh:fmtlib/fmt#7.1.3") +CPMAddPackage( + GITHUB_REPOSITORY jarro2783/cxxopts + VERSION 3.1.1 + OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES" +) target_link_libraries(adaparse PRIVATE cxxopts::cxxopts fmt::fmt) if(MSVC OR MINGW) From 0e7e32ab092fb34670c2c5ff27cc3f660e7397f5 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 13 Oct 2023 16:47:14 -0400 Subject: [PATCH 2/4] Missing file --- cmake/CPM.cmake | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cmake/CPM.cmake diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 000000000..ad6b74a8b --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.38.6) +set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) From ed055b6bbc7f83e57adc45c3fa9025b5696866d6 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 13 Oct 2023 21:34:49 -0400 Subject: [PATCH 3/4] tweak --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 738ce539a..5b474dcf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) option(ADA_BENCHMARKS "Build benchmarks" OFF) +include(cmake/CPM.cmake) + # We use Google Benchmark, but it does not build under several 32-bit systems. if((BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) - include(cmake/CPM.cmake) CPMAddPackage("gh:simdjson/simdjson@3.3.0") CPMAddPackage( NAME GTest From eed8ac2130c63d431d9a192b6c236afca5d9efd5 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Sat, 14 Oct 2023 15:01:02 -0400 Subject: [PATCH 4/4] git is a dependency for much of the library build --- .github/workflows/ubuntu-s390x.yml | 2 +- CMakeLists.txt | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ubuntu-s390x.yml b/.github/workflows/ubuntu-s390x.yml index 268acf230..9316ed50c 100644 --- a/.github/workflows/ubuntu-s390x.yml +++ b/.github/workflows/ubuntu-s390x.yml @@ -34,7 +34,7 @@ jobs: githubToken: ${{ github.token }} install: | apt-get update -q -y - apt-get install -y cmake make g++ + apt-get install -y cmake make g++ git apt-get install -y ninja-build run: | cmake -DCMAKE_BUILD_TYPE=Release -G Ninja -B build diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b474dcf3..5650c0e79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) option(ADA_BENCHMARKS "Build benchmarks" OFF) include(cmake/CPM.cmake) - +# CPM requires git as an implicit dependency +find_package(Git QUIET) # We use Google Benchmark, but it does not build under several 32-bit systems. -if((BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) +if(Git_FOUND AND (BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) CPMAddPackage("gh:simdjson/simdjson@3.3.0") CPMAddPackage( NAME GTest @@ -47,8 +48,12 @@ if((BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) endif() if (BUILD_TESTING AND NOT EMSCRIPTEN) - message(STATUS "The tests are enabled.") - add_subdirectory(tests) + if(Git_FOUND) + message(STATUS "The tests are enabled.") + add_subdirectory(tests) + else() + message(STATUS "The tests are disabled because git was not found.") + endif() else() if(is_top_project) message(STATUS "The tests are disabled.") @@ -56,8 +61,12 @@ else() endif(BUILD_TESTING AND NOT EMSCRIPTEN) If(ADA_BENCHMARKS AND NOT EMSCRIPTEN) - message(STATUS "Ada benchmarks enabled.") - add_subdirectory(benchmarks) + if(Git_FOUND) + message(STATUS "Ada benchmarks enabled.") + add_subdirectory(benchmarks) + else() + message(STATUS "The benchmarks are disabled because git was not found.") + endif() else(ADA_BENCHMARKS AND NOT EMSCRIPTEN) if(is_top_project) message(STATUS "Ada benchmarks disabled. Set ADA_BENCHMARKS=ON to enable them.") @@ -85,7 +94,11 @@ if(NOT ADA_COVERAGE AND NOT EMSCRIPTEN) endif() if(ADA_TOOLS) - add_subdirectory(tools) + if(Git_FOUND) + add_subdirectory(tools) + else() + message(STATUS "The tools are disabled because git was not found.") + endif() endif() install(