Skip to content

Commit bb6fe6a

Browse files
authored
Merge pull request #70 from brawer/fetchcontent-roaring
Use cmake FetchContent for CRoaring
2 parents 55488b1 + a1e5c5a commit bb6fe6a

File tree

9 files changed

+70
-24
lines changed

9 files changed

+70
-24
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "vendor/CRoaring"]
2-
path = vendor/CRoaring
3-
url = https://github.com/RoaringBitmap/CRoaring.git
41
[submodule "vendor/s2geometry"]
52
path = vendor/s2geometry
63
url = https://github.com/google/s2geometry.git

CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ set(CMAKE_CXX_FLAGS "-Wno-deprecated-declarations")
99
set(CMAKE_CXX_FLAGS "-pthread")
1010
set(OSMX_VERSION "0.2.0")
1111
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
12-
set(ROARING_BUILD_STATIC ON CACHE INTERNAL "")
13-
set(ROARING_LINK_STATIC ON CACHE INTERNAL "")
12+
set(ROARING_USE_CPM OFF)
13+
set(ENABLE_ROARING_TESTS OFF)
1414

1515
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
1616
include(FetchContent)
@@ -69,8 +69,15 @@ FetchContent_Declare(
6969
EXCLUDE_FROM_ALL
7070
FIND_PACKAGE_ARGS)
7171

72+
FetchContent_Declare(
73+
roaring
74+
GIT_REPOSITORY https://github.com/RoaringBitmap/CRoaring.git
75+
GIT_TAG v4.3.6
76+
EXCLUDE_FROM_ALL
77+
FIND_PACKAGE_ARGS)
78+
7279
FetchContent_MakeAvailable(
73-
CapnProto Catch2 cxxopts LMDB nlohmann_json Osmium Protozero)
80+
CapnProto Catch2 cxxopts LMDB nlohmann_json Osmium Protozero roaring)
7481

7582
if(NOT CapnProto_FOUND)
7683
add_subdirectory(${capnproto_SOURCE_DIR} EXCLUDE_FROM_ALL)
@@ -104,11 +111,8 @@ if(NOT Protozero_FOUND)
104111
endif()
105112

106113
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/s2geometry EXCLUDE_FROM_ALL)
107-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/CRoaring EXCLUDE_FROM_ALL)
108114

109115
include_directories(vendor/s2geometry/src)
110-
include_directories(vendor/CRoaring/cpp)
111-
include_directories(vendor/CRoaring/include)
112116
include_directories(include)
113117

114118
# needed for Expat install dir

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM alpine:3.22 AS builder
22

3+
# TODO: Add croaring-dev once available in Alpine Linux.
4+
# https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/87769
35
RUN apk add --no-cache \
46
clang \
57
cmake \
@@ -31,7 +33,7 @@ FROM alpine:3.22
3133

3234
# cxxopts, libosmium, nlohmann-json and protozero are header-only
3335
# C++ libraries; catch2 is only used for testing. We do not need
34-
# to install these.
36+
# them in the production container.
3537
RUN apk add --no-cache \
3638
libbz2 \
3739
libcrypto3 \

examples/bbox_wkt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "s2/s2latlng.h"
66
#include "s2/s2region_coverer.h"
77
#include "s2/s2latlng_rect.h"
8-
#include "roaring64map.hh"
8+
#include "roaring/roaring64map.hh"
99

1010
using namespace std;
1111

include/osmx/storage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "osmx/messages.capnp.h"
88
#include "osmx/util.h"
99
#include "s2/s2cell_id.h"
10-
#include "roaring64map.hh"
10+
#include "roaring/roaring64map.hh"
1111

1212
namespace osmx { namespace db {
1313

@@ -103,7 +103,7 @@ class IndexWriter : public Noncopyable {
103103
int mWrites = 0;
104104
};
105105

106-
void traverseCell(MDB_cursor *cursor,S2CellId cell_id,Roaring64Map &set);
107-
void traverseReverse(MDB_cursor *cursor,uint64_t from, Roaring64Map &set);
106+
void traverseCell(MDB_cursor *cursor, S2CellId cell_id, roaring::Roaring64Map &set);
107+
void traverseReverse(MDB_cursor *cursor, uint64_t from, roaring::Roaring64Map &set);
108108

109-
} }
109+
} }

src/extract.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ void cmdExtract(int argc, char * argv[]) {
147147
cout << "Query cells: " << covering.cell_ids().size() << endl;
148148
}
149149

150-
Roaring64Map node_ids;
151-
Roaring64Map way_ids;
152-
Roaring64Map relation_ids;
150+
roaring::Roaring64Map node_ids;
151+
roaring::Roaring64Map way_ids;
152+
roaring::Roaring64Map relation_ids;
153153

154154
MDB_env* env = db::createEnv(result["osmx"].as<string>(),false);
155155
MDB_txn* txn;
@@ -214,8 +214,8 @@ void cmdExtract(int argc, char * argv[]) {
214214
MDB_cursor *cursor;
215215
CHECK_LMDB(mdb_dbi_open(txn, "relation_relation", MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_INTEGERDUP, &dbi));
216216
CHECK_LMDB(mdb_cursor_open(txn,dbi,&cursor));
217-
Roaring64Map discovered_relations;
218-
Roaring64Map discovered_relations_2;
217+
roaring::Roaring64Map discovered_relations;
218+
roaring::Roaring64Map discovered_relations_2;
219219

220220
for (auto const &relation_id : relation_ids) {
221221
db::traverseReverse(cursor,relation_id,discovered_relations);

src/storage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void IndexWriter::commit() {
168168
CHECK_LMDB(mdb_txn_commit(mTxn));
169169
}
170170

171-
void traverseCell(MDB_cursor *cursor,S2CellId cell_id,Roaring64Map &set) {
171+
void traverseCell(MDB_cursor *cursor, S2CellId cell_id, roaring::Roaring64Map &set) {
172172
S2CellId start = cell_id.child_begin(CELL_INDEX_LEVEL);
173173
S2CellId end = cell_id.child_end(CELL_INDEX_LEVEL);
174174
MDB_val key, data;
@@ -191,7 +191,7 @@ void traverseCell(MDB_cursor *cursor,S2CellId cell_id,Roaring64Map &set) {
191191
}
192192
}
193193

194-
void traverseReverse(MDB_cursor *cursor,uint64_t from, Roaring64Map &set) {
194+
void traverseReverse(MDB_cursor *cursor,uint64_t from, roaring::Roaring64Map &set) {
195195
MDB_val key, data;
196196
key.mv_size = sizeof(uint64_t);
197197
key.mv_data = (void *)&from;

src/update.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,57 @@
22
#include <cassert>
33
#include <set>
44
#include "cxxopts.hpp"
5-
#include "roaring.hh"
65
#include "osmium/handler.hpp"
76
#include "osmium/io/any_input.hpp"
87
#include "osmium/visitor.hpp"
98
#include "osmium/util/progress_bar.hpp"
9+
#include "roaring/roaring.hh"
10+
11+
// Historically, OSMExpress had vendored its dependencies, but we move away
12+
// from this. At the moment, the S2 geometry library is the last remaining
13+
// dependency still being vendored. Our (rather ancient) bundled version
14+
// of S2 tests for a number of implementations of the Standard C library.
15+
// If S2 happens to recognize the library, it includes <byteswap.h>
16+
// (unless it is being compiled by a Microsoft or Apple compiler);
17+
// otherwise, S2 falls back to its own byteswap implementation.
18+
// What S2 does (or rather did, in the old version we happen
19+
// to bundle) isn't so great; it would have been better for S2 to use
20+
// a standards-conforming way of byteswapping, test for its presence,
21+
// and only use the fallback if that test fails. But that's how it is.
22+
//
23+
// Anyhow, the (equally ancient) version of CRoaring, another library
24+
// that we previously vendored into OSMExpress, was polluting the
25+
// C macro namespace in a way that made our bundled version of S2
26+
// believe to be on a C library it knew about. Therefore, at the time
27+
// when OSMExpress still vendored that old version of CRoaring, the
28+
// bundled version of S2 would always include <byteswap.h> instead
29+
// of (re-)defining it, even if S2 did not recognize the C library.
30+
//
31+
// As we upgraded CRoaring to a newer version, which does not pollute
32+
// the C macro namespace anymore, the C preprocessor would now execute
33+
// the fallback path in the S2 headers when compiling with a Standard C
34+
// library that our old version of S2 does not recognize. This caused
35+
// compilation errors on Alpine Linux, which uses musl, a very lightweight
36+
// but fully standards-conforming implementation of the Standard C library.
37+
//
38+
// The following hack prevents our vendored old version of S2 from
39+
// supplying its own byteswap functions. On Bionic (and also other
40+
// modern libc implementations, including musl), it is sufficient to
41+
// include <byteswap.h>. Note we cannot explicitly test for musl here,
42+
// because musl does not define a __MUSL__ macro. (They don't want to,
43+
// since such a macro would not be standards-conforming; whether it's
44+
// really helpful to be so puristic has been the subject of much debate).
45+
//
46+
// TODO: Remove this hack once we stop vendoring the S2 geometry library.
47+
// https://github.com/bdon/OSMExpress/issues/20
48+
#if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(__GLIBC__) \
49+
&& !defined(__BIONIC__) && !defined(__ASYLO__)
50+
#define __BIONIC__ 1
51+
#endif
52+
1053
#include "s2/s2latlng.h"
1154
#include "s2/s2cell_union.h"
55+
1256
#include "osmx/storage.h"
1357
#include "osmx/util.h"
1458

vendor/CRoaring

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)