diff --git a/services/backup/CMakeLists.txt b/services/backup/CMakeLists.txt index 2fdd46865..699d79ed4 100644 --- a/services/backup/CMakeLists.txt +++ b/services/backup/CMakeLists.txt @@ -1,135 +1,142 @@ PROJECT(backup CXX) cmake_minimum_required(VERSION 3.16) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) set(CMAKE_CXX_STANDARD 17) # For C++17 on MacOS, we must set minimum target to 10.14+ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14) set(BUILD_TESTING OFF CACHE BOOL "Turn off tests" FORCE) set(WITH_GTEST "Use Google Test" OFF) find_package(glog REQUIRED) find_package(protobuf REQUIRED) find_package(gRPC REQUIRED) find_package(Folly REQUIRED) find_package(AWSSDK REQUIRED COMPONENTS core dynamodb) find_package(Boost 1.40 COMPONENTS program_options context filesystem regex system thread REQUIRED ) +# Rust integration +include(cmake-components/corrosion-cxx.cmake) +find_package(Corrosion REQUIRED) + if(${CMAKE_CURRENT_SOURCE_DIR} MATCHES "^\/transferred.*") # Inside the docker build contex set(_proto_path "grpc") else() # Inside repo set(_proto_path "../../native/cpp/CommonCpp/grpc") endif() # Shared Comm protos add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${_proto_path} ${CMAKE_CURRENT_BINARY_DIR}/protos EXCLUDE_FROM_ALL ) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lib/src ${CMAKE_CURRENT_BINARY_DIR}/lib/src EXCLUDE_FROM_ALL ) file(GLOB_RECURSE SOURCE_CODE "./src/*.cpp") # SERVER add_executable( backup ${GENERATED_CODE} ${FOLLY_SOURCES} ${SOURCE_CODE} ) +add_library_rust(PATH rust_lib NAMESPACE backup) + target_include_directories( backup PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/grpc-client ${CMAKE_CURRENT_SOURCE_DIR}/src/DatabaseEntities ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors/server ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors/server/base-reactors ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors/client ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors/client/blob ${CMAKE_CURRENT_SOURCE_DIR}/src/Reactors/client/base-reactors ${Boost_INCLUDE_DIR} ) set( LIBS ${GRPC_LIBS} ${AWSSDK_LINK_LIBRARIES} ${Boost_LIBRARIES} glog::glog Folly::folly gRPC::grpc++ comm-blob-grpc comm-backup-grpc comm-services-common comm-client-base-reactors comm-server-base-reactors + backup::rust_lib ) target_link_libraries( backup ${LIBS} ) install( TARGETS backup RUNTIME DESTINATION bin/ ) # TEST if ($ENV{COMM_TEST_SERVICES} MATCHES 1) file(GLOB TEST_CODE "./test/*.cpp") list(FILTER SOURCE_CODE EXCLUDE REGEX "./src/server.cpp") enable_testing() find_package(GTest REQUIRED) include_directories( ${GTEST_INCLUDE_DIR} ./test ) add_executable( runTests ${GENERATED_CODE} ${FOLLY_SOURCES} ${SOURCE_CODE} ${TEST_CODE} ) target_link_libraries( runTests ${LIBS} gtest gtest_main ) add_test( NAME runTests COMMAND runTests ) endif() diff --git a/services/backup/Dockerfile b/services/backup/Dockerfile index 0397d350c..c45817d94 100644 --- a/services/backup/Dockerfile +++ b/services/backup/Dockerfile @@ -1,27 +1,29 @@ FROM commapp/services-base:1.3.2 RUN apt-get update && \ apt-get install -y uuid-dev && \ rm -rf /var/lib/apt/lists/* ARG COMM_TEST_SERVICES ARG COMM_SERVICES_SANDBOX ENV COMM_TEST_SERVICES=${COMM_TEST_SERVICES} ENV COMM_SERVICES_SANDBOX=${COMM_SERVICES_SANDBOX} -WORKDIR /transferred +WORKDIR /transferred/backup -COPY services/backup/ backup/ -COPY services/lib/src/ lib/src/ +COPY services/lib/docker/ scripts/ -WORKDIR /transferred/backup +# install rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +RUN scripts/install_corrosion.sh COPY native/cpp/CommonCpp/grpc grpc/ -COPY services/lib/docker/ scripts/ +COPY shared/cmake cmake-components/ -RUN scripts/build_service.sh +COPY services/backup/ /transferred/backup/ +COPY services/lib/src/ /transferred/lib/src/ -WORKDIR /transferred +RUN scripts/build_service.sh CMD if [ "$COMM_TEST_SERVICES" -eq 1 ]; then scripts/run_tests.sh; else scripts/run_service.sh; fi diff --git a/services/backup/rust_lib/Cargo.lock b/services/backup/rust_lib/Cargo.lock new file mode 100644 index 000000000..531e9b84e --- /dev/null +++ b/services/backup/rust_lib/Cargo.lock @@ -0,0 +1,173 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "cxx" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "873c2e83af70859af2aaecd1f5d862f3790b747b1f4f50fb45a931d000ac0422" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49edea7163bbc7a39e3d829b4b0b66a9d30486973152842b7413f2c7b5632bf" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46b787c15af80277db5c88c6ac6c502ae545e622f010e06f95e540d34931acf" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ba3f3a7efa46626878fb5d324fabca4d19d2956b6ae97ce43044ef4515f5abc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cae2cd7ba2f3f63938b9c724475dfb7b9861b545a90324476324ed21dbc8c8" +dependencies = [ + "cc", +] + +[[package]] +name = "once_cell" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" + +[[package]] +name = "proc-macro2" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rust_lib" +version = "0.1.0" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + +[[package]] +name = "syn" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "unicode-ident" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/services/backup/rust_lib/Cargo.toml b/services/backup/rust_lib/Cargo.toml new file mode 100644 index 000000000..a18805f0d --- /dev/null +++ b/services/backup/rust_lib/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "rust_lib" +version = "0.1.0" +edition = "2021" + +[dependencies] +cxx = "1.0" + +[build-dependencies] +cxx-build = "1.0" + +[lib] +crate-type = ["staticlib"] + +[profile.release] +panic = "abort" + +[profile.dev] +debug = true +panic = "abort" diff --git a/services/backup/rust_lib/build.rs b/services/backup/rust_lib/build.rs new file mode 100644 index 000000000..8bd5592ee --- /dev/null +++ b/services/backup/rust_lib/build.rs @@ -0,0 +1,4 @@ +fn main() { + let _build = cxx_build::bridge("src/lib.rs").flag_if_supported("-std=c++17"); + println!("cargo:rerun-if-changed=src/lib.rs"); +} diff --git a/services/backup/rust_lib/src/lib.rs b/services/backup/rust_lib/src/lib.rs new file mode 100644 index 000000000..33c1cad16 --- /dev/null +++ b/services/backup/rust_lib/src/lib.rs @@ -0,0 +1,10 @@ +#[cxx::bridge] +mod ffi { + extern "Rust" { + fn test_function() -> i32; + } +} + +pub fn test_function() -> i32 { + 0 +}