Skip to content

Commit

Permalink
Bundle dependencies
Browse files Browse the repository at this point in the history
Helps speed up builds, removes internet requirement to build the package, and solves a build problem on Windows where the dependencies would get built but then couldn't be accessed.
  • Loading branch information
alugowski committed Jan 27, 2023
1 parent 96d295f commit 541d778
Show file tree
Hide file tree
Showing 14 changed files with 6,663 additions and 24 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ jobs:
ctest -C Debug --output-on-failure --verbose
- name: Python Build and Install
# On GitHub Action Windows runner scikit-build has a permission denied error against the
# fast_float and Dragonbox libraries. Workaround by disabling those libraries on Windows for now.
#
# On some platforms pip uses a temporary build directory but only copies the python/ directory there.
# This breaks the relative symbolic links to the C++ library. Workaround is to pass the checkout directory
# as an environment variable so CMakeLists.txt can read it and know where to import the C++ library from.
run: |
if [ "$RUNNER_OS" == "Windows" ]; then export FMM_PYTHON_NO_DEPS=1; fi
export FMM_PYTHON_DIR="$(pwd)" && pip install python/.[test] -v
shell: bash

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ jobs:
CIBW_ARCHS_MACOS: "x86_64 arm64"
# No 32-bit builds. See https://cibuildwheel.readthedocs.io/en/stable/options/#archs
CIBW_SKIP: "*-win32 *_i686"
# Omit fast_float and Dragonbox on Windows because the Windows builder can't access them after it builds them for an unknown reason.
CIBW_ENVIRONMENT_WINDOWS: "FMM_PYTHON_NO_DEPS=1"
# make cibuildwheel install test dependencies from pyproject.toml
CIBW_TEST_EXTRAS: "test"
# run tests in the {package}/tests dir which is python/tests
Expand Down
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ endif()
# Setup fast_float.
# float and double parser.
if (FMM_USE_FAST_FLOAT)
message("Fetching fast_float.")

# Add fast_float library
include(cmake/fast_float.cmake)
message("Using fast_float")
set(FASTFLOAT_INSTALL OFF)
add_subdirectory(dependencies/fast_float)

target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_FAST_FLOAT)
target_link_libraries(fast_matrix_market INTERFACE fast_float)
Expand All @@ -87,9 +86,8 @@ endif()
# Setup Dragonbox.
# float and double formatter for shortest representation. No precision support.
if (FMM_USE_DRAGONBOX)
message("Fetching Dragonbox.")

include(cmake/Dragonbox.cmake)
message("Using Dragonbox")
add_subdirectory(dependencies/dragonbox)

target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_DRAGONBOX)
target_link_libraries(fast_matrix_market INTERFACE dragonbox::dragonbox_to_chars)
Expand All @@ -101,6 +99,7 @@ option(FMM_USE_RYU "Whether or not to use Ryu floating-point to string library"
if (FMM_USE_RYU)
message("Using ryu")
add_subdirectory(dependencies/ryu)

target_link_libraries(fast_matrix_market INTERFACE ryu::ryu)
target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_RYU)
endif()
Expand Down
28 changes: 28 additions & 0 deletions dependencies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Dependencies

Dependencies are included in this directory.

## [fast_float](https://github.com/fastfloat/fast_float)
Floating-point parsing.

Using the single-file release version. To upgrade just paste in a new version of `fast_float.h`.

Optional, set `FMM_USE_FAST_FLOAT=OFF` to disable.

## [Dragonbox](https://github.com/jk-jeon/dragonbox)
Floating-point rendering.

Using a pruned copy of the dragonbox repo. The original includes two large PDFs, subprojects, etc.
Just clone the repo and delete anything not needed to build the library.

Optional, set `FMM_USE_DRAGONBOX=OFF` to disable.

## [Ryu](https://github.com/ulfjack/ryu)
Floating-point rendering with user-specified precision.

Optional, set `FMM_USE_RYU=OFF` to disable.

## [thread-pool](https://github.com/bshoshany/thread-pool)
A lightweight thread pool using C++11 threads.

Bundled in `include/`.
123 changes: 123 additions & 0 deletions dependencies/dragonbox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(dragonbox
VERSION 1.1.3
LANGUAGES CXX)

# ---- Includes ----

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# ---- Warning guard ----

# Protect dependents from this project's warnings if the guard isn't disabled
set(dragonbox_warning_guard "SYSTEM")
if(dragonbox_INCLUDE_WITHOUT_SYSTEM)
set(dragonbox_warning_guard "")
endif()

# ---- Declare library (dragonbox) ----

add_library(dragonbox INTERFACE)
add_library(dragonbox::dragonbox ALIAS dragonbox)

set(dragonbox_headers include/dragonbox/dragonbox.h)

target_include_directories(dragonbox
${dragonbox_warning_guard}
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")

target_compile_features(dragonbox INTERFACE cxx_std_17)

# ---- Declare library (dragonbox_to_chars) ----

set(dragonbox_to_chars_headers
${dragonbox_headers}
include/dragonbox/dragonbox_to_chars.h)

set(dragonbox_to_chars_sources source/dragonbox_to_chars.cpp)

add_library(dragonbox_to_chars STATIC
${dragonbox_to_chars_headers}
${dragonbox_to_chars_sources})
add_library(dragonbox::dragonbox_to_chars ALIAS dragonbox_to_chars)

target_include_directories(dragonbox_to_chars
${dragonbox_warning_guard}
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")

target_compile_features(dragonbox_to_chars PUBLIC cxx_std_17)

# ---- Install ----

option(DRAGONBOX_INSTALL_TO_CHARS
"When invoked with --install, dragonbox_to_chars.h/.cpp are installed along with dragonbox.h"
On)

set(dragonbox_directory "dragonbox-${PROJECT_VERSION}")
set(dragonbox_include_directory "${CMAKE_INSTALL_INCLUDEDIR}/${dragonbox_directory}")
set(dragonbox_install_targets "dragonbox")

if (DRAGONBOX_INSTALL_TO_CHARS)
set(dragonbox_install_targets ${dragonbox_install_targets} dragonbox_to_chars)
endif()

install(TARGETS ${dragonbox_install_targets}
EXPORT dragonboxTargets
ARCHIVE #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT dragonbox_Development
INCLUDES #
DESTINATION "${dragonbox_include_directory}")

set(dragonbox_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${dragonbox_directory}")

write_basic_package_version_file(
dragonboxConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)

install(EXPORT dragonboxTargets
NAMESPACE dragonbox::
DESTINATION "${dragonbox_install_cmakedir}")

install(FILES
"${PROJECT_SOURCE_DIR}/cmake/dragonboxConfig.cmake"
"${PROJECT_BINARY_DIR}/dragonboxConfigVersion.cmake"
DESTINATION "${dragonbox_install_cmakedir}")

if (DRAGONBOX_INSTALL_TO_CHARS)
install(FILES ${dragonbox_to_chars_headers}
DESTINATION "${dragonbox_include_directory}/dragonbox")
else()
install(FILES ${dragonbox_headers}
DESTINATION "${dragonbox_include_directory}/dragonbox")
endif()

# ---- Subproject ----

option(DRAGONBOX_ENABLE_SUBPROJECT "Build subproject as well" OFF)

if (DRAGONBOX_ENABLE_SUBPROJECT)
add_subdirectory("subproject/benchmark")
add_subdirectory("subproject/meta")
add_subdirectory("subproject/test")
endif()

# ---- MSVC Specifics ----
if (MSVC)
# No need to not generate PDB
# /permissive- should be the default
# The compilation will fail without /experimental:newLambdaProcessor
target_compile_options(dragonbox INTERFACE
/Zi /permissive-
$<$<NOT:$<CXX_COMPILER_ID:Clang>>:/experimental:newLambdaProcessor>)
target_compile_options(dragonbox_to_chars PUBLIC
/Zi /permissive-
$<$<NOT:$<CXX_COMPILER_ID:Clang>>:/experimental:newLambdaProcessor>
$<$<CONFIG:Release>:/GL>)
endif()
Loading

0 comments on commit 541d778

Please sign in to comment.