From f77822e7322200d355fe7c3f7deb812673b99bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Thu, 4 Apr 2024 19:22:38 +0200 Subject: [PATCH] Vendor rust dependencies --- .gitmodules | 3 +++ contrib/rust_vendor | 1 + rust/CMakeLists.txt | 17 ++-------------- rust/VENDOR.md | 3 +++ rust/prql/.cargo/config.toml.in | 8 ++++++++ rust/prql/CMakeLists.txt | 1 + rust/prql/Cargo.lock | 1 + rust/skim/.cargo/config.toml.in | 6 ++++++ rust/skim/CMakeLists.txt | 36 +++++---------------------------- rust/skim/Cargo.lock | 1 + 10 files changed, 31 insertions(+), 46 deletions(-) create mode 160000 contrib/rust_vendor create mode 100644 rust/VENDOR.md create mode 100644 rust/prql/.cargo/config.toml.in create mode 120000 rust/prql/Cargo.lock create mode 120000 rust/skim/Cargo.lock diff --git a/.gitmodules b/.gitmodules index a618104f364..b589eec98ee 100644 --- a/.gitmodules +++ b/.gitmodules @@ -369,3 +369,6 @@ [submodule "contrib/idna"] path = contrib/idna url = https://github.com/ada-url/idna.git +[submodule "contrib/rust_vendor"] + path = contrib/rust_vendor + url = https://github.com/ClickHouse/rust_vendor.git diff --git a/contrib/rust_vendor b/contrib/rust_vendor new file mode 160000 index 00000000000..d9cdb3cc440 --- /dev/null +++ b/contrib/rust_vendor @@ -0,0 +1 @@ +Subproject commit d9cdb3cc4404b60dce8b6c4184226c7f7d50eef9 diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index cebfd36a24a..9257fc90c4e 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -52,6 +52,7 @@ macro(configure_rustc) message(STATUS "RUSTFLAGS: ${RUSTFLAGS}") message(STATUS "RUST_CARGO_BUILD_STD: ${RUST_CARGO_BUILD_STD}") + set(RUST_VENDOR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../contrib/rust_vendor") # 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) endmacro() @@ -80,9 +81,7 @@ function(clickhouse_import_crate) endif() endif() - # Note, here --offline is not used, since on CI vendor archive is used, and - # passing --offline here will be inconvenient for local development. - corrosion_import_crate(NO_STD ${ARGN} PROFILE ${profile}) + corrosion_import_crate(NO_STD ${ARGN} PROFILE ${profile} FLAGS --offline) endfunction() # Add crate from the build directory. @@ -100,18 +99,6 @@ function(add_rust_subdirectory src) file(COPY "${src}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" PATTERN target EXCLUDE) - # 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 - WORKING_DIRECTORY "${dst}" - RESULT_VARIABLE CARGO_UPDATE_RESULT - OUTPUT_VARIABLE CARGO_UPDATE_STDOUT - ERROR_VARIABLE CARGO_UPDATE_STDERR) - 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() - add_subdirectory("${dst}" "${dst}") # cmake -E copy* do now know how to exclude files diff --git a/rust/VENDOR.md b/rust/VENDOR.md new file mode 100644 index 00000000000..e3d4678b24a --- /dev/null +++ b/rust/VENDOR.md @@ -0,0 +1,3 @@ +- Update Cargo.lock +- Run `cargo vendor --locked ../contrib/rust_vendor` +- Update `rust_vendor` submodule with the new contents diff --git a/rust/prql/.cargo/config.toml.in b/rust/prql/.cargo/config.toml.in new file mode 100644 index 00000000000..18c1adece0b --- /dev/null +++ b/rust/prql/.cargo/config.toml.in @@ -0,0 +1,8 @@ +[env] +CXXFLAGS = "@RUST_CXXFLAGS@" + +[source.crates-io] +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "@RUST_VENDOR_DIR@" diff --git a/rust/prql/CMakeLists.txt b/rust/prql/CMakeLists.txt index 65109d19a81..88f9bb521ca 100644 --- a/rust/prql/CMakeLists.txt +++ b/rust/prql/CMakeLists.txt @@ -1,3 +1,4 @@ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml.in" "${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml" @ONLY) clickhouse_import_crate(MANIFEST_PATH Cargo.toml) target_include_directories(_ch_rust_prql INTERFACE include) add_library(ch_rust::prql ALIAS _ch_rust_prql) diff --git a/rust/prql/Cargo.lock b/rust/prql/Cargo.lock new file mode 120000 index 00000000000..09fdd3b6ba3 --- /dev/null +++ b/rust/prql/Cargo.lock @@ -0,0 +1 @@ +../Cargo.lock \ No newline at end of file diff --git a/rust/skim/.cargo/config.toml.in b/rust/skim/.cargo/config.toml.in index bcd4684f957..18c1adece0b 100644 --- a/rust/skim/.cargo/config.toml.in +++ b/rust/skim/.cargo/config.toml.in @@ -1,2 +1,8 @@ [env] CXXFLAGS = "@RUST_CXXFLAGS@" + +[source.crates-io] +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "@RUST_VENDOR_DIR@" diff --git a/rust/skim/CMakeLists.txt b/rust/skim/CMakeLists.txt index 82a62b792e8..9d393dbb510 100644 --- a/rust/skim/CMakeLists.txt +++ b/rust/skim/CMakeLists.txt @@ -1,25 +1,18 @@ if (OS_FREEBSD) # Right nix/libc requires fspacectl and it had been added only since FreeBSD14. - # And sicne sysroot has older libararies you will got undefined reference for clickhouse binary. + # And since sysroot has older libraries you will got undefined reference for clickhouse binary. # # But likely everything should work without this syscall, however it is not - # possible right now to gently override libraries versions for depdendcies, + # possible right now to gently override libraries versions for dependencies, # and forking rust modules is a little bit too much for this thing. # - # You can take a look at the details in the fillowing issue [1]. + # You can take a look at the details in the following issue [1]. # # [1]: https://github.com/rust-lang/cargo/issues/5640 # message(STATUS "skim is disabled for FreeBSD") return() endif() -if (SANITIZE STREQUAL "thread") - # Rust does not supports Thread Sanitizer [1] - # - # [1]: https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html#threadsanitizer - message(STATUS "skim is disabled under Thread Sanitizer") - return() -endif() clickhouse_import_crate(MANIFEST_PATH Cargo.toml) @@ -32,24 +25,5 @@ message(STATUS "RUST_CXXFLAGS (for skim): ${RUST_CXXFLAGS}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.rs.in" "${CMAKE_CURRENT_SOURCE_DIR}/build.rs" @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml.in" "${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml" @ONLY) -set (ffi_binding_generated_path - ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/cargo/build/${Rust_CARGO_TARGET_CACHED}/cxxbridge/_ch_rust_skim_rust/src/lib.rs.cc) -set (ffi_binding_final_path ${CMAKE_CURRENT_BINARY_DIR}/skim-ffi.cc) -message(STATUS "Writing FFI Binding for skim: ${ffi_binding_generated_path} => ${ffi_binding_final_path}") - -add_custom_command(OUTPUT ${ffi_binding_final_path} - COMMAND ${CMAKE_COMMAND} -E copy ${ffi_binding_generated_path} ${ffi_binding_final_path} - DEPENDS cargo-build__ch_rust_skim_rust) - -add_library(_ch_rust_skim_ffi ${ffi_binding_final_path}) - -# cxx bridge compiles such bindings -set_target_properties(_ch_rust_skim_ffi PROPERTIES COMPILE_FLAGS "${CXXBRIDGE_CXXFLAGS}") - -add_library(_ch_rust_skim INTERFACE) -target_include_directories(_ch_rust_skim INTERFACE include) -target_link_libraries(_ch_rust_skim INTERFACE - _ch_rust_skim_rust - _ch_rust_skim_ffi) - -add_library(ch_rust::skim ALIAS _ch_rust_skim) +target_include_directories(_ch_rust_skim_rust INTERFACE include) +add_library(ch_rust::skim ALIAS _ch_rust_skim_rust) diff --git a/rust/skim/Cargo.lock b/rust/skim/Cargo.lock new file mode 120000 index 00000000000..09fdd3b6ba3 --- /dev/null +++ b/rust/skim/Cargo.lock @@ -0,0 +1 @@ +../Cargo.lock \ No newline at end of file