2022-12-14 10:51:12 +00:00
# NOTE: should be macro to export RUST_CXXFLAGS/RUST_CFLAGS for subfolders
macro ( configure_rustc )
2022-12-07 12:14:24 +00:00
# NOTE: this can also be done by overriding rustc, but it not trivial with rustup.
set ( RUST_CFLAGS "${CMAKE_C_FLAGS}" )
set ( CXX_INCLUDE_DIR "${ClickHouse_SOURCE_DIR}/contrib/llvm-project/libcxx/include" )
2022-12-14 10:51:12 +00:00
set ( RUST_CXXFLAGS "${CMAKE_CXX_FLAGS} -isystem ${CXX_INCLUDE_DIR} -nostdinc++" )
2022-12-07 12:14:24 +00:00
if ( CMAKE_OSX_SYSROOT )
set ( RUST_CXXFLAGS "${RUST_CXXFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}" )
set ( RUST_CFLAGS "${RUST_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}" )
elseif ( CMAKE_SYSROOT )
set ( RUST_CXXFLAGS "${RUST_CXXFLAGS} --sysroot ${CMAKE_SYSROOT}" )
set ( RUST_CFLAGS "${RUST_CFLAGS} --sysroot ${CMAKE_SYSROOT}" )
endif ( )
2024-02-11 09:42:36 +00:00
if ( CMAKE_OSX_DEPLOYMENT_TARGET )
set ( RUST_CXXFLAGS "${RUST_CXXFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}" )
set ( RUST_CFLAGS "${RUST_CFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}" )
endif ( )
2023-12-11 19:48:48 +00:00
if ( USE_MUSL )
set ( RUST_CXXFLAGS "${RUST_CXXFLAGS} -D_LIBCPP_HAS_MUSL_LIBC=1" )
endif ( )
2023-08-10 14:17:00 +00:00
if ( CCACHE_EXECUTABLE MATCHES "/sccache$" )
message ( STATUS "Using RUSTC_WRAPPER: ${CCACHE_EXECUTABLE}" )
set ( RUSTCWRAPPER "rustc-wrapper = \" ${ CCACHE_EXECUTABLE } \"")
else ( )
set ( RUSTCWRAPPER "" )
endif ( )
2024-02-11 09:42:36 +00:00
set ( RUSTFLAGS )
if ( CMAKE_OSX_DEPLOYMENT_TARGET )
list ( APPEND RUSTFLAGS "-C" "link-arg=-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}" )
endif ( )
2023-06-03 19:31:43 +00:00
set ( RUST_CARGO_BUILD_STD "" )
# For more info: https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html#memorysanitizer
if ( SANITIZE STREQUAL "memory" )
set ( RUST_CARGO_BUILD_STD "build-std = [\" std\ ", \" panic_abort\ ", \" core\ ", \" alloc\ "]" )
2024-02-11 09:42:36 +00:00
list ( APPEND RUSTFLAGS "-Zsanitizer=memory" "-Zsanitizer-memory-track-origins" )
2023-06-03 19:31:43 +00:00
endif ( )
2024-02-11 09:42:36 +00:00
list ( TRANSFORM RUSTFLAGS PREPEND "\" " )
list ( TRANSFORM RUSTFLAGS APPEND "\" " )
list ( JOIN RUSTFLAGS "," RUSTFLAGS )
set ( RUSTFLAGS "[${RUSTFLAGS}]" )
2022-12-07 12:14:24 +00:00
message ( STATUS "RUST_CFLAGS: ${RUST_CFLAGS}" )
message ( STATUS "RUST_CXXFLAGS: ${RUST_CXXFLAGS}" )
2023-06-03 19:31:43 +00:00
message ( STATUS "RUSTFLAGS: ${RUSTFLAGS}" )
message ( STATUS "RUST_CARGO_BUILD_STD: ${RUST_CARGO_BUILD_STD}" )
2022-12-07 12:14:24 +00:00
# NOTE: requires RW access for the source dir
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml.in" "${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml" @ONLY )
2022-12-14 10:51:12 +00:00
endmacro ( )
2022-12-07 12:14:24 +00:00
configure_rustc ( )
2022-12-14 10:51:46 +00:00
function ( clickhouse_import_crate )
# This is a workaround for Corrosion case sensitive build type matching in
# _generator_add_cargo_targets(), that leads to different paths in
# IMPORTED_LOCATION and real path of the library.
#
# It uses CMAKE_CONFIGURATION_TYPES and $<CONFIG>, so here we preserve the
# case of ${CMAKE_BUILD_TYPE} in ${CMAKE_CONFIGURATION_TYPES}.
if ( "${CMAKE_BUILD_TYPE_UC}" STREQUAL "DEBUG" )
set ( CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE};release" )
else ( )
set ( CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE};debug" )
endif ( )
Improve performance of BLAKE3 by 11% by enabling LTO for Rust
LTO in Rust produces multiple definition of `rust_eh_personality' (and
few others), and to overcome this --allow-multiple-definition has been
added.
Query for benchmark:
SELECT ignore(BLAKE3(materialize('Lorem ipsum dolor sit amet, consectetur adipiscing elit'))) FROM numbers(1000000000) FORMAT `Null`
upstream : Elapsed: 2.494 sec. Processed 31.13 million rows, 249.08 MB (12.48 million rows/s., 99.86 MB/s.)
upstream + rust lto: Elapsed: 13.56 sec. Processed 191.9 million rows, 1.5400 GB (14.15 million rows/s., 113.22 MB/s.)
llvm BLAKE3 : Elapsed: 3.053 sec. Processed 43.24 million rows, 345.88 MB (14.16 million rows/s., 113.28 MB/s.)
Note, I thought about simply replacing it with BLAKE3 from LLVM, but:
- this will not solve LTO issues for Rust (and in future more libraries
could be added)
- it makes integrating_rust_libraries.md useless (and there is even blog
post)
So instead I've decided to add this quirk (--allow-multiple-definition)
to fix builds.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-05-06 16:54:56 +00:00
if ( CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG" )
set ( profile "" )
else ( )
if ( ENABLE_THINLTO )
set ( profile "release-thinlto" )
else ( )
set ( profile "release" )
endif ( )
endif ( )
2023-07-21 06:31:45 +00:00
# Note, here --offline is not used, since on CI vendor archive is used, and
# passing --offline here will be inconvenient for local development.
Improve performance of BLAKE3 by 11% by enabling LTO for Rust
LTO in Rust produces multiple definition of `rust_eh_personality' (and
few others), and to overcome this --allow-multiple-definition has been
added.
Query for benchmark:
SELECT ignore(BLAKE3(materialize('Lorem ipsum dolor sit amet, consectetur adipiscing elit'))) FROM numbers(1000000000) FORMAT `Null`
upstream : Elapsed: 2.494 sec. Processed 31.13 million rows, 249.08 MB (12.48 million rows/s., 99.86 MB/s.)
upstream + rust lto: Elapsed: 13.56 sec. Processed 191.9 million rows, 1.5400 GB (14.15 million rows/s., 113.22 MB/s.)
llvm BLAKE3 : Elapsed: 3.053 sec. Processed 43.24 million rows, 345.88 MB (14.16 million rows/s., 113.28 MB/s.)
Note, I thought about simply replacing it with BLAKE3 from LLVM, but:
- this will not solve LTO issues for Rust (and in future more libraries
could be added)
- it makes integrating_rust_libraries.md useless (and there is even blog
post)
So instead I've decided to add this quirk (--allow-multiple-definition)
to fix builds.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-05-06 16:54:56 +00:00
corrosion_import_crate ( NO_STD ${ ARGN } PROFILE ${ profile } )
2022-12-14 10:51:46 +00:00
endfunction ( )
2022-12-30 16:58:18 +00:00
# Add crate from the build directory.
#
# Our crates has configuration files:
# - config for cargo (see config.toml.in)
# - and possibly config for build (build.rs.in)
#
# And to avoid overlaps different builds for one source directory, crate will
# be copied from source directory to the binary directory.
file ( COPY ".cargo" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" )
function ( add_rust_subdirectory src )
set ( dst "${CMAKE_CURRENT_BINARY_DIR}/${src}" )
message ( STATUS "Copy ${src} to ${dst}" )
2023-02-02 17:04:40 +00:00
file ( COPY "${src}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
P A T T E R N t a r g e t E X C L U D E )
2024-03-26 13:47:01 +00:00
# Check is Rust available or not.
#
# `cargo update --dry-run` will not update anything, but will check the internet connectivity.
execute_process ( COMMAND ${ Rust_CARGO_CACHED } update --dry-run
W O R K I N G _ D I R E C T O R Y " $ { d s t } "
R E S U L T _ V A R I A B L E C A R G O _ U P D A T E _ R E S U L T
O U T P U T _ V A R I A B L E C A R G O _ U P D A T E _ S T D O U T
E R R O R _ V A R I A B L E C A R G O _ U P D A T E _ S T D E R R )
if ( CARGO_UPDATE_RESULT )
message ( FATAL_ERROR "Rust (${Rust_CARGO_CACHED}) support is not available (likely there is no internet connectivity):\n${CARGO_UPDATE_STDERR}\nYou can disable Rust support with -DENABLE_RUST=OFF" )
endif ( )
2022-12-30 16:58:18 +00:00
add_subdirectory ( "${dst}" "${dst}" )
2023-02-02 17:04:40 +00:00
# cmake -E copy* do now know how to exclude files
# but we need to exclude "target" folder from copying, if someone or semantic
# completion created it.
add_custom_target ( ${ src } -update ALL
C O M M A N D $ { C M A K E _ C O M M A N D }
- D F R O M = $ { s r c }
- D T O = $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
- P " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o p y _ e x c l u d e . c m a k e "
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
V E R B A T I M )
2022-12-30 16:58:18 +00:00
endfunction ( )
add_rust_subdirectory ( skim )
2023-07-20 10:54:42 +00:00
add_rust_subdirectory ( prql )