diff --git a/CMakeLists.txt b/CMakeLists.txt index e9656509..cfdaeaeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,31 @@ -cmake_minimum_required(VERSION 3.17) +cmake_minimum_required(VERSION 3.10) project(cppdriverv2 C CXX) set(CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(CASS_SRC_DIR "${CASS_ROOT_DIR}/src") set(CASS_INCLUDE_DIR "${CASS_ROOT_DIR}/include") +# Ensure functions/modules are available +list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake) + +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +enable_language(Rust) +include(CMakeCargo) + +#--------------- +# Policies +#--------------- + +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() + +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif() + #--------------- # Options #--------------- @@ -12,12 +33,13 @@ set(CASS_INCLUDE_DIR "${CASS_ROOT_DIR}/include") option(CASS_BUILD_EXAMPLES "Build examples" OFF) option(CASS_BUILD_INTEGRATION_TESTS "Build integration tests" OFF) option(CASS_BUILD_SHARED "Build shared library" ON) -option(CASS_BUILD_STATIC "Build static library" OFF) +option(CASS_BUILD_STATIC "Build static library" ON) option(CASS_BUILD_TESTS "Build tests" OFF) +option(CASS_BUILD_UNIT_TESTS "Build unit tests" OFF) option(CASS_DEBUG_CUSTOM_ALLOC "Debug custom allocator" OFF) -option(CASS_INSTALL_HEADER "Install header file" OFF) +option(CASS_INSTALL_HEADER "Install header file" ON) option(CASS_INSTALL_HEADER_IN_SUBDIR "Install header file under 'include/cassandra'" OFF) -option(CASS_INSTALL_PKG_CONFIG "Install pkg-config file(s)" OFF) +option(CASS_INSTALL_PKG_CONFIG "Install pkg-config file(s)" ON) option(CASS_MULTICORE_COMPILATION "Enable multicore compilation" ON) option(CASS_USE_BOOST_ATOMIC "Use Boost atomics library" OFF) option(CASS_USE_KERBEROS "Use Kerberos" OFF) @@ -25,243 +47,191 @@ option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" OFF) option(CASS_USE_OPENSSL "Use OpenSSL" ON) option(CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF) option(CASS_USE_STD_ATOMIC "Use std::atomic library" ON) -option(CASS_USE_ZLIB "Use zlib" ON) +option(CASS_USE_ZLIB "Use zlib" OFF) option(CASS_USE_TIMERFD "Use timerfd (Linux only)" ON) +option(CASS_USE_LIBUV "Use libuv" OFF) set(CASS_CPP_STANDARD "11" CACHE STRING "C++ standard (11, 14, 17, etc.)") -if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_TESTS) +if(CASS_BUILD_SHARED) + set(BUILD_SHARED_LIBS ON) +endif() +# Handle testing dependencies +if(CASS_BUILD_TESTS) + # Enable integration and unit tests + set(CASS_BUILD_INTEGRATION_TESTS ON) + set(CASS_BUILD_UNIT_TESTS ON) +endif() + +if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS) set(CASS_USE_OPENSSL ON) # Required for tests set(CASS_USE_KERBEROS ON) # Required for tests + set(CASS_USE_LIBUV ON) +endif() -# Ensure functions/modules are available - list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake) +# Determine which driver target should be used as a dependency +set(PROJECT_LIB_NAME_TARGET scylla-cpp-driver) +if(CASS_USE_STATIC_LIBS OR + (WIN32 AND (CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS))) + set(CASS_USE_STATIC_LIBS ON) # Not all driver internals are exported for test executable (e.g. CASS_EXPORT) + set(CASS_BUILD_STATIC ON) + set(PROJECT_LIB_NAME_TARGET scylla-cpp-driver_static) +endif() - set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Ensure the driver is configured to build +if(NOT CASS_BUILD_SHARED AND NOT CASS_BUILD_STATIC) + message(FATAL_ERROR "Driver is not Configured to Build: Ensure shared and/or static library is enabled") +endif() -#--------------- -# Policies -#--------------- +if(CASS_DEBUG_CUSTOM_ALLOC AND CASS_USE_STATIC_LIBS) + message(WARNING "Debugging the custom allocator while static linking the library can cause your application to fail") +endif() - if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) - endif() +#------------------------ +# Dependencies +#------------------------ - if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) - endif() +include(Dependencies) +include(ClangFormat) - # Determine which driver target should be used as a dependency - set(PROJECT_LIB_NAME_TARGET scylla-cpp-driver) - if(CASS_USE_STATIC_LIBS) - set(CASS_USE_STATIC_LIBS ON) # Not all driver internals are exported for test executable (e.g. CASS_EXPORT) - set(CASS_BUILD_STATIC ON) - set(PROJECT_LIB_NAME_TARGET scylla-cpp-driver_static) - endif() +#------------------------ +# Project Version +#------------------------ - # Ensure the driver is configured to build - if(NOT CASS_BUILD_SHARED AND NOT CASS_BUILD_STATIC) - message(FATAL_ERROR "Driver is not Configured to Build: Ensure shared and/or static library is enabled") - endif() +file(STRINGS "${CASS_INCLUDE_DIR}/cassandra.h" _VERSION_PARTS + REGEX "^#define[ \t]+CASS_VERSION_(MAJOR|MINOR|PATCH|SUFFIX)[ \t]+([0-9]+|\"([^\"]+)\")$") - if(CASS_DEBUG_CUSTOM_ALLOC AND CASS_USE_STATIC_LIBS) - message(WARNING "Debugging the custom allocator while static linking the library can cause your application to fail") +foreach(part MAJOR MINOR PATCH SUFFIX) + string(REGEX MATCH "CASS_VERSION_${part}[ \t]+([0-9]+|\"([^\"]+)\")" + PROJECT_VERSION_${part} ${_VERSION_PARTS}) + # Extract version numbers + if (PROJECT_VERSION_${part}) + string(REGEX REPLACE "CASS_VERSION_${part}[ \t]+([0-9]+|\"([^\"]+)\")" "\\1" + PROJECT_VERSION_${part} ${PROJECT_VERSION_${part}}) endif() +endforeach() - #------------------------ - # Dependencies - #------------------------ - - include(Dependencies) - include(ClangFormat) - - #------------------------ - # Project Version - #------------------------ - - file(STRINGS "${CASS_INCLUDE_DIR}/cassandra.h" _VERSION_PARTS - REGEX "^#define[ \t]+CASS_VERSION_(MAJOR|MINOR|PATCH|SUFFIX)[ \t]+([0-9]+|\"([^\"]+)\")$") - - foreach(part MAJOR MINOR PATCH SUFFIX) - string(REGEX MATCH "CASS_VERSION_${part}[ \t]+([0-9]+|\"([^\"]+)\")" - PROJECT_VERSION_${part} ${_VERSION_PARTS}) - # Extract version numbers - if (PROJECT_VERSION_${part}) - string(REGEX REPLACE "CASS_VERSION_${part}[ \t]+([0-9]+|\"([^\"]+)\")" "\\1" - PROJECT_VERSION_${part} ${PROJECT_VERSION_${part}}) - endif() - endforeach() - - # Verify version parts - if(NOT PROJECT_VERSION_MAJOR AND NOT PROJECT_VERSION_MINOR) - message(FATAL_ERROR "Unable to retrieve driver version from ${version_header_file}") - endif() +# Verify version parts +if(NOT PROJECT_VERSION_MAJOR AND NOT PROJECT_VERSION_MINOR) + message(FATAL_ERROR "Unable to retrieve driver version from ${version_header_file}") +endif() +set(PROJECT_VERSION_STRING + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) +if(NOT PROJECT_VERSION_PATCH STREQUAL "") set(PROJECT_VERSION_STRING - ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) - if(NOT PROJECT_VERSION_PATCH STREQUAL "") - set(PROJECT_VERSION_STRING - "${PROJECT_VERSION_STRING}.${PROJECT_VERSION_PATCH}") - endif() - if(NOT PROJECT_VERSION_SUFFIX STREQUAL "") - string(REPLACE "\"" "" - PROJECT_VERSION_SUFFIX ${PROJECT_VERSION_SUFFIX}) - set(PROJECT_VERSION_STRING - "${PROJECT_VERSION_STRING}-${PROJECT_VERSION_SUFFIX}") - endif() + "${PROJECT_VERSION_STRING}.${PROJECT_VERSION_PATCH}") +endif() +if(NOT PROJECT_VERSION_SUFFIX STREQUAL "") + string(REPLACE "\"" "" + PROJECT_VERSION_SUFFIX ${PROJECT_VERSION_SUFFIX}) + set(PROJECT_VERSION_STRING + "${PROJECT_VERSION_STRING}-${PROJECT_VERSION_SUFFIX}") +endif() - message(STATUS "Driver version: ${PROJECT_VERSION_STRING}") +message(STATUS "Driver version: ${PROJECT_VERSION_STRING}") - #------------------------ - # Determine atomic implementation - #------------------------ +#------------------------ +# Determine atomic implementation +#------------------------ - # Determine if std::atomic can be used for GCC, Clang, or MSVC - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - # Version determined from: https://gcc.gnu.org/wiki/Atomic/GCCMM - if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.7" OR - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7") - set(CASS_USE_STD_ATOMIC ON) - endif() - endif() - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") - # Version determined from: http://clang.llvm.org/cxx_status.html - # 3.2 includes the full C++11 memory model, but 3.1 had atomic - # support. - if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "3.1" OR - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "3.1") - set(CASS_USE_STD_ATOMIC ON) - endif() - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - # Version determined from https://msdn.microsoft.com/en-us/library/hh874894 - # VS2012+/VS 11.0+/WindowsSDK v8.0+ - if(MSVC_VERSION GREATER 1700 OR - MSVC_VERSION EQUAL 1700) +# Determine if std::atomic can be used for GCC, Clang, or MSVC +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + # Version determined from: https://gcc.gnu.org/wiki/Atomic/GCCMM + if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.7" OR + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7") set(CASS_USE_STD_ATOMIC ON) endif() endif() - - if(CASS_USE_BOOST_ATOMIC) - message(STATUS "Using boost::atomic implementation for atomic operations") - elseif(CASS_USE_STD_ATOMIC) - message(STATUS "Using std::atomic implementation for atomic operations") +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + # Version determined from: http://clang.llvm.org/cxx_status.html + # 3.2 includes the full C++11 memory model, but 3.1 had atomic + # support. + if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "3.1" OR + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "3.1") + set(CASS_USE_STD_ATOMIC ON) endif() +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # Version determined from https://msdn.microsoft.com/en-us/library/hh874894 + # VS2012+/VS 11.0+/WindowsSDK v8.0+ + if(MSVC_VERSION GREATER 1700 OR + MSVC_VERSION EQUAL 1700) + set(CASS_USE_STD_ATOMIC ON) + endif() +endif() - #------------------------ - # Top-level compiler flags - #------------------------ +if(CASS_USE_BOOST_ATOMIC) + message(STATUS "Using boost::atomic implementation for atomic operations") +elseif(CASS_USE_STD_ATOMIC) + message(STATUS "Using std::atomic implementation for atomic operations") +endif() - set (CMAKE_CXX_STANDARD ${CASS_CPP_STANDARD}) +#------------------------ +# Top-level compiler flags +#------------------------ - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +set (CMAKE_CXX_STANDARD ${CASS_CPP_STANDARD}) - # OpenSSL is deprecated on later versions of Mac OS X. The long-term solution - # is to provide a CommonCryto implementation. - if (APPLE AND CASS_USE_OPENSSL) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") - endif() +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") - # Clang/Intel specific compiler options - # I disabled long-long warning because boost generates about 50 such warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros -Wno-zero-length-array") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef -Wno-unknown-warning-option") - else() - # GCC specific compiler options - # I disabled long-long warning because boost generates about 50 such warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter -Wno-variadic-macros") - - if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.8" OR - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") - endif() - endif() - elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - add_definitions(/we4800) + # OpenSSL is deprecated on later versions of Mac OS X. The long-term solution + # is to provide a CommonCryto implementation. + if (APPLE AND CASS_USE_OPENSSL) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") + endif() - # Determine if multicore compilation should be enabled - if(CASS_MULTICORE_COMPILATION) - # Default multicore compilation with effective processors (see https://msdn.microsoft.com/en-us/library/bb385193.aspx) - add_definitions("/MP") + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + # Clang/Intel specific compiler options + # I disabled long-long warning because boost generates about 50 such warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros -Wno-zero-length-array") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef -Wno-unknown-warning-option") + else() + # GCC specific compiler options + # I disabled long-long warning because boost generates about 50 such warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter -Wno-variadic-macros") + + if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.8" OR + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") endif() + endif() +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + add_definitions(/we4800) - # On Visual C++ -pedantic flag is not used, - # -fPIC is not used on Windows platform (all DLLs are - # relocable), -Wall generates about 30k stupid warnings - # that can hide useful ones. - # Create specific warning disable compiler flags - # TODO(mpenick): Fix these "possible loss of data" warnings - add_definitions(/wd4244) - add_definitions(/wd4267) - - # Add preprocessor definitions for proper compilation - add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Remove warnings for not using safe functions (TODO: Fix codebase to be more secure for Visual Studio) - add_definitions(-DNOMINMAX) # Does not define min/max macros - add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) # Remove warnings for TR1 deprecation (Visual Studio 15 2017); caused by sparsehash - else() - message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") + # Determine if multicore compilation should be enabled + if(CASS_MULTICORE_COMPILATION) + # Default multicore compilation with effective processors (see https://msdn.microsoft.com/en-us/library/bb385193.aspx) + add_definitions("/MP") endif() + + # On Visual C++ -pedantic flag is not used, + # -fPIC is not used on Windows platform (all DLLs are + # relocable), -Wall generates about 30k stupid warnings + # that can hide useful ones. + # Create specific warning disable compiler flags + # TODO(mpenick): Fix these "possible loss of data" warnings + add_definitions(/wd4244) + add_definitions(/wd4267) + + # Add preprocessor definitions for proper compilation + add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Remove warnings for not using safe functions (TODO: Fix codebase to be more secure for Visual Studio) + add_definitions(-DNOMINMAX) # Does not define min/max macros + add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) # Remove warnings for TR1 deprecation (Visual Studio 15 2017); caused by sparsehash +else() + message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") endif() #------------------------ -# Actual project & subdirectories +# Subdirectories #------------------------ -# Enable ExternalProject CMake module -include(ExternalProject) - -# Set default ExternalProject root directory -set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/Rust) - -# Set a default build type if none was specified -set(default_build_type "Release") -if(EXISTS "${CMAKE_SOURCE_DIR}/.git") - set(default_build_type "Debug") -endif() - -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${default_build_type}' as none was specified.") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() - -# Add rust_example as a CMake target -ExternalProject_Add( - scylla-rust-cpp-driver - DOWNLOAD_COMMAND "" - CONFIGURE_COMMAND "" - BUILD_COMMAND cargo build $,,--release> - BINARY_DIR "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper" - INSTALL_COMMAND "" - LOG_BUILD ON - BUILD_ALWAYS TRUE) - -add_library(scylla-cpp-driver SHARED IMPORTED) -set_target_properties(scylla-cpp-driver PROPERTIES IMPORTED_NO_SONAME TRUE) -set_property(TARGET scylla-cpp-driver APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) -set_target_properties(scylla-cpp-driver PROPERTIES - IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/debug/libscylla_cpp_driver.so" -) -set_property(TARGET scylla-cpp-driver APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) -set_target_properties(scylla-cpp-driver PROPERTIES - IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/release/libscylla_cpp_driver.so" -) -set_target_properties(scylla-cpp-driver PROPERTIES - MAP_IMPORTED_CONFIG_MINSIZEREL Release - MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release -) -add_dependencies(scylla-cpp-driver scylla-rust-cpp-driver) -target_include_directories(scylla-cpp-driver INTERFACE "${CMAKE_SOURCE_DIR}/include") +add_subdirectory(scylla-rust-wrapper) add_subdirectory(src) @@ -271,4 +241,4 @@ endif() if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_TESTS) add_subdirectory(tests) -endif() \ No newline at end of file +endif() diff --git a/README.md b/README.md index d114d628..860a9c8c 100644 --- a/README.md +++ b/README.md @@ -343,12 +343,24 @@ To build deb package, run the following command: It will construct chrooted build environment of target distribution using pbuilder, and build deb in the environment. Target parameter should be debian/ubuntu codename. -On Ubuntu targets, currently tested on focal (20.04), jammy (22.04), mantic (23.10), noble (24.04). +On Ubuntu targets, currently tested on bionic (18.04), focal (20.04), jammy (22.04), mantic (23.10), noble (24.04). On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable). Build environment should be Fedora, Ubuntu or Debian, since these distribution provides pbuilder package. Built result will placed under build/debian/debs. +# Build & install HomeBrew package (macOS) + +--- + +To build HomeBrew pacakge, run the following command: +```shell +cd dist/homebrew +brew install --HEAD ./scylla-cpp-rust-driver.rb +``` +It will run build & install the driver in HomeBrew environment. +Tested on macOS 14.5. + # Getting Help ___ diff --git a/cmake/CMakeCargo.cmake b/cmake/CMakeCargo.cmake new file mode 100644 index 00000000..e42faf72 --- /dev/null +++ b/cmake/CMakeCargo.cmake @@ -0,0 +1,94 @@ +function(cargo_build) + cmake_parse_arguments(CARGO "" "NAME" "" ${ARGN}) + string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME}) + + set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}) + + if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(LIB_TARGET "x86_64-pc-windows-msvc") + else() + set(LIB_TARGET "i686-pc-windows-msvc") + endif() + elseif(ANDROID) + if(ANDROID_SYSROOT_ABI STREQUAL "x86") + set(LIB_TARGET "i686-linux-android") + elseif(ANDROID_SYSROOT_ABI STREQUAL "x86_64") + set(LIB_TARGET "x86_64-linux-android") + elseif(ANDROID_SYSROOT_ABI STREQUAL "arm") + set(LIB_TARGET "arm-linux-androideabi") + elseif(ANDROID_SYSROOT_ABI STREQUAL "arm64") + set(LIB_TARGET "aarch64-linux-android") + endif() + elseif(IOS) + set(LIB_TARGET "universal") + elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + set(LIB_TARGET "aarch64-apple-darwin") + else() + set(LIB_TARGET "${CMAKE_SYSTEM_PROCESSOR}-apple-darwin") + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(LIB_TARGET "${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu") + else() + set(LIB_TARGET "i686-unknown-linux-gnu") + endif() + else() + message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is unknown system") + endif() + + if(NOT CMAKE_BUILD_TYPE) + set(LIB_BUILD_TYPE "debug") + elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") + set(LIB_BUILD_TYPE "release") + elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + set(LIB_BUILD_TYPE "relwithdebinfo") + else() + set(LIB_BUILD_TYPE "debug") + endif() + + set(LIB_FILE "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") + if(BUILD_SHARED_LIBS) + set(LIB_FILE_SHARED "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") + endif() + + if(IOS) + set(CARGO_ARGS "lipo") + else() + set(CARGO_ARGS "build") + list(APPEND CARGO_ARGS "--target" ${LIB_TARGET}) + if (CMAKE_VERBOSE_MAKEFILE) + list(APPEND CARGO_ARGS "--verbose") + endif() + endif() + + if(${LIB_BUILD_TYPE} STREQUAL "release") + list(APPEND CARGO_ARGS "--release") + elseif(${LIB_BUILD_TYPE} STREQUAL "relwithdebinfo") + list(APPEND CARGO_ARGS "--profile" "relwithdebinfo") + elseif(${LIB_BUILD_TYPE} STREQUAL "debug") + list(APPEND CARGO_CARGS "--profile" "dev") + endif() + + file(GLOB_RECURSE LIB_SOURCES "*.rs") + + set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" "RUSTFLAGS=${CMAKE_Rust_FLAGS}") + + add_custom_command( + OUTPUT ${LIB_FILE} ${LIB_FILE_SHARED} + COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${LIB_SOURCES} + COMMENT "running cargo") + add_custom_target(${CARGO_NAME}_target ALL DEPENDS ${LIB_FILE}) + add_library(${CARGO_NAME} STATIC IMPORTED GLOBAL) + add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target) + set_target_properties(${CARGO_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_FILE}) + if(BUILD_SHARED_LIBS) + add_custom_target(${CARGO_NAME}_shared_target ALL DEPENDS ${LIB_FILE_SHARED}) + add_library(${CARGO_NAME}_shared SHARED IMPORTED GLOBAL) + add_dependencies(${CARGO_NAME}_shared ${CARGO_NAME}_shared_target) + set_target_properties(${CARGO_NAME}_shared PROPERTIES IMPORTED_LOCATION ${LIB_FILE_SHARED}) + endif() +endfunction() diff --git a/cmake/CMakeDetermineRustCompiler.cmake b/cmake/CMakeDetermineRustCompiler.cmake new file mode 100644 index 00000000..6d481529 --- /dev/null +++ b/cmake/CMakeDetermineRustCompiler.cmake @@ -0,0 +1,25 @@ + +if(NOT CMAKE_Rust_COMPILER) + find_package(Rust) + if(RUST_FOUND) + set(CMAKE_Rust_COMPILER "${RUSTC_EXECUTABLE}") + set(CMAKE_Rust_COMPILER_ID "Rust") + set(CMAKE_Rust_COMPILER_VERSION "${RUST_VERSION}") + set(CMAKE_Rust_PLATFORM_ID "Rust") + endif() +endif() + +message(STATUS "Cargo Home: ${CARGO_HOME}") +message(STATUS "Rust Compiler Version: ${RUSTC_VERSION}") + +mark_as_advanced(CMAKE_Rust_COMPILER) + +if(CMAKE_Rust_COMPILER) + set(CMAKE_Rust_COMPILER_LOADED 1) +endif(CMAKE_Rust_COMPILER) + +configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeRustCompiler.cmake.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakeRustCompiler.cmake IMMEDIATE @ONLY) + +set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC") + diff --git a/cmake/CMakeRust-LICENSE-APACHE b/cmake/CMakeRust-LICENSE-APACHE new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/cmake/CMakeRust-LICENSE-APACHE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/cmake/CMakeRust-LICENSE-MIT b/cmake/CMakeRust-LICENSE-MIT new file mode 100644 index 00000000..31aa7938 --- /dev/null +++ b/cmake/CMakeRust-LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/cmake/CMakeRustCompiler.cmake.in b/cmake/CMakeRustCompiler.cmake.in new file mode 100644 index 00000000..5916c1c3 --- /dev/null +++ b/cmake/CMakeRustCompiler.cmake.in @@ -0,0 +1,15 @@ + +set(CMAKE_Rust_COMPILER "@CMAKE_Rust_COMPILER@") +set(CMAKE_Rust_COMPILER_ID "@CMAKE_Rust_COMPILER_ID@") +set(CMAKE_Rust_COMPILER_VERSION "@CMAKE_Rust_COMPILER_VERSION@") +set(CMAKE_Rust_COMPILER_LOADED @CMAKE_Rust_COMPILER_LOADED@) +set(CMAKE_Rust_PLATFORM_ID "@CMAKE_Rust_PLATFORM_ID@") + +SET(CMAKE_Rust_SOURCE_FILE_EXTENSIONS rs) +SET(CMAKE_Rust_LINKER_PREFERENCE 40) +#SET(CMAKE_Rust_OUTPUT_EXTENSION_REPLACE 1) +SET(CMAKE_STATIC_LIBRARY_PREFIX_Rust "") +SET(CMAKE_STATIC_LIBRARY_SUFFIX_Rust .a) + +set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC") + diff --git a/cmake/CMakeRustInformation.cmake b/cmake/CMakeRustInformation.cmake new file mode 100644 index 00000000..05d96c94 --- /dev/null +++ b/cmake/CMakeRustInformation.cmake @@ -0,0 +1,106 @@ + +# +# Usage: rustc [OPTIONS] INPUT +# +# Options: +# -h --help Display this message +# --cfg SPEC Configure the compilation environment +# -L [KIND=]PATH Add a directory to the library search path. The +# optional KIND can be one of dependency, crate, native, +# framework or all (the default). +# -l [KIND=]NAME Link the generated crate(s) to the specified native +# library NAME. The optional KIND can be one of static, +# dylib, or framework. If omitted, dylib is assumed. +# --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|metadata] +# Comma separated list of types of crates for the +# compiler to emit +# --crate-name NAME Specify the name of the crate being built +# --emit [asm|llvm-bc|llvm-ir|obj|link|dep-info] +# Comma separated list of types of output for the +# compiler to emit +# --print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|target-features|relocation-models|code-models] +# Comma separated list of compiler information to print +# on stdout +# -g Equivalent to -C debuginfo=2 +# -O Equivalent to -C opt-level=2 +# -o FILENAME Write output to +# --out-dir DIR Write output to compiler-chosen filename in +# --explain OPT Provide a detailed explanation of an error message +# --test Build a test harness +# --target TARGET Target triple for which the code is compiled +# -W --warn OPT Set lint warnings +# -A --allow OPT Set lint allowed +# -D --deny OPT Set lint denied +# -F --forbid OPT Set lint forbidden +# --cap-lints LEVEL Set the most restrictive lint level. More restrictive +# lints are capped at this level +# -C --codegen OPT[=VALUE] +# Set a codegen option +# -V --version Print version info and exit +# -v --verbose Use verbose output +# +# Additional help: +# -C help Print codegen options +# -W help Print 'lint' options and default settings +# -Z help Print internal options for debugging rustc +# --help -v Print the full set of options rustc accepts +# + +# + +include(CMakeLanguageInformation) + +if(UNIX) + set(CMAKE_Rust_OUTPUT_EXTENSION .o) +else() + set(CMAKE_Rust_OUTPUT_EXTENSION .obj) +endif() + +set(CMAKE_Rust_ECHO_ALL "echo \"TARGET: TARGET_BASE: ") +set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} OBJECT: OBJECTS: OBJECT_DIR: SOURCE: SOURCES: ") +set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} LINK_LIBRARIES: FLAGS: LINK_FLAGS: \"") + +if(NOT CMAKE_Rust_CREATE_SHARED_LIBRARY) + set(CMAKE_Rust_CREATE_SHARED_LIBRARY + "echo \"CMAKE_Rust_CREATE_SHARED_LIBRARY\"" + "${CMAKE_Rust_ECHO_ALL}" + ) +endif() + +if(NOT CMAKE_Rust_CREATE_SHARED_MODULE) + set(CMAKE_Rust_CREATE_SHARED_MODULE + "echo \"CMAKE_Rust_CREATE_SHARED_MODULE\"" + "${CMAKE_Rust_ECHO_ALL}" + ) +endif() + +if(NOT CMAKE_Rust_CREATE_STATIC_LIBRARY) + set(CMAKE_Rust_CREATE_STATIC_LIBRARY + "echo \"CMAKE_Rust_CREATE_STATIC_LIBRARY\"" + "${CMAKE_Rust_ECHO_ALL}" + ) +endif() + +if(NOT CMAKE_Rust_COMPILE_OBJECT) + set(CMAKE_Rust_COMPILE_OBJECT + "echo \"CMAKE_Rust_COMPILE_OBJECT\"" + "${CMAKE_Rust_ECHO_ALL}" + "${CMAKE_Rust_COMPILER} --emit obj -o ") +endif() + +if(NOT CMAKE_Rust_LINK_EXECUTABLE) + set(CMAKE_Rust_LINK_EXECUTABLE + "echo \"CMAKE_Rust_LINK_EXECUTABLE\"" + "${CMAKE_Rust_ECHO_ALL}" + ) +endif() + +mark_as_advanced( + CMAKE_Rust_FLAGS + CMAKE_Rust_FLAGS_DEBUG + CMAKE_Rust_FLAGS_MINSIZEREL + CMAKE_Rust_FLAGS_RELEASE + CMAKE_Rust_FLAGS_RELWITHDEBINFO) + +set(CMAKE_Rust_INFORMATION_LOADED 1) + diff --git a/cmake/CMakeTestRustCompiler.cmake b/cmake/CMakeTestRustCompiler.cmake new file mode 100644 index 00000000..ff75bb3e --- /dev/null +++ b/cmake/CMakeTestRustCompiler.cmake @@ -0,0 +1,3 @@ + +set(CMAKE_Rust_COMPILER_WORKS 1 CACHE INTERNAL "") + diff --git a/cmake/CargoLink.cmake b/cmake/CargoLink.cmake new file mode 100644 index 00000000..1db2241b --- /dev/null +++ b/cmake/CargoLink.cmake @@ -0,0 +1,64 @@ + +function(cargo_print) + execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${ARGN}") +endfunction() + +function(cargo_link) + cmake_parse_arguments(CARGO_LINK "" "NAME" "TARGETS;EXCLUDE" ${ARGN}) + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c" "void cargo_link() {}") + add_library(${CARGO_LINK_NAME} "${CMAKE_CURRENT_BINARY_DIR}/cargo-link.c") + target_link_libraries(${CARGO_LINK_NAME} ${CARGO_LINK_TARGETS}) + + get_target_property(LINK_LIBRARIES ${CARGO_LINK_NAME} LINK_LIBRARIES) + + foreach(LINK_LIBRARY ${LINK_LIBRARIES}) + get_target_property(_INTERFACE_LINK_LIBRARIES ${LINK_LIBRARY} INTERFACE_LINK_LIBRARIES) + list(APPEND LINK_LIBRARIES ${_INTERFACE_LINK_LIBRARIES}) + endforeach() + list(REMOVE_DUPLICATES LINK_LIBRARIES) + + if(CARGO_LINK_EXCLUDE) + list(REMOVE_ITEM LINK_LIBRARIES ${CARGO_LINK_EXCLUDE}) + endif() + + set(LINK_DIRECTORIES "") + foreach(LINK_LIBRARY ${LINK_LIBRARIES}) + if(TARGET ${LINK_LIBRARY}) + get_target_property(_IMPORTED_CONFIGURATIONS ${LINK_LIBRARY} IMPORTED_CONFIGURATIONS) + list(FIND _IMPORTED_CONFIGURATIONS "RELEASE" _IMPORTED_CONFIGURATION_INDEX) + if (NOT (${_IMPORTED_CONFIGURATION_INDEX} GREATER -1)) + set(_IMPORTED_CONFIGURATION_INDEX 0) + endif() + list(GET _IMPORTED_CONFIGURATIONS ${_IMPORTED_CONFIGURATION_INDEX} _IMPORTED_CONFIGURATION) + get_target_property(_IMPORTED_LOCATION ${LINK_LIBRARY} "IMPORTED_LOCATION_${_IMPORTED_CONFIGURATION}") + get_filename_component(_IMPORTED_DIR ${_IMPORTED_LOCATION} DIRECTORY) + get_filename_component(_IMPORTED_NAME ${_IMPORTED_LOCATION} NAME_WE) + if(NOT WIN32) + string(REGEX REPLACE "^lib" "" _IMPORTED_NAME ${_IMPORTED_NAME}) + endif() + list(APPEND LINK_DIRECTORIES ${_IMPORTED_DIR}) + cargo_print("cargo:rustc-link-lib=static=${_IMPORTED_NAME}") + else() + if("${LINK_LIBRARY}" MATCHES "^.*/(.+)\\.framework$") + set(FRAMEWORK_NAME ${CMAKE_MATCH_1}) + cargo_print("cargo:rustc-link-lib=framework=${FRAMEWORK_NAME}") + elseif("${LINK_LIBRARY}" MATCHES "^(.*)/(.+)\\.so$") + set(LIBRARY_DIR ${CMAKE_MATCH_1}) + set(LIBRARY_NAME ${CMAKE_MATCH_2}) + if(NOT WIN32) + string(REGEX REPLACE "^lib" "" LIBRARY_NAME ${LIBRARY_NAME}) + endif() + list(APPEND LINK_DIRECTORIES ${LIBRARY_DIR}) + cargo_print("cargo:rustc-link-lib=${LIBRARY_NAME}") + else() + cargo_print("cargo:rustc-link-lib=${LINK_LIBRARY}") + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES LINK_DIRECTORIES) + + foreach(LINK_DIRECTORY ${LINK_DIRECTORIES}) + cargo_print("cargo:rustc-link-search=native=${LINK_DIRECTORY}") + endforeach() +endfunction() diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 90524723..a7e6c70a 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -11,53 +11,55 @@ endif() # Libuv #------------------------ -# Setup the paths and hints for libuv -if(NOT LIBUV_ROOT_DIR) - if(EXISTS "${PROJECT_SOURCE_DIR}/lib/libuv/") - set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/lib/libuv/") - elseif(EXISTS "${PROJECT_SOURCE_DIR}/build/libs/libuv/") - set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/build/libs/libuv/") +if(CASS_USE_LIBUV) + # Setup the paths and hints for libuv + if(NOT LIBUV_ROOT_DIR) + if(EXISTS "${PROJECT_SOURCE_DIR}/lib/libuv/") + set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/lib/libuv/") + elseif(EXISTS "${PROJECT_SOURCE_DIR}/build/libs/libuv/") + set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/build/libs/libuv/") + endif() endif() -endif() -# Ensure libuv was found -find_package(Libuv "1.0.0") -if(WIN32 AND NOT LIBUV_FOUND) - message(STATUS "Unable to Locate libuv: Third party build step will be performed") - include(ExternalProject-libuv) -elseif(NOT LIBUV_FOUND) - message(FATAL_ERROR "Unable to Locate libuv: libuv v1.0.0+ is required") -endif() + # Ensure libuv was found + find_package(Libuv "1.0.0") + if(WIN32 AND NOT LIBUV_FOUND) + message(STATUS "Unable to Locate libuv: Third party build step will be performed") + include(ExternalProject-libuv) + elseif(NOT LIBUV_FOUND) + message(FATAL_ERROR "Unable to Locate libuv: libuv v1.0.0+ is required") + endif() -if(LIBUV_VERSION VERSION_LESS "1.0") - message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not " - " supported. Please updgrade to libuv version 1.0 or greater in order to " - "utilize the driver.") -endif() + if(LIBUV_VERSION VERSION_LESS "1.0") + message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not " + " supported. Please updgrade to libuv version 1.0 or greater in order to " + "utilize the driver.") + endif() -if(LIBUV_VERSION VERSION_LESS "1.6") - message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom " - "memory allocators (version 1.6 or greater required)") -endif() + if(LIBUV_VERSION VERSION_LESS "1.6") + message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom " + "memory allocators (version 1.6 or greater required)") + endif() -# Assign libuv include and libraries -set(CASS_INCLUDES ${CASS_INCLUDES} ${LIBUV_INCLUDE_DIRS}) -set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES}) + # Assign libuv include and libraries + set(CASS_INCLUDES ${CASS_INCLUDES} ${LIBUV_INCLUDE_DIRS}) + set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES}) -# libuv and gtests require thread library -if(NOT WIN32) - set(CMAKE_THREAD_PREFER_PTHREAD 1) - set(THREADS_PREFER_PTHREAD_FLAG 1) -endif() + # libuv and gtests require thread library + if(NOT WIN32) + set(CMAKE_THREAD_PREFER_PTHREAD 1) + set(THREADS_PREFER_PTHREAD_FLAG 1) + endif() -find_package(Threads REQUIRED) + find_package(Threads REQUIRED) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") -if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0") - # FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") + if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0") + # FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") + endif() endif() #------------------------ diff --git a/cmake/FindRust.cmake b/cmake/FindRust.cmake new file mode 100644 index 00000000..53127a10 --- /dev/null +++ b/cmake/FindRust.cmake @@ -0,0 +1,73 @@ + +set(_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + +if(CMAKE_HOST_WIN32) + set(USER_HOME "$ENV{USERPROFILE}") +else() + set(USER_HOME "$ENV{HOME}") +endif() + +if(NOT DEFINED CARGO_HOME) + if("$ENV{CARGO_HOME}" STREQUAL "") + set(CARGO_HOME "${USER_HOME}/.cargo") + else() + set(CARGO_HOME "$ENV{CARGO_HOME}") + endif() +endif() + +# Find cargo executable +find_program(CARGO_EXECUTABLE cargo + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(CARGO_EXECUTABLE) + +# Find rustc executable +find_program(RUSTC_EXECUTABLE rustc + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(RUSTC_EXECUTABLE) + +# Find rustdoc executable +find_program(RUSTDOC_EXECUTABLE rustdoc + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(RUSTDOC_EXECUTABLE) + +# Find rust-gdb executable +find_program(RUST_GDB_EXECUTABLE rust-gdb + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(RUST_GDB_EXECUTABLE) + +# Find rust-lldb executable +find_program(RUST_LLDB_EXECUTABLE rust-lldb + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(RUST_LLDB_EXECUTABLE) + +# Find rustup executable +find_program(RUSTUP_EXECUTABLE rustup + HINTS "${CARGO_HOME}" + PATH_SUFFIXES "bin") +mark_as_advanced(RUSTUP_EXECUTABLE) + +set(RUST_FOUND FALSE CACHE INTERNAL "") + +if(CARGO_EXECUTABLE AND RUSTC_EXECUTABLE AND RUSTDOC_EXECUTABLE) + set(RUST_FOUND TRUE CACHE INTERNAL "") + + set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home") + + execute_process(COMMAND ${RUSTC_EXECUTABLE} --version OUTPUT_VARIABLE RUSTC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" RUSTC_VERSION "${RUSTC_VERSION}") +endif() + +if(NOT RUST_FOUND) + message(FATAL_ERROR "Could not find Rust!") +endif() + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}) diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 00000000..4a00a165 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,25 @@ + +cmake_policy(SET CMP0007 OLD) + +if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"") +endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + execute_process( + COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message("Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) + else (EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif (EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/dist/debian/debian/control b/dist/debian/debian/control index a3b1765e..eedefa8f 100644 --- a/dist/debian/debian/control +++ b/dist/debian/debian/control @@ -6,12 +6,12 @@ Priority: optional Standards-Version: 4.6.0 Build-Depends: debhelper-compat (= 11), libssl-dev, - libclang-dev, pkg-config, openssl, ca-certificates, curl, - clang + clang, + cmake Package: libscylla-cpp-driver0 Architecture: any diff --git a/dist/debian/debian/rules b/dist/debian/debian/rules index f193f5c7..21ca98b8 100755 --- a/dist/debian/debian/rules +++ b/dist/debian/debian/rules @@ -6,48 +6,20 @@ export DH_VERBOSE=1 include /usr/share/dpkg/architecture.mk include /usr/share/dpkg/buildflags.mk -export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS -export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE +export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS DEB_HOST_GNU_TYPE jobs := $(shell echo $$DEB_BUILD_OPTIONS | sed -r "s/.*parallel=([0-9]+).*/-j\1/") -SCYLLA_VERSION := $(shell cat version | awk -F'-' '{print $1}' | sed 's/-/~/') - -VERSION_MAJOR := $(shell sed -n -e 's/^#define CASS_VERSION_MAJOR \(.*\)/\1/p' include/cassandra.h) -RUSTFLAGS := --cap-lints warn -C linker=x86_64-linux-gnu-gcc -C link-arg=-Wl,-Bsymbolic-functions -C link-arg=-Wl,-z,relro -Clink-arg=-Wl,-soname=libscylla-cpp-driver.so.$(VERSION_MAJOR) -export RUSTFLAGS +CARGO_HOME := $(CURDIR)/scylla-rust-wrapper/.cargo +RUSTUP_HOME := $(CURDIR)/scylla-rust-wrapper/.rustup +export CARGO_HOME +export RUSTUP_HOME %: dh $@ override_dh_auto_clean: - rm -rf scylla-rust-wrapper/target/packaging rm -rf scylla-rust-wrapper/.cargo - rm -rf scylla-rust-wrapper/.rust + rm -rf scylla-rust-wrapper/.rustup override_dh_auto_configure: - /usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=$(CURDIR)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(CURDIR)/scylla-rust-wrapper/.rust /bin/sh -s -- -v -y --no-modify-path - -override_dh_auto_build: - (cd scylla-rust-wrapper && PATH=$(CURDIR)/scylla-rust-wrapper/.cargo/bin:$$PATH CARGO_HOME=$(CURDIR)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(CURDIR)/scylla-rust-wrapper/.rust $(CURDIR)/scylla-rust-wrapper/.cargo/bin/cargo build $(jobs) --profile packaging --verbose) - (cd scylla-rust-wrapper && ./versioning.sh --profile packaging) - sed -e "s#@prefix@#/usr#g" \ - -e "s#@exec_prefix@#/usr#g" \ - -e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \ - -e "s#@includedir@#/usr/include#g" \ - -e "s#@version@#$(SCYLLA_VERSION)#g" \ - dist/common/pkgconfig/scylla-cpp-driver.pc.in > debian/scylla-cpp-driver.pc - sed -e "s#@prefix@#/usr#g" \ - -e "s#@exec_prefix@#/usr#g" \ - -e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \ - -e "s#@includedir@#/usr/include#g" \ - -e "s#@version@#$(SCYLLA_VERSION)#g" \ - dist/common/pkgconfig/scylla-cpp-driver_static.pc.in > debian/scylla-cpp-driver_static.pc - -override_dh_auto_install: - mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)" - mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig - mkdir -p "$(CURDIR)"/debian/tmp/usr/include - install -Dpm0644 "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.a "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)" - # We need to avoid dereference symlink, so can't use install here - cp -a "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.so "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.so.* "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/ - install -Dpm0644 "$(CURDIR)"/debian/*.pc "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig - install -Dpm0644 "$(CURDIR)"/include/*.h "$(CURDIR)"/debian/tmp/usr/include + /usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | /bin/sh -s -- -v -y --no-modify-path + dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_RustFLAGS="--cap-lints warn -C linker=$(DEB_HOST_GNU_TYPE)-gcc -C link-arg=-Wl,-Bsymbolic-functions -C link-arg=-Wl,-z,relro" diff --git a/dist/homebrew/cpp-rust-driver.rb b/dist/homebrew/cpp-rust-driver.rb deleted file mode 100644 index 2f2392ae..00000000 --- a/dist/homebrew/cpp-rust-driver.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "formula" - -class CppRustDriver < Formula - homepage "https://github.com/scylladb/cpp-rust-driver" - head "https://github.com/scylladb/cpp-rust-driver.git", branch: "master" - - depends_on "openssl" - depends_on "rust" - - def install - cass_header = File.open('include/cassandra.h').read() - version_major = cass_header.match(/^#define CASS_VERSION_MAJOR (.+)$/)[1] - version_minor = cass_header.match(/^#define CASS_VERSION_MINOR (.+)$/)[1] - version_patch = cass_header.match(/^#define CASS_VERSION_PATCH (.+)$/)[1] - version = "#{version_major}.#{version_minor}.#{version_patch}" - puts version - - ENV["RUSTFLAGS"] = "-Clink-arg=-Wl,-install_name,#{lib}/libscylla-cpp-driver.#{version_major}.dylib -Clink-arg=-Wl,-current_version,#{version} -Clink-arg=-Wl,-compatibility_version,#{version_major}" - chdir "scylla-rust-wrapper" do - system "cargo", "build", "--profile", "packaging", "--verbose" - system "./versioning.sh", "--profile", "packaging" - lib.install Dir["target/packaging/*.dylib","target/packaging/*.a"] - end - - cp "dist/common/pkgconfig/scylla-cpp-driver.pc.in", "scylla-cpp-driver.pc" - inreplace "scylla-cpp-driver.pc" do |s| - s.gsub! "@prefix@", "#{prefix}" - s.gsub! "@exec_prefix@", "#{bin}" - s.gsub! "@libdir@", "#{lib}" - s.gsub! "@includedir@", "#{include}" - s.gsub! "@version@", "#{version}" - end - - cp "dist/common/pkgconfig/scylla-cpp-driver_static.pc.in", "scylla-cpp-driver_static.pc" - inreplace "scylla-cpp-driver_static.pc" do |s| - s.gsub! "@prefix@", "#{prefix}" - s.gsub! "@exec_prefix@", "#{bin}" - s.gsub! "@libdir@", "#{lib}" - s.gsub! "@includedir@", "#{include}" - s.gsub! "@version@", "#{version}" - end - - (lib/"pkgconfig").install Dir["*.pc"] - include.install "include/cassandra.h" - end -end diff --git a/dist/homebrew/scylla-cpp-rust-driver.rb b/dist/homebrew/scylla-cpp-rust-driver.rb new file mode 100644 index 00000000..56300584 --- /dev/null +++ b/dist/homebrew/scylla-cpp-rust-driver.rb @@ -0,0 +1,16 @@ +require "formula" + +class ScyllaCppRustDriver < Formula + homepage "https://github.com/scylladb/cpp-rust-driver" + head "https://github.com/scylladb/cpp-rust-driver.git", branch: "master" + + depends_on "cmake" => :build + depends_on "rust" => :build + depends_on "openssl@3" + + def install + system "cmake", "-S", ".", "-B", "build", "-DCMAKE_BUILD_TYPE=RelWithDebInfo", "-DCMAKE_VERBOSE_MAKEFILE=ON", *std_cmake_args + system "cmake", "--build", "build" + system "cmake", "--install", "build" + end +end diff --git a/dist/redhat/build_rpm.sh b/dist/redhat/build_rpm.sh index 212363fb..a9493ed4 100755 --- a/dist/redhat/build_rpm.sh +++ b/dist/redhat/build_rpm.sh @@ -2,7 +2,7 @@ . /etc/os-release print_usage() { - echo "build_rpm.sh --jobs 2 --target rocky+epel-9-x86_64" + echo "build_rpm.sh --jobs 2 --target rocky-9-x86_64" echo " --jobs specify number of jobs" echo " --target target distribution in mock cfg name" exit 1 diff --git a/dist/redhat/scylla-cpp-rust-driver.spec b/dist/redhat/scylla-cpp-rust-driver.spec index 46d95e41..ecf65aa6 100644 --- a/dist/redhat/scylla-cpp-rust-driver.spec +++ b/dist/redhat/scylla-cpp-rust-driver.spec @@ -8,8 +8,9 @@ License: LGPLv2.1 URL: https://github.com/scylladb/cpp-rust-driver Source0: %{name}-%{driver_version}-%{driver_release}.tar BuildRequires: openssl-devel -BuildRequires: clang-devel +BuildRequires: clang BuildRequires: curl +BuildRequires: cmake Conflicts: scylla-cpp-driver %description @@ -27,38 +28,23 @@ Development libraries for %{name} %prep %autosetup -%{__rm} -rf scylla-rust-wrapper/target/packaging %{__rm} -rf scylla-rust-wrapper/.cargo -%{__rm} -rf scylla-rust-wrapper/.rust -/usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=$(pwd)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(pwd)/scylla-rust-wrapper/.rust RUSTUP_INIT_SKIP_PATH_CHECK=yes /bin/sh -s -- -y -set -euo pipefail +%{__rm} -rf scylla-rust-wrapper/.rustup +export CARGO_HOME=$(pwd)/scylla-rust-wrapper/.cargo +export RUSTUP_HOME=$(pwd)/scylla-rust-wrapper/.rustup +/usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | RUSTUP_INIT_SKIP_PATH_CHECK=yes /bin/sh -s -- -y %build -RUSTFLAGS="-Cforce-frame-pointers=yes --cap-lints=warn" -VERSION_MAJOR=$(sed -n -e 's/^#define CASS_VERSION_MAJOR \(.*\)/\1/p' include/cassandra.h) -export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-Wl,-soname=libscylla-cpp-driver.so.$VERSION_MAJOR" -(cd scylla-rust-wrapper && PATH=$(pwd)/.cargo/bin:$PATH CARGO_HOME=$(pwd)/.cargo RUSTUP_HOME=$(pwd)/.rust $(pwd)/.cargo/bin/cargo build %{?_smp_mflags} --profile packaging --verbose) -(cd scylla-rust-wrapper && ./versioning.sh --profile packaging) -sed -e "s#@prefix@#%{_prefix}#g" \ - -e "s#@exec_prefix@#%{_exec_prefix}#g" \ - -e "s#@libdir@#%{_libdir}#g" \ - -e "s#@includedir@#%{_includedir}#g" \ - -e "s#@version@#%{version}#g" \ - dist/common/pkgconfig/scylla-cpp-driver.pc.in > scylla-cpp-driver.pc -sed -e "s#@prefix@#%{_prefix}#g" \ - -e "s#@exec_prefix@#%{_exec_prefix}#g" \ - -e "s#@libdir@#%{_libdir}#g" \ - -e "s#@includedir@#%{_includedir}#g" \ - -e "s#@version@#%{version}#g" \ - dist/common/pkgconfig/scylla-cpp-driver_static.pc.in > scylla-cpp-driver_static.pc +export CARGO_HOME=$(pwd)/scylla-rust-wrapper/.cargo +export RUSTUP_HOME=$(pwd)/scylla-rust-wrapper/.rustup +%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_RustFLAGS="-Cforce-frame-pointers=yes --cap-lints=warn" +%cmake_build %install -rm -rf %{buildroot} -install -Dpm0644 scylla-rust-wrapper/target/packaging/*.a -t %{buildroot}%{_libdir} -# We need to avoid dereference symlink, so can't use install here -cp -a scylla-rust-wrapper/target/packaging/{*.so.*,*.so} %{buildroot}%{_libdir} -install -Dpm0644 *.pc -t %{buildroot}%{_libdir}/pkgconfig -install -Dpm0644 include/*.h -t %{buildroot}%{_includedir} +%cmake_install + +%check +%ctest %ldconfig_scriptlets diff --git a/scylla-rust-wrapper/CMakeLists.txt b/scylla-rust-wrapper/CMakeLists.txt new file mode 100644 index 00000000..760b6a64 --- /dev/null +++ b/scylla-rust-wrapper/CMakeLists.txt @@ -0,0 +1,150 @@ +list(APPEND INCLUDE_DIRS ${CASS_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +#------------------------------ +# Targets +#------------------------------ + +macro(create_symlink source_file symlink_name) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${symlink_name} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${source_file} ${CMAKE_BINARY_DIR}/${symlink_name} + ) + add_custom_target(${symlink_name}_symlink ALL DEPENDS ${CMAKE_BINARY_DIR}/${symlink_name}) +endmacro() + +macro(create_copy source_file dest_name) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${dest_name} + DEPENDS ${source_file} + COMMAND ${CMAKE_COMMAND} -E copy ${source_file} ${CMAKE_BINARY_DIR}/${dest_name} + ) + add_custom_target(${dest_name}_copy ALL DEPENDS ${CMAKE_BINARY_DIR}/${dest_name}) +endmacro() + +if(APPLE) + set(INSTALL_NAME_SHARED "libscylla-cpp-driver.${PROJECT_VERSION_STRING}.dylib") + set(INSTALL_NAME_SHARED_SYMLINK_VERSION "libscylla-cpp-driver.${PROJECT_VERSION_MAJOR}.dylib") + set(INSTALL_NAME_SHARED_SYMLINK_NO_VERSION "libscylla-cpp-driver.dylib") + set(CMAKE_Rust_FLAGS_SONAME "-Clink-arg=-Wl,-install_name,${CMAKE_INSTALL_LIBDIR}/libscylla-cpp-driver.${PROJECT_VERSION_MAJOR}.dylib -Clink-arg=-Wl,-current_version,${PROJECT_VERSION_STRING} -Clink-arg=-Wl,-compatibility_version,${PROJECT_VERSION_MAJOR}") +else() + set(INSTALL_NAME_SHARED "libscylla-cpp-driver.so.${PROJECT_VERSION_STRING}") + set(INSTALL_NAME_SHARED_SYMLINK_VERSION "libscylla-cpp-driver.so.${PROJECT_VERSION_MAJOR}") + set(INSTALL_NAME_SHARED_SYMLINK_NO_VERSION "libscylla-cpp-driver.so") + set(CMAKE_Rust_FLAGS_SONAME "-Clink-arg=-Wl,-soname=libscylla-cpp-driver.so.${PROJECT_VERSION_MAJOR}") +endif() +set(INSTALL_NAME_STATIC "libscylla-cpp-driver_static.a") +if(DEFINED CMAKE_Rust_FLAGS) + set(CMAKE_Rust_FLAGS "${CMAKE_Rust_FLAGS} ${CMAKE_Rust_FLAGS_SONAME}") +else() + set(CMAKE_Rust_FLAGS "${CMAKE_Rust_FLAGS_SONAME}") +endif() +cargo_build(NAME scylla_cpp_driver) +create_copy($ ${INSTALL_NAME_SHARED}) +add_library(scylla-cpp-driver SHARED IMPORTED GLOBAL) +add_dependencies(scylla-cpp-driver scylla-cpp-driver_target) +set_target_properties(scylla-cpp-driver PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED}) +create_copy($ ${INSTALL_NAME_STATIC}) +add_library(scylla-cpp-driver_static STATIC IMPORTED GLOBAL) +add_dependencies(scylla-cpp-driver_static scylla-cpp-driver_static_target) +set_target_properties(scylla-cpp-driver_static PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/${INSTALL_NAME_STATIC}) +create_symlink(${INSTALL_NAME_SHARED} ${INSTALL_NAME_SHARED_SYMLINK_VERSION}) +create_symlink(${INSTALL_NAME_SHARED} ${INSTALL_NAME_SHARED_SYMLINK_NO_VERSION}) + +#------------------------------------- +# Installation +#------------------------------------- + +# Determine if the library directory needs to be determined +if(NOT DEFINED CMAKE_INSTALL_LIBDIR) + if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR + "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")) + if(EXISTS "/etc/debian_version") + set (CMAKE_INSTALL_LIBDIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}") + elseif(EXISTS "/etc/redhat-release" OR EXISTS "/etc/fedora-release" OR + EXISTS "/etc/slackware-version" OR EXISTS "/etc/gentoo-release") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set (CMAKE_INSTALL_LIBDIR "lib64") + else() + set (CMAKE_INSTALL_LIBDIR "lib") + endif() + else() + set (CMAKE_INSTALL_LIBDIR "lib") + endif() + else() + set (CMAKE_INSTALL_LIBDIR "lib") + endif() +endif() + +# Create a binary directory executable and DLLs (windows only) +set(INSTALL_DLL_EXE_DIR "bin") # Determine the header install dir +if (CASS_INSTALL_HEADER_IN_SUBDIR) + if (CASS_INSTALL_HEADER_SUBDIR_NAME) + # User-specified include sub-dir + set(INSTALL_HEADER_DIR "include/${CASS_INSTALL_HEADER_SUBDIR_NAME}") + else() + # Default subdir location is 'include/cassandra' + set(INSTALL_HEADER_DIR "include/cassandra") + endif() +else() + # Default header install location is 'include' + set(INSTALL_HEADER_DIR "include") +endif() + +if(CASS_INSTALL_PKG_CONFIG) + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + set(prefix ${CMAKE_INSTALL_PREFIX}) + set(exec_prefix ${CMAKE_INSTALL_PREFIX}) + set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) + set(includedir ${CMAKE_INSTALL_PREFIX}/${INSTALL_HEADER_DIR}) + set(version ${PROJECT_VERSION_STRING}) + endif() +endif() + +# Determine if the header should be installed +if(CASS_INSTALL_HEADER) + file(GLOB CASS_API_HEADER_FILES ${CASS_INCLUDE_DIR}/*.h) + install(FILES ${CASS_API_HEADER_FILES} DESTINATION ${INSTALL_HEADER_DIR}) +endif() + +# Install the dynamic/shared library +if(CASS_BUILD_SHARED) + install(FILES $ + DESTINATION ${CMAKE_INSTALL_LIBDIR} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ) + install(FILES ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED_SYMLINK_VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(FILES ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED_SYMLINK_NO_VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(CASS_INSTALL_PKG_CONFIG) + if(PKG_CONFIG_FOUND) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scylla-cpp-driver.pc.in" "scylla-cpp-driver.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/scylla-cpp-driver.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + endif() + endif() +endif() + +if(CASS_BUILD_STATIC) + install(FILES $ + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(CASS_INSTALL_PKG_CONFIG) + if(PKG_CONFIG_FOUND) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scylla-cpp-driver_static.pc.in" "scylla-cpp-driver_static.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/scylla-cpp-driver_static.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + endif() + endif() +endif() + +#------------------- +# Uninstall target +#------------------- + +configure_file( + "${CASS_ROOT_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) diff --git a/scylla-rust-wrapper/Cargo.toml b/scylla-rust-wrapper/Cargo.toml index 9f672d7d..130f492b 100644 --- a/scylla-rust-wrapper/Cargo.toml +++ b/scylla-rust-wrapper/Cargo.toml @@ -47,7 +47,7 @@ panic = "abort" lto = true panic = "abort" -[profile.packaging] +[profile.relwithdebinfo] inherits = "release" opt-level = 3 codegen-units = 1 diff --git a/dist/common/pkgconfig/scylla-cpp-driver.pc.in b/scylla-rust-wrapper/scylla-cpp-driver.pc.in similarity index 100% rename from dist/common/pkgconfig/scylla-cpp-driver.pc.in rename to scylla-rust-wrapper/scylla-cpp-driver.pc.in diff --git a/dist/common/pkgconfig/scylla-cpp-driver_static.pc.in b/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in similarity index 100% rename from dist/common/pkgconfig/scylla-cpp-driver_static.pc.in rename to scylla-rust-wrapper/scylla-cpp-driver_static.pc.in diff --git a/scylla-rust-wrapper/versioning.sh b/scylla-rust-wrapper/versioning.sh deleted file mode 100755 index a7190cf2..00000000 --- a/scylla-rust-wrapper/versioning.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -e - -print_usage() { - echo "$0 --profile release" - echo " --profile specify profile" - exit 1 -} -PROFILE="release" -while [[ $# -gt 0 ]]; do - case "$1" in - "--profile") - PROFILE="$2" - shift 2 - ;; - *) - print_usage - ;; - esac -done - -TARGET="${PROFILE}" -case "${PROFILE}" in - "dev") - TARGET="debug" - ;; -esac - -if [[ ! -d target/"${TARGET}" ]]; then - echo "Failed to locate build directory: target/${TARGET}" - exit 1 -fi - -VERSION_MAJOR=$(sed -n -e 's/^#define CASS_VERSION_MAJOR \(.*\)/\1/p' ../include/cassandra.h) -VERSION_MINOR=$(sed -n -e 's/^#define CASS_VERSION_MINOR \(.*\)/\1/p' ../include/cassandra.h) -VERSION_PATCH=$(sed -n -e 's/^#define CASS_VERSION_PATCH \(.*\)/\1/p' ../include/cassandra.h) -VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" - -UNAME="$(uname)" -# On macOS -if [[ "${UNAME}" = "Darwin" ]]; then - # library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here - rm -f target/"${TARGET}"/{libscylla-cpp-driver.dylib,libscylla-cpp-driver_static.a} - cp -v target/"${TARGET}"/libscylla_cpp_driver.dylib target/"${TARGET}"/libscylla-cpp-driver.dylib - cp -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a - rm -fv target/"${TARGET}"/libscylla_cpp_driver.{dylib,a} - - # make .so "versioned" style using symlinks - rm -f target/"${TARGET}"/libscylla-cpp-driver."${VERSION}".dylib - cp -v target/"${TARGET}"/libscylla-cpp-driver.dylib target/"${TARGET}"/libscylla-cpp-driver."${VERSION}".dylib - ln -vsf libscylla-cpp-driver."${VERSION}".dylib target/"${TARGET}"/libscylla-cpp-driver."${VERSION_MAJOR}".dylib - ln -vsf libscylla-cpp-driver."${VERSION}".dylib target/"${TARGET}"/libscylla-cpp-driver.dylib -# Linux and other -else - # library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here - cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.so target/"${TARGET}"/libscylla-cpp-driver.so - cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a - rm -fv target/"${TARGET}"/libscylla_cpp_driver.{so,a} - - # make .so "versioned" style using symlinks - cp --remove-destination -v target/"${TARGET}"/libscylla-cpp-driver.so target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION}" - ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION_MAJOR}" - ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so -fi