Skip to content

Commit

Permalink
remove linking to boost (valhalla#3346)
Browse files Browse the repository at this point in the history
* add cxxopts at v2.2.1 (302302b), poc for valhalla_build_tiles

* add back condition

* somehow the submodule wasn't properly registered

* turn off clang-format for the options

* remove input_files var

* can't remove input_files, need to re-orer

* valhalla_build_admins

* migrate all other relevant executables to cxxopts

* still an orphan reference for bpo

* minor changes

* more minor changes

* fix add predicted speeds

* fix run_route

* last errors

* get rid of more redundant stuff

* overlooked a few more redundancies

* add boost dependencies via bcp: needs some maunal cleaning, a few files and directories are redundant; remove all boost references

* finally conan worked; removed all other boost build references; temp install conan on circieci until docker is pushed, btw: looks like a bug in the builder image dockerfile

* forgot circleci runs in valhalla's image

* copy/paste fail to osx

* -y for apt-get..

* still a conflic message in cmakelists.txt

* changelog and oops, still boost

* small typo in cmakelists.txt

* clean up after own review

* this isnt compiled and its served its purpose as as POC

* change boost::headers to boost::boost for compatibility; check in the conan.cmake to git to avoid downloading

* shorten conan handling in root cmakelists

* maybe the missing boost depends was screwing with msvc

* adapt CI to cache conan directory

* changelog

* add conanfile.txt hash to azure cache key; few other minor fixes

* can't reproduce the osx & win failures on linux locally, but might be missing the append to cmake_prefix_paths

* reading error messages helps..

* dumb mistake

* add back the conan recommended way

* finally found the sucker.. bug in conan's boost recipe: somehow it wants to link to boost.regex on the mjolnir executables for windows/visual studio only; no idea what causes or how to even reproduce in a minimal example to file a bug, must be some mjolnir link no since the TOOLS exes seem to be fine no?! important to note: this trick will likely only work as long as conan installs an older version of boost than we're referencing with our vcpkg commit. remove this dependency once conan fixed it upstream

* kevin found the problem.. not that it's _at all_ comprehensible what exactly is going on but hey, fixed for us;)

* oops haha accidentally cached the whole source tree on azure

* remove temp ci stuff now that conan is installed in the build imag

* Update Dockerfile-run

* let cmake discover existing boost installations

Co-authored-by: Kevin Kreiser <[email protected]>
  • Loading branch information
nilsnolde and kevinkreiser authored Dec 14, 2021
1 parent a9bdd47 commit 20a655d
Show file tree
Hide file tree
Showing 37 changed files with 1,857 additions and 2,265 deletions.
29 changes: 22 additions & 7 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
VCPKG_DIR: '$(Build.SourcesDirectory)\vcpkg'
VCPKG_REF: 'f4bd6423'
TRIPLET: 'x64'
CONAN_HOME: '$(Build.SourcesDirectory)/conan'

steps:
- script: |
Expand All @@ -52,16 +53,24 @@ jobs:
key: .\.vcpkg_deps.txt | "$(VCPKG_REF)" | "$(TRIPLET)" | ".v2"
path: "$(VCPKG_DIR)"
cacheHitVar: CACHE_RESTORED

- task: Cache@2
displayName: "Cache build"
displayName: "Cache conan packages"
inputs:
key: '"msvc-v16.10.0" | build | "$(Build.SourceBranch)"'
path: "$(BUILD_DIR)"
restoreKeys: |
"msvc-v16.10.0" | build | "$(Build.SourceBranch)"
"msvc-v16.10.0" | build
key: '"msvc-v16.10.0" | conan | .\conanfile.txt | "$(Build.SourceBranch)" | "v2"'
path: "$(CONAN_HOME)"
cacheHitVar: BUILD_CACHE_RESTORED

# TODO: cache build never worked, look into it
# - task: Cache@2
# displayName: "Cache build"
# inputs:
# key: '"msvc-v16.10.0" | build | "$(Build.SourceBranch)"'
# path: "$(BUILD_DIR)"
# restoreKeys: |
# "msvc-v16.10.0" | build | "$(Build.SourceBranch)"
# "msvc-v16.10.0" | build
# cacheHitVar: BUILD_CACHE_RESTORED

- task: UsePythonVersion@0
inputs:
Expand Down Expand Up @@ -102,6 +111,10 @@ jobs:
Expand-Archive $(Build.SourcesDirectory)\ninja_win.zip -DestinationPath $(Build.SourcesDirectory)\ninja
displayName: 'Download Ninja'
- script: |
pip install conan
displayName: Install conan
- script: |
SET PATH=%PATH%;$(Build.SourcesDirectory)\ninja
pushd "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
Expand All @@ -110,6 +123,8 @@ jobs:
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
cmake --version
cmake -G "Ninja" -H$(Build.SourcesDirectory) -B%BUILD_DIR% -DCMAKE_BUILD_TYPE=%BUILD_CFG% -DCMAKE_TOOLCHAIN_FILE=%VCPKG_DIR%\scripts\buildsystems\vcpkg.cmake -DVCPKG_APPLOCAL_DEPS=ON -DENABLE_DATA_TOOLS=ON -DENABLE_TOOLS=ON -DENABLE_PYTHON_BINDINGS=ON -DENABLE_TESTS=OFF -DENABLE_CCACHE=OFF -DENABLE_HTTP=OFF -DENABLE_SERVICES=OFF -DENABLE_BENCHMARKS=OFF -DLUA_INCLUDE_DIR=%VCPKG_DIR%\installed\%TRIPLET%-windows\include\luajit -DLUA_LIBRARIES=%VCPKG_DIR%\installed\%TRIPLET%-windows\lib\lua51.lib"
env:
CONAN_USER_HOME: $(CONAN_HOME)
displayName: 'Run CMake to configure build'
- script: |
Expand Down
25 changes: 14 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ executors:
commands:
install_macos_dependencies:
steps:
- run: brew install protobuf cmake ccache libtool boost libspatialite pkg-config luajit curl wget czmq lz4 spatialite-tools unzip
- run: pip3 install requests shapely
- run: brew install protobuf cmake ccache libtool libspatialite pkg-config luajit curl wget czmq lz4 spatialite-tools unzip
- run: pip3 install requests shapely conan
- run: git clone https://github.com/kevinkreiser/prime_server --recurse-submodules && cd prime_server && ./autogen.sh && ./configure && make -j4 && make install

jobs:
Expand Down Expand Up @@ -58,8 +58,8 @@ jobs:
- run: git submodule sync && git submodule update --init
- restore_cache:
keys:
- ccache-debug-linux-x86_64-{{ .Branch }}
- ccache-debug-linux-x86_64
- ccache-debug-linux-x86_64-{{ .Branch }}-{{ checksum "conanfile.txt" }}
- ccache-debug-linux-x86_64-{{ checksum "conanfile.txt" }}
- run: mkdir build
- run: |
# NOTE: -Werror disabled in CI, as we currently have >4k warnings.
Expand All @@ -78,9 +78,10 @@ jobs:
# Note: we save the cache here before doing linting so that if linting fails, we can rebuild quickly
# for follow-up fixes
- save_cache:
key: ccache-debug-linux-x86_64-{{ .Branch }}-{{ epoch }}
key: ccache-debug-linux-x86_64-{{ .Branch }}-{{ checksum "conanfile.txt" }}-{{ epoch }}
paths:
- ~/.ccache
- ~/.conan
- run: scripts/clang-tidy-only-diff.sh 4
- run: make -C build install
- run: make -C build package
Expand All @@ -104,8 +105,8 @@ jobs:
- run: git submodule sync && git submodule update --init
- restore_cache:
keys:
- ccache-release-linux-x86_64-{{ .Branch }}
- ccache-release-linux-x86_64
- ccache-release-linux-x86_64-{{ .Branch }}-{{ checksum "conanfile.txt" }}
- ccache-release-linux-x86_64-{{ checksum "conanfile.txt" }}
- run: mkdir build
- run: |
cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On -DENABLE_PYTHON_BINDINGS=On \
Expand All @@ -119,9 +120,10 @@ jobs:
- run: make -C build -j8 benchmarks
- run: make -C build -j8 run-benchmarks
- save_cache:
key: ccache-release-linux-x86_64-{{ .Branch }}-{{ epoch }}
key: ccache-release-linux-x86_64-{{ .Branch }}-{{ checksum "conanfile.txt" }}-{{ epoch }}
paths:
- ~/.ccache
- ~/.conan
- run: make -C build install
- run: make -C build package

Expand All @@ -139,8 +141,8 @@ jobs:
- run: git submodule sync && git submodule update --init
- restore_cache:
keys:
- ccache-release-macos-{{ .Branch }}
- ccache-release-macos
- ccache-release-macos-{{ .Branch }}-{{ checksum "conanfile.txt" }}
- ccache-release-macos-{{ checksum "conanfile.txt" }}
- run: mkdir -p build
- run: cd build && cmake ..
- run: make -C build -j4
Expand All @@ -150,9 +152,10 @@ jobs:
- run: make -C build -j2 benchmarks
- run: make -C build run-benchmarks
- save_cache:
key: ccache-release-macos-{{ .Branch }}-{{ epoch }}
key: ccache-release-macos-{{ .Branch }}-{{ checksum "conanfile.txt" }}-{{ epoch }}
paths:
- ~/.ccache
- ~/.conan

workflows:
version: 2
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@
[submodule "third_party/lz4"]
path = third_party/lz4
url = https://github.com/lz4/lz4
[submodule "third_party/cxxopts"]
path = third_party/cxxopts
url = https://github.com/jarro2783/cxxopts.git
9 changes: 0 additions & 9 deletions .vcpkg_deps.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
boost-algorithm
boost-config
boost-core
boost-heap
boost-lexical-cast
boost-property-tree
boost-variant
boost-geometry
boost-program-options
curl
protobuf
zlib
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* CHANGED: Removed all protobuf defaults either by doing them in code or by relying on 0 initialization. Also deprecated best_paths and do_not_track [#3454](https://github.com/valhalla/valhalla/pull/3454)
* ADDED: isochrone action for /expansion endpoint to track dijkstra expansion [#3215](https://github.com/valhalla/valhalla/pull/3215)
* CHANGED: remove boost from dependencies and add conan as prep for #3346 [#3459](https://github.com/valhalla/valhalla/pull/3459)
* CHANGED: Remove boost.program_options in favor of cxxopts header-only lib and use conan to install header-only boost. [#3346](https://github.com/valhalla/valhalla/pull/3346)

## Release Date: 2021-10-07 Valhalla 3.1.4
* **Removed**
Expand Down
42 changes: 31 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ endif()
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)

# try to find an installed boost or install locally with conan
set(boost_VERSION "1.71")
find_package(Boost ${boost_VERSION} QUIET)
if (NOT Boost_FOUND)
# bail if there's no conan installed
message(STATUS "No compatible boost version detected, using conan...")
find_program(conan_FOUND conan)
if (NOT conan_FOUND)
message(FATAL_ERROR "conan needs to be installed for boost, see https://docs.conan.io/en/latest/installation.html.")
endif()

# build dir needs to be added, that's where conan writes some info
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
include(${VALHALLA_SOURCE_DIR}/cmake/conan.cmake)

conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE ${VALHALLA_SOURCE_DIR}/conanfile.txt
REMOTE conancenter
SETTINGS ${settings}
OUTPUT_QUIET)
endif()
find_package(Boost ${boost_VERSION} REQUIRED)
add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)

if(NOT TARGET CURL::CURL)
add_library(CURL::CURL INTERFACE IMPORTED)
if(ENABLE_HTTP OR ENABLE_DATA_TOOLS)
Expand Down Expand Up @@ -219,22 +244,14 @@ endif()
## Mjolnir and associated executables
if(ENABLE_DATA_TOOLS)
add_compile_definitions(DATA_TOOLS)
find_package(Boost 1.51 REQUIRED COMPONENTS program_options)
find_package(SQLite3 REQUIRED)
find_package(SpatiaLite REQUIRED)
find_package(LuaJIT)
add_library(Lua::Lua INTERFACE IMPORTED)
set_target_properties(Lua::Lua PROPERTIES
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}")
## Top level executables
elseif(ENABLE_TOOLS)
find_package(Boost 1.51 REQUIRED COMPONENTS program_options)
## Header only boost for the library without mjolnir
elseif(NOT Boost_FOUND)
find_package(Boost 1.51 REQUIRED)
endif()
add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)

if (ENABLE_THREAD_SAFE_TILE_REF_COUNT)
add_definitions(-DENABLE_THREAD_SAFE_TILE_REF_COUNT)
Expand Down Expand Up @@ -291,7 +308,8 @@ if(ENABLE_TOOLS)
add_executable(${program} ${path})
set_target_properties(${program} PROPERTIES FOLDER "Tools")
create_source_groups("Source Files" ${path})
target_link_libraries(${program} Boost::program_options valhalla)
target_link_libraries(${program} valhalla)
target_include_directories(${program} PUBLIC ${VALHALLA_SOURCE_DIR}/third_party/cxxopts/include)
if(MSVC)
target_link_libraries(${program} ${CURL_LIBRARIES})
endif()
Expand All @@ -305,7 +323,8 @@ if(ENABLE_DATA_TOOLS)
add_executable(${program} ${path})
create_source_groups("Source Files" ${path})
set_target_properties(${program} PROPERTIES FOLDER "Data Tools")
target_link_libraries(${program} valhalla Boost::program_options)
target_include_directories(${program} PUBLIC ${VALHALLA_SOURCE_DIR}/third_party/cxxopts/include)
target_link_libraries(${program} valhalla)
if (LUAJIT_FOUND AND APPLE)
# Using LuaJIT on macOS requires a couple of extra linker flags
target_link_options(${program} PUBLIC -pagezero_size 10000 -image_base 100000000)
Expand All @@ -330,7 +349,8 @@ if(ENABLE_SERVICES)
add_executable(${program} src/${program}.cc)
create_source_groups("Source Files" src/${program}.cc)
set_target_properties(${program} PROPERTIES FOLDER "Services")
target_link_libraries(${program} valhalla Boost::program_options)
target_link_libraries(${program} valhalla)
target_include_directories(${program} PUBLIC ${VALHALLA_SOURCE_DIR}/third_party/cxxopts/include)
install(TARGETS ${program} DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime)
endforeach()
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ To install on a Debian or Ubuntu system you need to install its dependencies wit
```bash
sudo add-apt-repository -y ppa:valhalla-core/valhalla
sudo apt-get update
sudo apt-get install -y cmake make libtool pkg-config g++ gcc curl unzip jq lcov protobuf-compiler vim-common locales libboost-all-dev libcurl4-openssl-dev zlib1g-dev liblz4-dev libprime-server-dev libprotobuf-dev prime-server-bin
sudo apt-get install -y cmake make libtool pkg-config g++ gcc curl unzip jq lcov protobuf-compiler vim-common locales libcurl4-openssl-dev zlib1g-dev liblz4-dev libprime-server-dev libprotobuf-dev prime-server-bin
#if you plan to compile with data building support, see below for more info
sudo apt-get install -y libgeos-dev libgeos++-dev libluajit-5.1-dev libspatialite-dev libsqlite3-dev wget sqlite3 spatialite-bin python3-shapely
source /etc/lsb-release
Expand Down Expand Up @@ -172,7 +172,7 @@ To install valhalla on macOS, you need to install its dependencies with [Homebre

```bash
# install dependencies (automake & czmq are required by prime_server)
brew install automake cmake libtool protobuf-c boost-python libspatialite pkg-config sqlite3 jq curl wget czmq lz4 spatialite-tools unzip luajit
brew install automake cmake libtool protobuf-c libspatialite pkg-config sqlite3 jq curl wget czmq lz4 spatialite-tools unzip luajit
# following packages are needed for running Linux compatible scripts
brew install bash coreutils binutils
# Update your PATH env variable to include /usr/local/opt/binutils/bin:/usr/local/opt/coreutils/libexec/gnubin
Expand Down
Loading

0 comments on commit 20a655d

Please sign in to comment.