From b276a87193ba8436d0f33dca746bb1896a094e9a Mon Sep 17 00:00:00 2001 From: Kitlith Date: Sun, 2 Jul 2023 00:09:04 -0700 Subject: [PATCH] Remove rust portion. Consensus is that we're not going to move in this direction -- if anything, we'll rewrite it in rust. --- .github/workflows/build.yml | 13 ++--- CMakeLists.txt | 7 +-- rust_part/.gitignore | 2 - rust_part/CMakeLists.txt | 49 ------------------ rust_part/Cargo.toml | 15 ------ rust_part/build.rs | 5 -- rust_part/src/lib.rs | 100 ------------------------------------ src/cxx_test.cpp | 48 ----------------- 8 files changed, 5 insertions(+), 234 deletions(-) delete mode 100644 rust_part/.gitignore delete mode 100644 rust_part/CMakeLists.txt delete mode 100644 rust_part/Cargo.toml delete mode 100644 rust_part/build.rs delete mode 100644 rust_part/src/lib.rs delete mode 100644 src/cxx_test.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60c4f9b..a03695e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [windows-latest, ubuntu-latest] - + steps: - uses: actions/checkout@v2 with: @@ -17,13 +17,6 @@ jobs: # shallow clone doesn't pull tags, unfortunately. fetch-depth: 0 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - # components: rustfmt, clippy - - uses: lukka/get-cmake@latest - name: vcpkg setup/restore artifacts @@ -31,7 +24,7 @@ jobs: id: runvcpkg with: vcpkgJsonGlob: 'vcpkg.json' - + - name: Prints output of run-vcpkg's action. run: echo "root='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}', triplet='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_DEFAULT_TRIPLET_OUT }}' " @@ -79,7 +72,7 @@ jobs: uses: actions/upload-artifact@v3 with: path: ${{ env.artifactPath }} - + - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') diff --git a/CMakeLists.txt b/CMakeLists.txt index 96b581a..63a6dc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,18 +15,15 @@ find_package(simdjson CONFIG REQUIRED) set(protos_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/protos) file(MAKE_DIRECTORY "${protos_OUTPUT_DIR}") -include_directories(${CMAKE_BINARY_DIR}/rust_part) include_directories(include) -add_subdirectory(rust_part) - set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH $ORIGIN) # Project -add_executable("${PROJECT_NAME}" "src/main.cpp" "src/pathtools_excerpt.cpp" "src/pathtools_excerpt.h" "src/matrix_utils.cpp" "src/matrix_utils.h" "src/bridge.cpp" "src/bridge.hpp" "src/setup.cpp" "src/setup.hpp" "ProtobufMessages.proto" "src/cxx_test.cpp") -target_link_libraries("${PROJECT_NAME}" PRIVATE "${OPENVR_LIB}" fmt::fmt protobuf::libprotobuf simdjson::simdjson rust_part) +add_executable("${PROJECT_NAME}" "src/main.cpp" "src/pathtools_excerpt.cpp" "src/pathtools_excerpt.h" "src/matrix_utils.cpp" "src/matrix_utils.h" "src/bridge.cpp" "src/bridge.hpp" "src/setup.cpp" "src/setup.hpp" "ProtobufMessages.proto") +target_link_libraries("${PROJECT_NAME}" PRIVATE "${OPENVR_LIB}" fmt::fmt protobuf::libprotobuf simdjson::simdjson) protobuf_generate(TARGET "${PROJECT_NAME}" LANGUAGE cpp PROTOC_OUT_DIR ${protos_OUTPUT_DIR}) target_include_directories("${PROJECT_NAME}" PUBLIC ${protos_OUTPUT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_compile_features("${PROJECT_NAME}" PRIVATE cxx_std_17) diff --git a/rust_part/.gitignore b/rust_part/.gitignore deleted file mode 100644 index 4470988..0000000 --- a/rust_part/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Cargo.lock \ No newline at end of file diff --git a/rust_part/CMakeLists.txt b/rust_part/CMakeLists.txt deleted file mode 100644 index d38e779..0000000 --- a/rust_part/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ - -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CARGO_CMD cargo build --verbose) - set(TARGET_DIR "debug") -else () - set(CARGO_CMD cargo build --release --verbose) - set(TARGET_DIR "release") -endif () - -# TODO: this would be really nice to enable, but is not really setup everywhere else -# if(ENABLE_LTO) -# set(RUST_FLAGS "-Clinker-plugin-lto" "-Clinker=clang-13" "-Clink-arg=-fuse-ld=lld-13") -# endif() - -if (MSVC) - set(RUST_PART_LIB "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/rust_part.lib") -elseif (UNIX) - set(RUST_PART_LIB "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/librust_part.a") -else () - message(FATAL_ERROR "It's not unix and not windows, ¯\\_(ツ)_/¯") -endif () - -set(RUST_PART_CXX "${CMAKE_CURRENT_BINARY_DIR}/rust_part.cpp") -add_library(rust_part STATIC ${RUST_PART_CXX}) -add_custom_command( - OUTPUT ${RUST_PART_CXX} ${RUST_PART_LIB} - COMMAND ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} RUSTFLAGS="${RUST_FLAGS}" ${CARGO_CMD} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/rust_part/src/lib.rs.cc ${RUST_PART_CXX} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/rust_part/src/lib.rs.h ${CMAKE_CURRENT_BINARY_DIR}/rust_part.h - DEPENDS src/lib.rs - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_link_libraries(rust_part ${RUST_PART_LIB}) -# if (MSVC) -# target_link_libraries(rust_part ws2_32 userenv advapi32 shell32) -# if (CMAKE_BUILD_TYPE STREQUAL "Release") -# target_link_libraries(rust_part msvcrt) -# else () -# target_link_libraries(rust_part msvcrtd) -# endif() -# else -if (UNIX) - target_link_libraries(rust_part pthread m dl) -endif () - -add_test(NAME rust_part_test - COMMAND cargo test - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/rust_part/Cargo.toml b/rust_part/Cargo.toml deleted file mode 100644 index 142b89d..0000000 --- a/rust_part/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "rust_part" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -cxx = "1.0" - -[build-dependencies] -cxx-build = "1.0" - -[lib] -crate-type = ["staticlib"] \ No newline at end of file diff --git a/rust_part/build.rs b/rust_part/build.rs deleted file mode 100644 index acd3d90..0000000 --- a/rust_part/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let _build = cxx_build::bridge("src/lib.rs"); - - println!("cargo:rerun-if-changed=src/lib.rs"); -} diff --git a/rust_part/src/lib.rs b/rust_part/src/lib.rs deleted file mode 100644 index 2f4475f..0000000 --- a/rust_part/src/lib.rs +++ /dev/null @@ -1,100 +0,0 @@ -use std::fmt; - -#[cxx::bridge] -mod ffi { - #[namespace = "shared"] - struct Color { - r: u8, - g: u8, - b: u8, - } - - // #[namespace = "shared"] - // struct SharedThing { - // points: Box, - // persons: UniquePtr, - // pixels: Vec, - // } - - // unsafe extern "C++" { - // include!("cpp_part.h"); - // type Person; - - // fn get_name(person: &Person) -> &CxxString; - // fn make_person() -> UniquePtr; - // fn is_black(self: &Color) -> bool; - // } - - #[namespace = "rust_part"] - extern "Rust" { - // type Points; - // fn print_shared_thing(points: &SharedThing); - // fn make_shared_thing() -> SharedThing; - fn rust_echo(val: i32) -> i32; - } - - #[namespace = "shared"] - extern "Rust" { - fn is_white(self: &Color) -> bool; - } -} - -#[derive(Debug)] -pub struct Points { - x: Vec, - y: Vec, -} - -impl ffi::Color { - pub fn white() -> Self { - Self { - r: 255, - g: 255, - b: 255, - } - } - - pub fn black() -> Self { - Self { r: 0, g: 0, b: 0 } - } - - pub fn is_white(&self) -> bool { - self.r == 255 && self.g == 255 && self.b == 255 - } -} - -impl fmt::Debug for ffi::Color { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Color") - .field("r", &self.r) - .field("g", &self.g) - .field("b", &self.b) - .finish() - } -} - -// fn print_shared_thing(thing: &ffi::SharedThing) { -// println!("{:#?}", thing.points); -// println!( -// "Pixel 0 is white: {}, pixel is black: {}", -// thing.pixels[0].is_white(), -// thing.pixels[1].is_black() -// ); -// println!("{:#?}", ffi::get_name(thing.persons.as_ref().unwrap())); -// } - -// fn make_shared_thing() -> ffi::SharedThing { -// ffi::SharedThing { -// points: Box::new(Points { -// x: vec![1, 2, 3], -// y: vec![4, 5, 6], -// }), -// persons: ffi::make_person(), -// pixels: vec![ffi::Color::white(), ffi::Color::black()], -// } -// } - -#[inline(always)] -fn rust_echo(val: i32) -> i32 { - val -} diff --git a/src/cxx_test.cpp b/src/cxx_test.cpp deleted file mode 100644 index 24e5b45..0000000 --- a/src/cxx_test.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "rust_part.h" -#include - -int cpp_echo(int val) -{ - return val; -} - -int test_fun() -{ - int sum = 0; - for (int i = 0; i < 1000000; i += 1) - { - sum += rust_part::rust_echo(i); - } - return sum; -} - -int test_inline() -{ - int sum = 0; - for (int i = 0; i < 1000000; i += 1) - { - sum += cpp_echo(i); - } - return sum; -} - -void test_lto() -{ - auto t1 = std::chrono::high_resolution_clock::now(); - auto sum = test_fun(); - auto t2 = std::chrono::high_resolution_clock::now(); - - auto duration = std::chrono::duration_cast(t2 - t1).count(); - - std::cout << "Calling rust function" - << ", time elapsed: " << duration << " ns." << std::endl; - - t1 = std::chrono::high_resolution_clock::now(); - sum = test_inline(); - t2 = std::chrono::high_resolution_clock::now(); - duration = std::chrono::duration_cast(t2 - t1).count(); - - std::cout << "Calling c++ function" - << ", time elapsed: " << duration << " ns." << std::endl; -} \ No newline at end of file