-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
278 lines (251 loc) · 11.6 KB
/
Copy pathCMakeLists.txt
File metadata and controls
278 lines (251 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
cmake_minimum_required(VERSION 3.20)
set(CORROSION_VERBOSE_OUTPUT ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Get installed Rust targets
execute_process(
COMMAND rustup target list --installed
OUTPUT_VARIABLE RUST_TARGETS
ERROR_QUIET
)
# Propagate arch to rust build for CI
set(Rust_CARGO_TARGET "")
if("${OS_NAME}" STREQUAL "linux")
if ("${OS_ARCH}" STREQUAL "arm64")
set(Rust_CARGO_TARGET "aarch64-unknown-linux-gnu")
elseif("${CMAKE_CXX_COMPILER}" MATCHES "aarch64")
set(Rust_CARGO_TARGET "aarch64-unknown-linux-gnu")
else()
string(FIND "${RUST_TARGETS}" "musl" MUSL_TARGET_FOUND)
if(NOT MUSL_TARGET_FOUND EQUAL -1)
set(Rust_CARGO_TARGET "x86_64-unknown-linux-musl")
else()
set(Rust_CARGO_TARGET "x86_64-unknown-linux-gnu")
endif()
endif()
elseif("${OS_NAME}" STREQUAL "osx")
if ("${OSX_BUILD_ARCH}" STREQUAL "arm64")
set(Rust_CARGO_TARGET "aarch64-apple-darwin")
elseif ("${OSX_BUILD_ARCH}" STREQUAL "x86_64")
set(Rust_CARGO_TARGET "x86_64-apple-darwin")
elseif ("${OS_ARCH}" STREQUAL "arm64")
set(Rust_CARGO_TARGET "aarch64-apple-darwin")
endif()
elseif(WIN32)
if (MINGW AND "${OS_ARCH}" STREQUAL "arm64")
set(Rust_CARGO_TARGET "aarch64-pc-windows-gnu")
elseif (MINGW AND "${OS_ARCH}" STREQUAL "amd64")
set(Rust_CARGO_TARGET "x86_64-pc-windows-gnu")
elseif (MSVC AND "${OS_ARCH}" STREQUAL "arm64")
set(Rust_CARGO_TARGET "aarch64-pc-windows-msvc")
elseif (MSVC AND "${OS_ARCH}" STREQUAL "amd64")
set(Rust_CARGO_TARGET "x86_64-pc-windows-msvc")
endif()
endif()
# Check for WASM target
string(FIND "${RUST_TARGETS}" "wasm32-unknown-emscripten" WASM_TARGET_FOUND)
if (NOT WASM_TARGET_FOUND EQUAL -1)
set(Rust_CARGO_TARGET "wasm32-unknown-emscripten")
endif()
message(STATUS "Rust_CARGO_TARGET: ${Rust_CARGO_TARGET}")
message(STATUS "OS_NAME: ${OS_NAME}")
message(STATUS "OS_ARCH: ${OS_ARCH}")
# Fetch Corrosion for Rust integration
# Disable vcpkg for Corrosion's internal CMake to avoid toolchain conflicts
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.5.2
)
# Set any global configuration variables such as `Rust_TOOLCHAIN` before this line!
FetchContent_MakeAvailable(Corrosion)
# Import the Rust FFI crate
corrosion_import_crate(
MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/crates/anofox-stats-ffi/Cargo.toml"
CRATES "anofox_stats_ffi"
)
# Set extension name here
set(TARGET_NAME anofox_statistics)
set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
project(${TARGET_NAME})
# --- Telemetry (disabled on MinGW where vcpkg cannot build OpenSSL) ---
if(NOT MINGW)
find_package(OpenSSL REQUIRED)
add_library(posthog_telemetry_obj OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/posthog-telemetry/src/telemetry.cpp
)
target_include_directories(posthog_telemetry_obj PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/posthog-telemetry/include
${CMAKE_CURRENT_SOURCE_DIR}/duckdb/src/include
${CMAKE_CURRENT_SOURCE_DIR}/duckdb/third_party
${CMAKE_CURRENT_SOURCE_DIR}/duckdb/third_party/httplib
${OPENSSL_INCLUDE_DIR}
)
target_compile_features(posthog_telemetry_obj PUBLIC cxx_std_17)
target_compile_definitions(posthog_telemetry_obj PRIVATE ANOFOX_TELEMETRY_ENABLED)
set(ANOFOX_TELEMETRY_ENABLED ON)
else()
message(STATUS "Telemetry disabled: OpenSSL not available on MinGW")
set(ANOFOX_TELEMETRY_ENABLED OFF)
endif()
# Feedback banner (header-only, no dependencies of its own). Its banner_shown
# event goes through posthog-telemetry, so the flag follows whether telemetry is
# actually compiled in -- on MinGW it is not, and the banner header would then
# include a telemetry.hpp that is not on the path.
set(DATAZOO_BANNER_TELEMETRY ${ANOFOX_TELEMETRY_ENABLED} CACHE BOOL "" FORCE)
set(DATAZOO_BANNER_TELEMETRY_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/posthog-telemetry/include CACHE PATH "" FORCE)
add_subdirectory(datazoo-banner)
include_directories(src/include)
# Extension source files
set(EXTENSION_SOURCES
src/anofox_statistics_extension.cpp
src/include/map_options_parser.cpp
src/table_functions/ols_fit.cpp
src/table_functions/ridge_fit.cpp
src/table_functions/elasticnet_fit.cpp
src/table_functions/wls_fit.cpp
src/table_functions/huber_fit.cpp
src/table_functions/ransac_fit.cpp
src/table_functions/theil_sen_fit.cpp
src/table_functions/predict.cpp
src/table_functions/rls_fit.cpp
src/aggregate_functions/ols_aggregate.cpp
src/aggregate_functions/ridge_aggregate.cpp
src/aggregate_functions/elasticnet_aggregate.cpp
src/aggregate_functions/lars_aggregate.cpp
src/aggregate_functions/wls_aggregate.cpp
src/aggregate_functions/huber_aggregate.cpp
src/aggregate_functions/ransac_aggregate.cpp
src/aggregate_functions/theil_sen_aggregate.cpp
src/aggregate_functions/rls_aggregate.cpp
src/aggregate_functions/vif_aggregate.cpp
src/aggregate_functions/jarque_bera_aggregate.cpp
src/aggregate_functions/residuals_diagnostics_aggregate.cpp
src/aggregate_functions/ols_predict_aggregate.cpp
src/aggregate_functions/huber_predict_aggregate.cpp
src/aggregate_functions/ransac_predict_aggregate.cpp
src/aggregate_functions/theil_sen_predict_aggregate.cpp
src/aggregate_functions/ridge_predict_aggregate.cpp
src/aggregate_functions/wls_predict_aggregate.cpp
src/aggregate_functions/rls_predict_aggregate.cpp
src/aggregate_functions/elasticnet_predict_aggregate.cpp
src/aggregate_functions/poisson_aggregate.cpp
src/aggregate_functions/aft_aggregate.cpp
src/aggregate_functions/eb_shrink_aggregate.cpp
src/aggregate_functions/glmm_aggregate.cpp
src/aggregate_functions/binomial_aggregate.cpp
src/aggregate_functions/negbinom_aggregate.cpp
src/aggregate_functions/tweedie_aggregate.cpp
src/aggregate_functions/gamma_aggregate.cpp
src/aggregate_functions/logistic_aggregate.cpp
src/aggregate_functions/alm_aggregate.cpp
src/aggregate_functions/bls_aggregate.cpp
src/aggregate_functions/bls_fit_predict_aggregate.cpp
src/aggregate_functions/alm_fit_predict_aggregate.cpp
src/aggregate_functions/poisson_fit_predict_aggregate.cpp
src/aggregate_functions/aid_aggregate.cpp
src/aggregate_functions/shapiro_wilk_aggregate.cpp
src/aggregate_functions/t_test_aggregate.cpp
src/aggregate_functions/pearson_aggregate.cpp
src/aggregate_functions/spearman_aggregate.cpp
src/aggregate_functions/mann_whitney_aggregate.cpp
src/aggregate_functions/anova_aggregate.cpp
src/aggregate_functions/kruskal_wallis_aggregate.cpp
src/aggregate_functions/chisq_aggregate.cpp
src/aggregate_functions/kendall_aggregate.cpp
src/aggregate_functions/fisher_exact_aggregate.cpp
src/aggregate_functions/brunner_munzel_aggregate.cpp
src/aggregate_functions/dagostino_k2_aggregate.cpp
src/aggregate_functions/energy_distance_aggregate.cpp
src/aggregate_functions/mmd_aggregate.cpp
src/aggregate_functions/tost_t_test_aggregate.cpp
src/aggregate_functions/wilcoxon_signed_rank_aggregate.cpp
src/aggregate_functions/distance_cor_aggregate.cpp
src/aggregate_functions/yuen_aggregate.cpp
src/aggregate_functions/brown_forsythe_aggregate.cpp
src/aggregate_functions/diebold_mariano_aggregate.cpp
src/aggregate_functions/clark_west_aggregate.cpp
src/aggregate_functions/permutation_t_test_aggregate.cpp
src/aggregate_functions/tost_paired_aggregate.cpp
src/aggregate_functions/tost_correlation_aggregate.cpp
src/aggregate_functions/chisq_gof_aggregate.cpp
src/aggregate_functions/prop_test_one_aggregate.cpp
src/aggregate_functions/prop_test_two_aggregate.cpp
src/aggregate_functions/binom_test_aggregate.cpp
src/aggregate_functions/cramers_v_aggregate.cpp
src/aggregate_functions/cohen_kappa_aggregate.cpp
src/aggregate_functions/icc_aggregate.cpp
src/aggregate_functions/g_test_aggregate.cpp
src/aggregate_functions/mcnemar_aggregate.cpp
src/aggregate_functions/phi_coefficient_aggregate.cpp
src/aggregate_functions/contingency_coef_aggregate.cpp
src/aggregate_functions/pls_fit_predict_aggregate.cpp
src/aggregate_functions/isotonic_fit_predict_aggregate.cpp
src/aggregate_functions/quantile_fit_predict_aggregate.cpp
src/scalar_functions/vif.cpp
src/scalar_functions/aic_bic.cpp
src/scalar_functions/jarque_bera.cpp
src/scalar_functions/residuals_diagnostics.cpp
src/window_functions/ols_fit_predict.cpp
src/window_functions/huber_fit_predict.cpp
src/window_functions/ransac_fit_predict.cpp
src/window_functions/theil_sen_fit_predict.cpp
src/window_functions/ridge_fit_predict.cpp
src/window_functions/wls_fit_predict.cpp
src/window_functions/rls_fit_predict.cpp
src/window_functions/elasticnet_fit_predict.cpp
src/macros/fit_predict_macros.cpp
)
# Build static extension
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
# Build loadable extension
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
# Link to Rust library
target_link_libraries(${EXTENSION_NAME} anofox_stats_ffi-static datazoo_banner)
target_link_libraries(${LOADABLE_EXTENSION_NAME} anofox_stats_ffi-static datazoo_banner)
# Telemetry header is always needed (provides no-op stubs when telemetry is disabled)
target_include_directories(${EXTENSION_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/posthog-telemetry/include)
target_include_directories(${LOADABLE_EXTENSION_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/posthog-telemetry/include)
# Add telemetry objects and OpenSSL linking (when available)
if(ANOFOX_TELEMETRY_ENABLED)
target_sources(${EXTENSION_NAME} PRIVATE $<TARGET_OBJECTS:posthog_telemetry_obj>)
target_sources(${LOADABLE_EXTENSION_NAME} PRIVATE $<TARGET_OBJECTS:posthog_telemetry_obj>)
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
target_compile_definitions(${EXTENSION_NAME} PRIVATE ANOFOX_TELEMETRY_ENABLED)
target_compile_definitions(${LOADABLE_EXTENSION_NAME} PRIVATE ANOFOX_TELEMETRY_ENABLED)
# posthog-telemetry reads the machine id from the IORegistry on macOS
# (IORegistryEntryFromPath et al.), which requires linking IOKit explicitly.
if(APPLE)
target_link_libraries(${EXTENSION_NAME} "-framework IOKit" "-framework CoreFoundation")
target_link_libraries(${LOADABLE_EXTENSION_NAME} "-framework IOKit" "-framework CoreFoundation")
endif()
else()
# Since posthog-telemetry consolidated on main (DataZooDE/posthog-telemetry#5),
# the header's no-op stubs are opt-out: POSTHOG_TELEMETRY_DISABLED turns every
# telemetry call into an inline no-op (the old header keyed on the absence of
# ANOFOX_TELEMETRY_ENABLED instead).
target_compile_definitions(${EXTENSION_NAME} PRIVATE POSTHOG_TELEMETRY_DISABLED)
target_compile_definitions(${LOADABLE_EXTENSION_NAME} PRIVATE POSTHOG_TELEMETRY_DISABLED)
endif()
# Link Windows system libraries
if(WIN32)
# bcrypt: required by Rust's getrandom crate
target_link_libraries(${EXTENSION_NAME} bcrypt)
target_link_libraries(${LOADABLE_EXTENSION_NAME} bcrypt)
if(ANOFOX_TELEMETRY_ENABLED)
# iphlpapi: required by telemetry GetAdaptersInfo
target_link_libraries(${EXTENSION_NAME} iphlpapi)
target_link_libraries(${LOADABLE_EXTENSION_NAME} iphlpapi)
endif()
endif()
# Install
install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
)