diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ lib/node_modules native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/target -native/cpp/CommonCpp/grpc/grpc_client/target web/node_modules web/dist diff --git a/native/cpp/CommonCpp/grpc/grpc_client/cxx.h b/native/cpp/CommonCpp/grpc/grpc_client/cxx.h deleted file mode 100644 --- a/native/cpp/CommonCpp/grpc/grpc_client/cxx.h +++ /dev/null @@ -1,1046 +0,0 @@ -#pragma once -#include <algorithm> -#include <array> -#include <cassert> -#include <cstddef> -#include <cstdint> -#include <exception> -#include <initializer_list> -#include <iosfwd> -#include <iterator> -#include <new> -#include <stdexcept> -#include <string> -#include <type_traits> -#include <utility> -#include <vector> -#if defined(_WIN32) -#include <basetsd.h> -#else -#include <sys/types.h> -#endif - -namespace rust { -inline namespace cxxbridge1 { - -struct unsafe_bitcopy_t; - -namespace { -template <typename T> class impl; -} - -#ifndef CXXBRIDGE1_RUST_STRING -#define CXXBRIDGE1_RUST_STRING -// https://cxx.rs/binding/string.html -class String final { -public: - String() noexcept; - String(const String &) noexcept; - String(String &&) noexcept; - ~String() noexcept; - - String(const std::string &); - String(const char *); - String(const char *, std::size_t); - String(const char16_t *); - String(const char16_t *, std::size_t); - - // Replace invalid Unicode data with the replacement character (U+FFFD). - static String lossy(const std::string &) noexcept; - static String lossy(const char *) noexcept; - static String lossy(const char *, std::size_t) noexcept; - static String lossy(const char16_t *) noexcept; - static String lossy(const char16_t *, std::size_t) noexcept; - - String &operator=(const String &) &noexcept; - String &operator=(String &&) &noexcept; - - explicit operator std::string() const; - - // Note: no null terminator. - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - const char *c_str() noexcept; - - std::size_t capacity() const noexcept; - void reserve(size_t new_cap) noexcept; - - using iterator = char *; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const String &) const noexcept; - bool operator!=(const String &) const noexcept; - bool operator<(const String &) const noexcept; - bool operator<=(const String &) const noexcept; - bool operator>(const String &) const noexcept; - bool operator>=(const String &) const noexcept; - - void swap(String &) noexcept; - - // Internal API only intended for the cxxbridge code generator. - String(unsafe_bitcopy_t, const String &) noexcept; - -private: - struct lossy_t; - String(lossy_t, const char *, std::size_t) noexcept; - String(lossy_t, const char16_t *, std::size_t) noexcept; - friend void swap(String &lhs, String &rhs) noexcept { - lhs.swap(rhs); - } - - // Size and alignment statically verified by rust_string.rs. - std::array<std::uintptr_t, 3> repr; -}; -#endif // CXXBRIDGE1_RUST_STRING - -#ifndef CXXBRIDGE1_RUST_STR -#define CXXBRIDGE1_RUST_STR -// https://cxx.rs/binding/str.html -class Str final { -public: - Str() noexcept; - Str(const String &) noexcept; - Str(const std::string &); - Str(const char *); - Str(const char *, std::size_t); - - Str &operator=(const Str &) &noexcept = default; - - explicit operator std::string() const; - - // Note: no null terminator. - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - // Important in order for System V ABI to pass in registers. - Str(const Str &) noexcept = default; - ~Str() noexcept = default; - - using iterator = const char *; - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const Str &) const noexcept; - bool operator!=(const Str &) const noexcept; - bool operator<(const Str &) const noexcept; - bool operator<=(const Str &) const noexcept; - bool operator>(const Str &) const noexcept; - bool operator>=(const Str &) const noexcept; - - void swap(Str &) noexcept; - -private: - class uninit; - Str(uninit) noexcept; - friend impl<Str>; - - std::array<std::uintptr_t, 2> repr; -}; -#endif // CXXBRIDGE1_RUST_STR - -#ifndef CXXBRIDGE1_RUST_SLICE -namespace detail { -template <bool> struct copy_assignable_if {}; - -template <> struct copy_assignable_if<false> { - copy_assignable_if() noexcept = default; - copy_assignable_if(const copy_assignable_if &) noexcept = default; - copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete; - copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default; -}; -} // namespace detail - -// https://cxx.rs/binding/slice.html -template <typename T> -class Slice final - : private detail::copy_assignable_if<std::is_const<T>::value> { -public: - using value_type = T; - - Slice() noexcept; - Slice(T *, std::size_t count) noexcept; - - Slice &operator=(const Slice<T> &) &noexcept = default; - Slice &operator=(Slice<T> &&) &noexcept = default; - - T *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - T &operator[](std::size_t n) const noexcept; - T &at(std::size_t n) const; - T &front() const noexcept; - T &back() const noexcept; - - // Important in order for System V ABI to pass in registers. - Slice(const Slice<T> &) noexcept = default; - ~Slice() noexcept = default; - - class iterator; - iterator begin() const noexcept; - iterator end() const noexcept; - - void swap(Slice &) noexcept; - -private: - class uninit; - Slice(uninit) noexcept; - friend impl<Slice>; - friend void sliceInit(void *, const void *, std::size_t) noexcept; - friend void *slicePtr(const void *) noexcept; - friend std::size_t sliceLen(const void *) noexcept; - - std::array<std::uintptr_t, 2> repr; -}; - -template <typename T> class Slice<T>::iterator final { -public: - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = typename std::add_pointer<T>::type; - using reference = typename std::add_lvalue_reference<T>::type; - - reference operator*() const noexcept; - pointer operator->() const noexcept; - reference operator[](difference_type) const noexcept; - - iterator &operator++() noexcept; - iterator operator++(int) noexcept; - iterator &operator--() noexcept; - iterator operator--(int) noexcept; - - iterator &operator+=(difference_type) noexcept; - iterator &operator-=(difference_type) noexcept; - iterator operator+(difference_type) const noexcept; - iterator operator-(difference_type) const noexcept; - difference_type operator-(const iterator &) const noexcept; - - bool operator==(const iterator &) const noexcept; - bool operator!=(const iterator &) const noexcept; - bool operator<(const iterator &) const noexcept; - bool operator<=(const iterator &) const noexcept; - bool operator>(const iterator &) const noexcept; - bool operator>=(const iterator &) const noexcept; - -private: - friend class Slice; - void *pos; - std::size_t stride; -}; -#endif // CXXBRIDGE1_RUST_SLICE - -#ifndef CXXBRIDGE1_RUST_BOX -// https://cxx.rs/binding/box.html -template <typename T> class Box final { -public: - using element_type = T; - using const_pointer = - typename std::add_pointer<typename std::add_const<T>::type>::type; - using pointer = typename std::add_pointer<T>::type; - - Box() = delete; - Box(Box &&) noexcept; - ~Box() noexcept; - - explicit Box(const T &); - explicit Box(T &&); - - Box &operator=(Box &&) &noexcept; - - const T *operator->() const noexcept; - const T &operator*() const noexcept; - T *operator->() noexcept; - T &operator*() noexcept; - - template <typename... Fields> static Box in_place(Fields &&...); - - void swap(Box &) noexcept; - - // Important: requires that `raw` came from an into_raw call. Do not pass a - // pointer from `new` or any other source. - static Box from_raw(T *) noexcept; - - T *into_raw() noexcept; - - /* Deprecated */ using value_type = element_type; - -private: - class uninit; - class allocation; - Box(uninit) noexcept; - void drop() noexcept; - - friend void swap(Box &lhs, Box &rhs) noexcept { - lhs.swap(rhs); - } - - T *ptr; -}; -#endif // CXXBRIDGE1_RUST_BOX - -#ifndef CXXBRIDGE1_RUST_VEC -// https://cxx.rs/binding/vec.html -template <typename T> class Vec final { -public: - using value_type = T; - - Vec() noexcept; - Vec(std::initializer_list<T>); - Vec(const Vec &); - Vec(Vec &&) noexcept; - ~Vec() noexcept; - - Vec &operator=(Vec &&) &noexcept; - Vec &operator=(const Vec &) &; - - std::size_t size() const noexcept; - bool empty() const noexcept; - const T *data() const noexcept; - T *data() noexcept; - std::size_t capacity() const noexcept; - - const T &operator[](std::size_t n) const noexcept; - const T &at(std::size_t n) const; - const T &front() const noexcept; - const T &back() const noexcept; - - T &operator[](std::size_t n) noexcept; - T &at(std::size_t n); - T &front() noexcept; - T &back() noexcept; - - void reserve(std::size_t new_cap); - void push_back(const T &value); - void push_back(T &&value); - template <typename... Args> void emplace_back(Args &&...args); - void truncate(std::size_t len); - void clear(); - - using iterator = typename Slice<T>::iterator; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = typename Slice<const T>::iterator; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - void swap(Vec &) noexcept; - - // Internal API only intended for the cxxbridge code generator. - Vec(unsafe_bitcopy_t, const Vec &) noexcept; - -private: - void reserve_total(std::size_t new_cap) noexcept; - void set_len(std::size_t len) noexcept; - void drop() noexcept; - - friend void swap(Vec &lhs, Vec &rhs) noexcept { - lhs.swap(rhs); - } - - // Size and alignment statically verified by rust_vec.rs. - std::array<std::uintptr_t, 3> repr; -}; -#endif // CXXBRIDGE1_RUST_VEC - -#ifndef CXXBRIDGE1_RUST_FN -// https://cxx.rs/binding/fn.html -template <typename Signature> class Fn; - -template <typename Ret, typename... Args> class Fn<Ret(Args...)> final { -public: - Ret operator()(Args... args) const noexcept; - Fn operator*() const noexcept; - -private: - Ret (*trampoline)(Args..., void *fn) noexcept; - void *fn; -}; -#endif // CXXBRIDGE1_RUST_FN - -#ifndef CXXBRIDGE1_RUST_ERROR -#define CXXBRIDGE1_RUST_ERROR -// https://cxx.rs/binding/result.html -class Error final : public std::exception { -public: - Error(const Error &); - Error(Error &&) noexcept; - ~Error() noexcept override; - - Error &operator=(const Error &) &; - Error &operator=(Error &&) &noexcept; - - const char *what() const noexcept override; - -private: - Error() noexcept = default; - friend impl<Error>; - const char *msg; - std::size_t len; -}; -#endif // CXXBRIDGE1_RUST_ERROR - -#ifndef CXXBRIDGE1_RUST_ISIZE -#define CXXBRIDGE1_RUST_ISIZE -#if defined(_WIN32) -using isize = SSIZE_T; -#else -using isize = ssize_t; -#endif -#endif // CXXBRIDGE1_RUST_ISIZE - -std::ostream &operator<<(std::ostream &, const String &); -std::ostream &operator<<(std::ostream &, const Str &); - -#ifndef CXXBRIDGE1_RUST_OPAQUE -#define CXXBRIDGE1_RUST_OPAQUE -// Base class of generated opaque Rust types. -class Opaque { -public: - Opaque() = delete; - Opaque(const Opaque &) = delete; - ~Opaque() = delete; -}; -#endif // CXXBRIDGE1_RUST_OPAQUE - -template <typename T> std::size_t size_of(); -template <typename T> std::size_t align_of(); - -// IsRelocatable<T> is used in assertions that a C++ type passed by value -// between Rust and C++ is soundly relocatable by Rust. -// -// There may be legitimate reasons to opt out of the check for support of types -// that the programmer knows are soundly Rust-movable despite not being -// recognized as such by the C++ type system due to a move constructor or -// destructor. To opt out of the relocatability check, do either of the -// following things in any header used by `include!` in the bridge. -// -// --- if you define the type: -// struct MyType { -// ... -// + using IsRelocatable = std::true_type; -// }; -// -// --- otherwise: -// + template <> -// + struct rust::IsRelocatable<MyType> : std::true_type {}; -template <typename T> struct IsRelocatable; - -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; -using usize = std::size_t; // see static asserts in cxx.cc -using i8 = std::int8_t; -using i16 = std::int16_t; -using i32 = std::int32_t; -using i64 = std::int64_t; -using f32 = float; -using f64 = double; - -// Snake case aliases for use in code that uses this style for type names. -using string = String; -using str = Str; -template <typename T> using slice = Slice<T>; -template <typename T> using box = Box<T>; -template <typename T> using vec = Vec<T>; -using error = Error; -template <typename Signature> using fn = Fn<Signature>; -template <typename T> using is_relocatable = IsRelocatable<T>; - -//////////////////////////////////////////////////////////////////////////////// -/// end public API, begin implementation details - -#ifndef CXXBRIDGE1_PANIC -#define CXXBRIDGE1_PANIC -template <typename Exception> void panic [[noreturn]] (const char *msg); -#endif // CXXBRIDGE1_PANIC - -#ifndef CXXBRIDGE1_RUST_FN -#define CXXBRIDGE1_RUST_FN -template <typename Ret, typename... Args> -Ret Fn<Ret(Args...)>::operator()(Args... args) const noexcept { - return (*this->trampoline)(std::forward<Args>(args)..., this->fn); -} - -template <typename Ret, typename... Args> -Fn<Ret(Args...)> Fn<Ret(Args...)>::operator*() const noexcept { - return *this; -} -#endif // CXXBRIDGE1_RUST_FN - -#ifndef CXXBRIDGE1_RUST_BITCOPY_T -#define CXXBRIDGE1_RUST_BITCOPY_T -struct unsafe_bitcopy_t final { - explicit unsafe_bitcopy_t() = default; -}; -#endif // CXXBRIDGE1_RUST_BITCOPY_T - -#ifndef CXXBRIDGE1_RUST_BITCOPY -#define CXXBRIDGE1_RUST_BITCOPY -constexpr unsafe_bitcopy_t unsafe_bitcopy{}; -#endif // CXXBRIDGE1_RUST_BITCOPY - -#ifndef CXXBRIDGE1_RUST_SLICE -#define CXXBRIDGE1_RUST_SLICE -template <typename T> Slice<T>::Slice() noexcept { - sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0); -} - -template <typename T> Slice<T>::Slice(T *s, std::size_t count) noexcept { - assert(s != nullptr || count == 0); - sliceInit( - this, - s == nullptr && count == 0 - ? reinterpret_cast<void *>(align_of<T>()) - : const_cast<typename std::remove_const<T>::type *>(s), - count); -} - -template <typename T> T *Slice<T>::data() const noexcept { - return reinterpret_cast<T *>(slicePtr(this)); -} - -template <typename T> std::size_t Slice<T>::size() const noexcept { - return sliceLen(this); -} - -template <typename T> std::size_t Slice<T>::length() const noexcept { - return this->size(); -} - -template <typename T> bool Slice<T>::empty() const noexcept { - return this->size() == 0; -} - -template <typename T> T &Slice<T>::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n; - return *reinterpret_cast<T *>(ptr); -} - -template <typename T> T &Slice<T>::at(std::size_t n) const { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Slice index out of range"); - } - return (*this)[n]; -} - -template <typename T> T &Slice<T>::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> T &Slice<T>::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> -typename Slice<T>::iterator::reference -Slice<T>::iterator::operator*() const noexcept { - return *static_cast<T *>(this->pos); -} - -template <typename T> -typename Slice<T>::iterator::pointer -Slice<T>::iterator::operator->() const noexcept { - return static_cast<T *>(this->pos); -} - -template <typename T> -typename Slice<T>::iterator::reference Slice<T>::iterator::operator[]( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ptr = static_cast<char *>(this->pos) + this->stride * n; - return *reinterpret_cast<T *>(ptr); -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept { - this->pos = static_cast<char *>(this->pos) + this->stride; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast<char *>(this->pos) + this->stride; - return ret; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept { - this->pos = static_cast<char *>(this->pos) - this->stride; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast<char *>(this->pos) - this->stride; - return ret; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator+=( - typename Slice<T>::iterator::difference_type n) noexcept { - this->pos = static_cast<char *>(this->pos) + this->stride * n; - return *this; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator-=( - typename Slice<T>::iterator::difference_type n) noexcept { - this->pos = static_cast<char *>(this->pos) - this->stride * n; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator+( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast<char *>(this->pos) + this->stride * n; - return ret; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator-( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast<char *>(this->pos) - this->stride * n; - return ret; -} - -template <typename T> -typename Slice<T>::iterator::difference_type -Slice<T>::iterator::operator-(const iterator &other) const noexcept { - auto diff = std::distance( - static_cast<char *>(other.pos), static_cast<char *>(this->pos)); - return diff / this->stride; -} - -template <typename T> -bool Slice<T>::iterator::operator==(const iterator &other) const noexcept { - return this->pos == other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept { - return this->pos != other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator<(const iterator &other) const noexcept { - return this->pos < other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept { - return this->pos <= other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator>(const iterator &other) const noexcept { - return this->pos > other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept { - return this->pos >= other.pos; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::begin() const noexcept { - iterator it; - it.pos = slicePtr(this); - it.stride = size_of<T>(); - return it; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::end() const noexcept { - iterator it = this->begin(); - it.pos = static_cast<char *>(it.pos) + it.stride * this->size(); - return it; -} - -template <typename T> void Slice<T>::swap(Slice &rhs) noexcept { - std::swap(*this, rhs); -} -#endif // CXXBRIDGE1_RUST_SLICE - -#ifndef CXXBRIDGE1_RUST_BOX -#define CXXBRIDGE1_RUST_BOX -template <typename T> class Box<T>::uninit {}; - -template <typename T> class Box<T>::allocation { - static T *alloc() noexcept; - static void dealloc(T *) noexcept; - -public: - allocation() noexcept : ptr(alloc()) { - } - ~allocation() noexcept { - if (this->ptr) { - dealloc(this->ptr); - } - } - T *ptr; -}; - -template <typename T> Box<T>::Box(Box &&other) noexcept : ptr(other.ptr) { - other.ptr = nullptr; -} - -template <typename T> Box<T>::Box(const T &val) { - allocation alloc; - ::new (alloc.ptr) T(val); - this->ptr = alloc.ptr; - alloc.ptr = nullptr; -} - -template <typename T> Box<T>::Box(T &&val) { - allocation alloc; - ::new (alloc.ptr) T(std::move(val)); - this->ptr = alloc.ptr; - alloc.ptr = nullptr; -} - -template <typename T> Box<T>::~Box() noexcept { - if (this->ptr) { - this->drop(); - } -} - -template <typename T> Box<T> &Box<T>::operator=(Box &&other) &noexcept { - if (this->ptr) { - this->drop(); - } - this->ptr = other.ptr; - other.ptr = nullptr; - return *this; -} - -template <typename T> const T *Box<T>::operator->() const noexcept { - return this->ptr; -} - -template <typename T> const T &Box<T>::operator*() const noexcept { - return *this->ptr; -} - -template <typename T> T *Box<T>::operator->() noexcept { - return this->ptr; -} - -template <typename T> T &Box<T>::operator*() noexcept { - return *this->ptr; -} - -template <typename T> -template <typename... Fields> -Box<T> Box<T>::in_place(Fields &&...fields) { - allocation alloc; - auto ptr = alloc.ptr; - ::new (ptr) T{std::forward<Fields>(fields)...}; - alloc.ptr = nullptr; - return from_raw(ptr); -} - -template <typename T> void Box<T>::swap(Box &rhs) noexcept { - using std::swap; - swap(this->ptr, rhs.ptr); -} - -template <typename T> Box<T> Box<T>::from_raw(T *raw) noexcept { - Box box = uninit{}; - box.ptr = raw; - return box; -} - -template <typename T> T *Box<T>::into_raw() noexcept { - T *raw = this->ptr; - this->ptr = nullptr; - return raw; -} - -template <typename T> Box<T>::Box(uninit) noexcept { -} -#endif // CXXBRIDGE1_RUST_BOX - -#ifndef CXXBRIDGE1_RUST_VEC -#define CXXBRIDGE1_RUST_VEC -template <typename T> Vec<T>::Vec(std::initializer_list<T> init) : Vec{} { - this->reserve_total(init.size()); - std::move(init.begin(), init.end(), std::back_inserter(*this)); -} - -template <typename T> Vec<T>::Vec(const Vec &other) : Vec() { - this->reserve_total(other.size()); - std::copy(other.begin(), other.end(), std::back_inserter(*this)); -} - -template <typename T> Vec<T>::Vec(Vec &&other) noexcept : repr(other.repr) { - new (&other) Vec(); -} - -template <typename T> Vec<T>::~Vec() noexcept { - this->drop(); -} - -template <typename T> Vec<T> &Vec<T>::operator=(Vec &&other) &noexcept { - this->drop(); - this->repr = other.repr; - new (&other) Vec(); - return *this; -} - -template <typename T> Vec<T> &Vec<T>::operator=(const Vec &other) & { - if (this != &other) { - this->drop(); - new (this) Vec(other); - } - return *this; -} - -template <typename T> bool Vec<T>::empty() const noexcept { - return this->size() == 0; -} - -template <typename T> T *Vec<T>::data() noexcept { - return const_cast<T *>(const_cast<const Vec<T> *>(this)->data()); -} - -template <typename T> -const T &Vec<T>::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto data = reinterpret_cast<const char *>(this->data()); - return *reinterpret_cast<const T *>(data + n * size_of<T>()); -} - -template <typename T> const T &Vec<T>::at(std::size_t n) const { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Vec index out of range"); - } - return (*this)[n]; -} - -template <typename T> const T &Vec<T>::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> const T &Vec<T>::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> T &Vec<T>::operator[](std::size_t n) noexcept { - assert(n < this->size()); - auto data = reinterpret_cast<char *>(this->data()); - return *reinterpret_cast<T *>(data + n * size_of<T>()); -} - -template <typename T> T &Vec<T>::at(std::size_t n) { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Vec index out of range"); - } - return (*this)[n]; -} - -template <typename T> T &Vec<T>::front() noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> T &Vec<T>::back() noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> void Vec<T>::reserve(std::size_t new_cap) { - this->reserve_total(new_cap); -} - -template <typename T> void Vec<T>::push_back(const T &value) { - this->emplace_back(value); -} - -template <typename T> void Vec<T>::push_back(T &&value) { - this->emplace_back(std::move(value)); -} - -template <typename T> -template <typename... Args> -void Vec<T>::emplace_back(Args &&...args) { - auto size = this->size(); - this->reserve_total(size + 1); - ::new (reinterpret_cast<T *>( - reinterpret_cast<char *>(this->data()) + size * size_of<T>())) - T(std::forward<Args>(args)...); - this->set_len(size + 1); -} - -template <typename T> void Vec<T>::clear() { - this->truncate(0); -} - -template <typename T> typename Vec<T>::iterator Vec<T>::begin() noexcept { - return Slice<T>(this->data(), this->size()).begin(); -} - -template <typename T> typename Vec<T>::iterator Vec<T>::end() noexcept { - return Slice<T>(this->data(), this->size()).end(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::begin() const noexcept { - return this->cbegin(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::end() const noexcept { - return this->cend(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::cbegin() const noexcept { - return Slice<const T>(this->data(), this->size()).begin(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::cend() const noexcept { - return Slice<const T>(this->data(), this->size()).end(); -} - -template <typename T> void Vec<T>::swap(Vec &rhs) noexcept { - using std::swap; - swap(this->repr, rhs.repr); -} - -// Internal API only intended for the cxxbridge code generator. -template <typename T> -Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) { -} -#endif // CXXBRIDGE1_RUST_VEC - -#ifndef CXXBRIDGE1_IS_COMPLETE -#define CXXBRIDGE1_IS_COMPLETE -namespace detail { -namespace { -template <typename T, typename = std::size_t> -struct is_complete : std::false_type {}; -template <typename T> -struct is_complete<T, decltype(sizeof(T))> : std::true_type {}; -} // namespace -} // namespace detail -#endif // CXXBRIDGE1_IS_COMPLETE - -#ifndef CXXBRIDGE1_LAYOUT -#define CXXBRIDGE1_LAYOUT -class layout { - template <typename T> friend std::size_t size_of(); - template <typename T> friend std::size_t align_of(); - template <typename T> - static typename std:: - enable_if<std::is_base_of<Opaque, T>::value, std::size_t>::type - do_size_of() { - return T::layout::size(); - } - template <typename T> - static typename std:: - enable_if<!std::is_base_of<Opaque, T>::value, std::size_t>::type - do_size_of() { - return sizeof(T); - } - template <typename T> - static - typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type - size_of() { - return do_size_of<T>(); - } - template <typename T> - static typename std:: - enable_if<std::is_base_of<Opaque, T>::value, std::size_t>::type - do_align_of() { - return T::layout::align(); - } - template <typename T> - static typename std:: - enable_if<!std::is_base_of<Opaque, T>::value, std::size_t>::type - do_align_of() { - return alignof(T); - } - template <typename T> - static - typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type - align_of() { - return do_align_of<T>(); - } -}; - -template <typename T> std::size_t size_of() { - return layout::size_of<T>(); -} - -template <typename T> std::size_t align_of() { - return layout::align_of<T>(); -} -#endif // CXXBRIDGE1_LAYOUT - -#ifndef CXXBRIDGE1_RELOCATABLE -#define CXXBRIDGE1_RELOCATABLE -namespace detail { -template <typename... Ts> struct make_void { - using type = void; -}; - -template <typename... Ts> using void_t = typename make_void<Ts...>::type; - -template <typename Void, template <typename...> class, typename...> -struct detect : std::false_type {}; -template <template <typename...> class T, typename... A> -struct detect<void_t<T<A...>>, T, A...> : std::true_type {}; - -template <template <typename...> class T, typename... A> -using is_detected = detect<void, T, A...>; - -template <typename T> using detect_IsRelocatable = typename T::IsRelocatable; - -template <typename T> -struct get_IsRelocatable - : std::is_same<typename T::IsRelocatable, std::true_type> {}; -} // namespace detail - -template <typename T> -struct IsRelocatable - : std::conditional< - detail::is_detected<detail::detect_IsRelocatable, T>::value, - detail::get_IsRelocatable<T>, - std::integral_constant< - bool, - std::is_trivially_move_constructible<T>::value && - std::is_trivially_destructible<T>::value>>::type {}; -#endif // CXXBRIDGE1_RELOCATABLE - -} // namespace cxxbridge1 -} // namespace rust diff --git a/native/cpp/CommonCpp/grpc/grpc_client/lib.rs.h b/native/cpp/CommonCpp/grpc/grpc_client/lib.rs.h deleted file mode 100644 --- a/native/cpp/CommonCpp/grpc/grpc_client/lib.rs.h +++ /dev/null @@ -1,871 +0,0 @@ -#pragma once -#include <algorithm> -#include <array> -#include <cassert> -#include <cstddef> -#include <cstdint> -#include <initializer_list> -#include <iterator> -#include <new> -#include <stdexcept> -#include <string> -#include <type_traits> -#include <utility> - -namespace rust { -inline namespace cxxbridge1 { -// #include "rust/cxx.h" - -#ifndef CXXBRIDGE1_PANIC -#define CXXBRIDGE1_PANIC -template <typename Exception> void panic [[noreturn]] (const char *msg); -#endif // CXXBRIDGE1_PANIC - -struct unsafe_bitcopy_t; - -namespace { -template <typename T> class impl; -} // namespace - -template <typename T>::std::size_t size_of(); -template <typename T>::std::size_t align_of(); - -#ifndef CXXBRIDGE1_RUST_STRING -#define CXXBRIDGE1_RUST_STRING -class String final { -public: - String() noexcept; - String(const String &) noexcept; - String(String &&) noexcept; - ~String() noexcept; - - String(const std::string &); - String(const char *); - String(const char *, std::size_t); - String(const char16_t *); - String(const char16_t *, std::size_t); - - static String lossy(const std::string &) noexcept; - static String lossy(const char *) noexcept; - static String lossy(const char *, std::size_t) noexcept; - static String lossy(const char16_t *) noexcept; - static String lossy(const char16_t *, std::size_t) noexcept; - - String &operator=(const String &) &noexcept; - String &operator=(String &&) &noexcept; - - explicit operator std::string() const; - - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - const char *c_str() noexcept; - - std::size_t capacity() const noexcept; - void reserve(size_t new_cap) noexcept; - - using iterator = char *; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const String &) const noexcept; - bool operator!=(const String &) const noexcept; - bool operator<(const String &) const noexcept; - bool operator<=(const String &) const noexcept; - bool operator>(const String &) const noexcept; - bool operator>=(const String &) const noexcept; - - void swap(String &) noexcept; - - String(unsafe_bitcopy_t, const String &) noexcept; - -private: - struct lossy_t; - String(lossy_t, const char *, std::size_t) noexcept; - String(lossy_t, const char16_t *, std::size_t) noexcept; - friend void swap(String &lhs, String &rhs) noexcept { - lhs.swap(rhs); - } - - std::array<std::uintptr_t, 3> repr; -}; -#endif // CXXBRIDGE1_RUST_STRING - -#ifndef CXXBRIDGE1_RUST_SLICE -#define CXXBRIDGE1_RUST_SLICE -namespace detail { -template <bool> struct copy_assignable_if {}; - -template <> struct copy_assignable_if<false> { - copy_assignable_if() noexcept = default; - copy_assignable_if(const copy_assignable_if &) noexcept = default; - copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete; - copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default; -}; -} // namespace detail - -template <typename T> -class Slice final - : private detail::copy_assignable_if<std::is_const<T>::value> { -public: - using value_type = T; - - Slice() noexcept; - Slice(T *, std::size_t count) noexcept; - - Slice &operator=(const Slice<T> &) &noexcept = default; - Slice &operator=(Slice<T> &&) &noexcept = default; - - T *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - T &operator[](std::size_t n) const noexcept; - T &at(std::size_t n) const; - T &front() const noexcept; - T &back() const noexcept; - - Slice(const Slice<T> &) noexcept = default; - ~Slice() noexcept = default; - - class iterator; - iterator begin() const noexcept; - iterator end() const noexcept; - - void swap(Slice &) noexcept; - -private: - class uninit; - Slice(uninit) noexcept; - friend impl<Slice>; - friend void sliceInit(void *, const void *, std::size_t) noexcept; - friend void *slicePtr(const void *) noexcept; - friend std::size_t sliceLen(const void *) noexcept; - - std::array<std::uintptr_t, 2> repr; -}; - -template <typename T> class Slice<T>::iterator final { -public: - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = typename std::add_pointer<T>::type; - using reference = typename std::add_lvalue_reference<T>::type; - - reference operator*() const noexcept; - pointer operator->() const noexcept; - reference operator[](difference_type) const noexcept; - - iterator &operator++() noexcept; - iterator operator++(int) noexcept; - iterator &operator--() noexcept; - iterator operator--(int) noexcept; - - iterator &operator+=(difference_type) noexcept; - iterator &operator-=(difference_type) noexcept; - iterator operator+(difference_type) const noexcept; - iterator operator-(difference_type) const noexcept; - difference_type operator-(const iterator &) const noexcept; - - bool operator==(const iterator &) const noexcept; - bool operator!=(const iterator &) const noexcept; - bool operator<(const iterator &) const noexcept; - bool operator<=(const iterator &) const noexcept; - bool operator>(const iterator &) const noexcept; - bool operator>=(const iterator &) const noexcept; - -private: - friend class Slice; - void *pos; - std::size_t stride; -}; - -template <typename T> Slice<T>::Slice() noexcept { - sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0); -} - -template <typename T> Slice<T>::Slice(T *s, std::size_t count) noexcept { - assert(s != nullptr || count == 0); - sliceInit( - this, - s == nullptr && count == 0 - ? reinterpret_cast<void *>(align_of<T>()) - : const_cast<typename std::remove_const<T>::type *>(s), - count); -} - -template <typename T> T *Slice<T>::data() const noexcept { - return reinterpret_cast<T *>(slicePtr(this)); -} - -template <typename T> std::size_t Slice<T>::size() const noexcept { - return sliceLen(this); -} - -template <typename T> std::size_t Slice<T>::length() const noexcept { - return this->size(); -} - -template <typename T> bool Slice<T>::empty() const noexcept { - return this->size() == 0; -} - -template <typename T> T &Slice<T>::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n; - return *reinterpret_cast<T *>(ptr); -} - -template <typename T> T &Slice<T>::at(std::size_t n) const { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Slice index out of range"); - } - return (*this)[n]; -} - -template <typename T> T &Slice<T>::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> T &Slice<T>::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> -typename Slice<T>::iterator::reference -Slice<T>::iterator::operator*() const noexcept { - return *static_cast<T *>(this->pos); -} - -template <typename T> -typename Slice<T>::iterator::pointer -Slice<T>::iterator::operator->() const noexcept { - return static_cast<T *>(this->pos); -} - -template <typename T> -typename Slice<T>::iterator::reference Slice<T>::iterator::operator[]( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ptr = static_cast<char *>(this->pos) + this->stride * n; - return *reinterpret_cast<T *>(ptr); -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept { - this->pos = static_cast<char *>(this->pos) + this->stride; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast<char *>(this->pos) + this->stride; - return ret; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept { - this->pos = static_cast<char *>(this->pos) - this->stride; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast<char *>(this->pos) - this->stride; - return ret; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator+=( - typename Slice<T>::iterator::difference_type n) noexcept { - this->pos = static_cast<char *>(this->pos) + this->stride * n; - return *this; -} - -template <typename T> -typename Slice<T>::iterator &Slice<T>::iterator::operator-=( - typename Slice<T>::iterator::difference_type n) noexcept { - this->pos = static_cast<char *>(this->pos) - this->stride * n; - return *this; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator+( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast<char *>(this->pos) + this->stride * n; - return ret; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::iterator::operator-( - typename Slice<T>::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast<char *>(this->pos) - this->stride * n; - return ret; -} - -template <typename T> -typename Slice<T>::iterator::difference_type -Slice<T>::iterator::operator-(const iterator &other) const noexcept { - auto diff = std::distance( - static_cast<char *>(other.pos), static_cast<char *>(this->pos)); - return diff / this->stride; -} - -template <typename T> -bool Slice<T>::iterator::operator==(const iterator &other) const noexcept { - return this->pos == other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept { - return this->pos != other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator<(const iterator &other) const noexcept { - return this->pos < other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept { - return this->pos <= other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator>(const iterator &other) const noexcept { - return this->pos > other.pos; -} - -template <typename T> -bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept { - return this->pos >= other.pos; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::begin() const noexcept { - iterator it; - it.pos = slicePtr(this); - it.stride = size_of<T>(); - return it; -} - -template <typename T> -typename Slice<T>::iterator Slice<T>::end() const noexcept { - iterator it = this->begin(); - it.pos = static_cast<char *>(it.pos) + it.stride * this->size(); - return it; -} - -template <typename T> void Slice<T>::swap(Slice &rhs) noexcept { - std::swap(*this, rhs); -} -#endif // CXXBRIDGE1_RUST_SLICE - -#ifndef CXXBRIDGE1_RUST_BOX -#define CXXBRIDGE1_RUST_BOX -template <typename T> class Box final { -public: - using element_type = T; - using const_pointer = - typename std::add_pointer<typename std::add_const<T>::type>::type; - using pointer = typename std::add_pointer<T>::type; - - Box() = delete; - Box(Box &&) noexcept; - ~Box() noexcept; - - explicit Box(const T &); - explicit Box(T &&); - - Box &operator=(Box &&) &noexcept; - - const T *operator->() const noexcept; - const T &operator*() const noexcept; - T *operator->() noexcept; - T &operator*() noexcept; - - template <typename... Fields> static Box in_place(Fields &&...); - - void swap(Box &) noexcept; - - static Box from_raw(T *) noexcept; - - T *into_raw() noexcept; - - /* Deprecated */ using value_type = element_type; - -private: - class uninit; - class allocation; - Box(uninit) noexcept; - void drop() noexcept; - - friend void swap(Box &lhs, Box &rhs) noexcept { - lhs.swap(rhs); - } - - T *ptr; -}; - -template <typename T> class Box<T>::uninit {}; - -template <typename T> class Box<T>::allocation { - static T *alloc() noexcept; - static void dealloc(T *) noexcept; - -public: - allocation() noexcept : ptr(alloc()) { - } - ~allocation() noexcept { - if (this->ptr) { - dealloc(this->ptr); - } - } - T *ptr; -}; - -template <typename T> Box<T>::Box(Box &&other) noexcept : ptr(other.ptr) { - other.ptr = nullptr; -} - -template <typename T> Box<T>::Box(const T &val) { - allocation alloc; - ::new (alloc.ptr) T(val); - this->ptr = alloc.ptr; - alloc.ptr = nullptr; -} - -template <typename T> Box<T>::Box(T &&val) { - allocation alloc; - ::new (alloc.ptr) T(std::move(val)); - this->ptr = alloc.ptr; - alloc.ptr = nullptr; -} - -template <typename T> Box<T>::~Box() noexcept { - if (this->ptr) { - this->drop(); - } -} - -template <typename T> Box<T> &Box<T>::operator=(Box &&other) &noexcept { - if (this->ptr) { - this->drop(); - } - this->ptr = other.ptr; - other.ptr = nullptr; - return *this; -} - -template <typename T> const T *Box<T>::operator->() const noexcept { - return this->ptr; -} - -template <typename T> const T &Box<T>::operator*() const noexcept { - return *this->ptr; -} - -template <typename T> T *Box<T>::operator->() noexcept { - return this->ptr; -} - -template <typename T> T &Box<T>::operator*() noexcept { - return *this->ptr; -} - -template <typename T> -template <typename... Fields> -Box<T> Box<T>::in_place(Fields &&...fields) { - allocation alloc; - auto ptr = alloc.ptr; - ::new (ptr) T{std::forward<Fields>(fields)...}; - alloc.ptr = nullptr; - return from_raw(ptr); -} - -template <typename T> void Box<T>::swap(Box &rhs) noexcept { - using std::swap; - swap(this->ptr, rhs.ptr); -} - -template <typename T> Box<T> Box<T>::from_raw(T *raw) noexcept { - Box box = uninit{}; - box.ptr = raw; - return box; -} - -template <typename T> T *Box<T>::into_raw() noexcept { - T *raw = this->ptr; - this->ptr = nullptr; - return raw; -} - -template <typename T> Box<T>::Box(uninit) noexcept { -} -#endif // CXXBRIDGE1_RUST_BOX - -#ifndef CXXBRIDGE1_RUST_BITCOPY_T -#define CXXBRIDGE1_RUST_BITCOPY_T -struct unsafe_bitcopy_t final { - explicit unsafe_bitcopy_t() = default; -}; -#endif // CXXBRIDGE1_RUST_BITCOPY_T - -#ifndef CXXBRIDGE1_RUST_VEC -#define CXXBRIDGE1_RUST_VEC -template <typename T> class Vec final { -public: - using value_type = T; - - Vec() noexcept; - Vec(std::initializer_list<T>); - Vec(const Vec &); - Vec(Vec &&) noexcept; - ~Vec() noexcept; - - Vec &operator=(Vec &&) &noexcept; - Vec &operator=(const Vec &) &; - - std::size_t size() const noexcept; - bool empty() const noexcept; - const T *data() const noexcept; - T *data() noexcept; - std::size_t capacity() const noexcept; - - const T &operator[](std::size_t n) const noexcept; - const T &at(std::size_t n) const; - const T &front() const noexcept; - const T &back() const noexcept; - - T &operator[](std::size_t n) noexcept; - T &at(std::size_t n); - T &front() noexcept; - T &back() noexcept; - - void reserve(std::size_t new_cap); - void push_back(const T &value); - void push_back(T &&value); - template <typename... Args> void emplace_back(Args &&...args); - void truncate(std::size_t len); - void clear(); - - using iterator = typename Slice<T>::iterator; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = typename Slice<const T>::iterator; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - void swap(Vec &) noexcept; - - Vec(unsafe_bitcopy_t, const Vec &) noexcept; - -private: - void reserve_total(std::size_t new_cap) noexcept; - void set_len(std::size_t len) noexcept; - void drop() noexcept; - - friend void swap(Vec &lhs, Vec &rhs) noexcept { - lhs.swap(rhs); - } - - std::array<std::uintptr_t, 3> repr; -}; - -template <typename T> Vec<T>::Vec(std::initializer_list<T> init) : Vec{} { - this->reserve_total(init.size()); - std::move(init.begin(), init.end(), std::back_inserter(*this)); -} - -template <typename T> Vec<T>::Vec(const Vec &other) : Vec() { - this->reserve_total(other.size()); - std::copy(other.begin(), other.end(), std::back_inserter(*this)); -} - -template <typename T> Vec<T>::Vec(Vec &&other) noexcept : repr(other.repr) { - new (&other) Vec(); -} - -template <typename T> Vec<T>::~Vec() noexcept { - this->drop(); -} - -template <typename T> Vec<T> &Vec<T>::operator=(Vec &&other) &noexcept { - this->drop(); - this->repr = other.repr; - new (&other) Vec(); - return *this; -} - -template <typename T> Vec<T> &Vec<T>::operator=(const Vec &other) & { - if (this != &other) { - this->drop(); - new (this) Vec(other); - } - return *this; -} - -template <typename T> bool Vec<T>::empty() const noexcept { - return this->size() == 0; -} - -template <typename T> T *Vec<T>::data() noexcept { - return const_cast<T *>(const_cast<const Vec<T> *>(this)->data()); -} - -template <typename T> -const T &Vec<T>::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto data = reinterpret_cast<const char *>(this->data()); - return *reinterpret_cast<const T *>(data + n * size_of<T>()); -} - -template <typename T> const T &Vec<T>::at(std::size_t n) const { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Vec index out of range"); - } - return (*this)[n]; -} - -template <typename T> const T &Vec<T>::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> const T &Vec<T>::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> T &Vec<T>::operator[](std::size_t n) noexcept { - assert(n < this->size()); - auto data = reinterpret_cast<char *>(this->data()); - return *reinterpret_cast<T *>(data + n * size_of<T>()); -} - -template <typename T> T &Vec<T>::at(std::size_t n) { - if (n >= this->size()) { - panic<std::out_of_range>("rust::Vec index out of range"); - } - return (*this)[n]; -} - -template <typename T> T &Vec<T>::front() noexcept { - assert(!this->empty()); - return (*this)[0]; -} - -template <typename T> T &Vec<T>::back() noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; -} - -template <typename T> void Vec<T>::reserve(std::size_t new_cap) { - this->reserve_total(new_cap); -} - -template <typename T> void Vec<T>::push_back(const T &value) { - this->emplace_back(value); -} - -template <typename T> void Vec<T>::push_back(T &&value) { - this->emplace_back(std::move(value)); -} - -template <typename T> -template <typename... Args> -void Vec<T>::emplace_back(Args &&...args) { - auto size = this->size(); - this->reserve_total(size + 1); - ::new (reinterpret_cast<T *>( - reinterpret_cast<char *>(this->data()) + size * size_of<T>())) - T(std::forward<Args>(args)...); - this->set_len(size + 1); -} - -template <typename T> void Vec<T>::clear() { - this->truncate(0); -} - -template <typename T> typename Vec<T>::iterator Vec<T>::begin() noexcept { - return Slice<T>(this->data(), this->size()).begin(); -} - -template <typename T> typename Vec<T>::iterator Vec<T>::end() noexcept { - return Slice<T>(this->data(), this->size()).end(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::begin() const noexcept { - return this->cbegin(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::end() const noexcept { - return this->cend(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::cbegin() const noexcept { - return Slice<const T>(this->data(), this->size()).begin(); -} - -template <typename T> -typename Vec<T>::const_iterator Vec<T>::cend() const noexcept { - return Slice<const T>(this->data(), this->size()).end(); -} - -template <typename T> void Vec<T>::swap(Vec &rhs) noexcept { - using std::swap; - swap(this->repr, rhs.repr); -} - -template <typename T> -Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) { -} -#endif // CXXBRIDGE1_RUST_VEC - -#ifndef CXXBRIDGE1_RUST_OPAQUE -#define CXXBRIDGE1_RUST_OPAQUE -class Opaque { -public: - Opaque() = delete; - Opaque(const Opaque &) = delete; - ~Opaque() = delete; -}; -#endif // CXXBRIDGE1_RUST_OPAQUE - -#ifndef CXXBRIDGE1_IS_COMPLETE -#define CXXBRIDGE1_IS_COMPLETE -namespace detail { -namespace { -template <typename T, typename = std::size_t> -struct is_complete : std::false_type {}; -template <typename T> -struct is_complete<T, decltype(sizeof(T))> : std::true_type {}; -} // namespace -} // namespace detail -#endif // CXXBRIDGE1_IS_COMPLETE - -#ifndef CXXBRIDGE1_LAYOUT -#define CXXBRIDGE1_LAYOUT -class layout { - template <typename T> friend std::size_t size_of(); - template <typename T> friend std::size_t align_of(); - template <typename T> - static typename std:: - enable_if<std::is_base_of<Opaque, T>::value, std::size_t>::type - do_size_of() { - return T::layout::size(); - } - template <typename T> - static typename std:: - enable_if<!std::is_base_of<Opaque, T>::value, std::size_t>::type - do_size_of() { - return sizeof(T); - } - template <typename T> - static - typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type - size_of() { - return do_size_of<T>(); - } - template <typename T> - static typename std:: - enable_if<std::is_base_of<Opaque, T>::value, std::size_t>::type - do_align_of() { - return T::layout::align(); - } - template <typename T> - static typename std:: - enable_if<!std::is_base_of<Opaque, T>::value, std::size_t>::type - do_align_of() { - return alignof(T); - } - template <typename T> - static - typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type - align_of() { - return do_align_of<T>(); - } -}; - -template <typename T> std::size_t size_of() { - return layout::size_of<T>(); -} - -template <typename T> std::size_t align_of() { - return layout::align_of<T>(); -} -#endif // CXXBRIDGE1_LAYOUT -} // namespace cxxbridge1 -} // namespace rust - -struct Client; - -#ifndef CXXBRIDGE1_STRUCT_Client -#define CXXBRIDGE1_STRUCT_Client -struct Client final : public ::rust::Opaque { - ~Client() = delete; - -private: - friend ::rust::layout; - struct layout { - static ::std::size_t size() noexcept; - static ::std::size_t align() noexcept; - }; -}; -#endif // CXXBRIDGE1_STRUCT_Client - -::rust::Box<::Client> initialize_client() noexcept; - -::rust::String get_user_id_blocking( - ::rust::Box<::Client> client, - ::std::int32_t auth_type, - ::rust::String user_info); - -bool verify_user_token_blocking( - ::rust::Box<::Client> client, - ::rust::String user_id, - ::rust::String device_id, - ::rust::String access_token); - -::rust::String register_user_blocking( - ::rust::Box<::Client> client, - ::rust::String user_id, - ::rust::String device_id, - ::rust::String username, - ::rust::String password, - ::rust::String user_public_key); - -::rust::String login_user_pake_blocking( - ::rust::Box<::Client> client, - ::rust::String user_id, - ::rust::String device_id, - ::rust::String password); - -::rust::String login_user_wallet_blocking( - ::rust::Box<::Client> client, - ::rust::String user_id, - ::rust::String device_id, - ::rust::String siwe_message, - ::rust::Vec<::std::uint8_t> siwe_signature, - ::rust::String user_public_key); diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -39,8 +39,8 @@ 7F8D602326535E060053CB29 /* OpenSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7F8D602026535E060053CB29 /* OpenSans-Regular.ttf */; }; 7F8D602826535F240053CB29 /* IBMPlexSans-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7F8D602726535EEE0053CB29 /* IBMPlexSans-Bold.ttf */; }; 7F8D602926535F2A0053CB29 /* IBMPlexSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7F8D602626535EEE0053CB29 /* IBMPlexSans-Regular.ttf */; }; - 8B99AF6628D5024800EB5ADB /* lib.rs.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8B99AF6428D5024700EB5ADB /* lib.rs.cc */; }; - 8BF9F24D28B7943000E20C13 /* libgrpc_client.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BF9F24C28B7943000E20C13 /* libgrpc_client.a */; }; + 8B99BAAC28D50F3000EB5ADB /* libnative_rust_library.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B99BAAB28D50F3000EB5ADB /* libnative_rust_library.a */; }; + 8B99BAAE28D511FF00EB5ADB /* lib.rs.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8B99BAAD28D511FF00EB5ADB /* lib.rs.cc */; }; B7162ABD28AAD461006588D3 /* CommIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B7162ABC28AAD461006588D3 /* CommIcons.ttf */; }; B71AFF1F265EDD8600B22352 /* IBMPlexSans-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B71AFF1E265EDD8600B22352 /* IBMPlexSans-Medium.ttf */; }; B734D11028ADD55200570D04 /* SWMansionIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B734D10F28ADD55200570D04 /* SWMansionIcons.ttf */; }; @@ -176,10 +176,10 @@ 7FCEA2DC2444010B004017B1 /* Comm-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Comm-Bridging-Header.h"; sourceTree = "<group>"; }; 7FCFD8BD1E81B8DF00629B0E /* Comm.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = Comm.entitlements; path = Comm/Comm.entitlements; sourceTree = "<group>"; }; 891D1495EE1F375F3AF6C7ED /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = "<group>"; }; - 8B15717B28CA442C00209C6A /* cxx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cxx.h; path = grpc_client/cxx.h; sourceTree = "<group>"; }; - 8B99AF6428D5024700EB5ADB /* lib.rs.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lib.rs.cc; path = grpc_client/lib.rs.cc; sourceTree = "<group>"; }; - 8B99AF6528D5024800EB5ADB /* lib.rs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lib.rs.h; path = grpc_client/lib.rs.h; sourceTree = "<group>"; }; - 8BF9F24C28B7943000E20C13 /* libgrpc_client.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgrpc_client.a; path = ../cpp/CommonCpp/grpc/grpc_client/target/universal/release/libgrpc_client.a; sourceTree = "<group>"; }; + 8B99AF6D28D50D4800EB5ADB /* lib.rs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lib.rs.h; sourceTree = "<group>"; }; + 8B99B59928D50D4900EB5ADB /* cxx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cxx.h; sourceTree = "<group>"; }; + 8B99BAAB28D50F3000EB5ADB /* libnative_rust_library.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libnative_rust_library.a; path = ../native_rust_library/target/universal/release/libnative_rust_library.a; sourceTree = "<group>"; }; + 8B99BAAD28D511FF00EB5ADB /* lib.rs.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lib.rs.cc; sourceTree = "<group>"; }; 913E5A7BDECB327E3DE11053 /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = "<group>"; }; 994BEBDD4E4959F69CEA0BC3 /* libPods-Comm.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Comm.a"; sourceTree = BUILT_PRODUCTS_DIR; }; B7055C6B26E477CF00BE0548 /* MessageStoreOperations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageStoreOperations.h; sourceTree = "<group>"; }; @@ -236,7 +236,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8BF9F24D28B7943000E20C13 /* libgrpc_client.a in Frameworks */, + 8B99BAAC28D50F3000EB5ADB /* libnative_rust_library.a in Frameworks */, 7F761E602201141E001B6FB7 /* JavaScriptCore.framework in Frameworks */, D7DB6E0F85B2DBE15B01EC21 /* libPods-Comm.a in Frameworks */, ); @@ -315,9 +315,6 @@ 718A3C0426F22BD100F04A8D /* grpc */ = { isa = PBXGroup; children = ( - 8B99AF6428D5024700EB5ADB /* lib.rs.cc */, - 8B99AF6528D5024800EB5ADB /* lib.rs.h */, - 8B15717B28CA442C00209C6A /* cxx.h */, 71009A7926FDCD71002C8453 /* Client.cpp */, 71009A7A26FDCD71002C8453 /* Client.h */, B7BEE744279B3E20009CCA35 /* GRPCStreamHostObject.cpp */, @@ -482,7 +479,7 @@ 7FF0870B1E833C3F000A1ACF /* Frameworks */ = { isa = PBXGroup; children = ( - 8BF9F24C28B7943000E20C13 /* libgrpc_client.a */, + 8B99BAAB28D50F3000EB5ADB /* libnative_rust_library.a */, CB3C621327CE66540054F24C /* libEXSecureStore.a */, 724995FA27BA9E8C00323FCE /* UserNotifications.framework */, 711CF80E25DC096000A00FBD /* libFolly.a */, @@ -496,6 +493,7 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( + 8B99AF6B28D50D4800EB5ADB /* native_rust_library */, FC2DF94E28BFCF5B0017C4AF /* shared */, 71BE84362636A944002849D2 /* cpp */, 13B07FAE1A68108700A75B9A /* Comm */, @@ -521,6 +519,17 @@ name = Products; sourceTree = "<group>"; }; + 8B99AF6B28D50D4800EB5ADB /* native_rust_library */ = { + isa = PBXGroup; + children = ( + 8B99BAAD28D511FF00EB5ADB /* lib.rs.cc */, + 8B99AF6D28D50D4800EB5ADB /* lib.rs.h */, + 8B99B59928D50D4900EB5ADB /* cxx.h */, + ); + name = native_rust_library; + path = ../native_rust_library; + sourceTree = "<group>"; + }; AFF3F1F76178B42122C79BDE /* ExpoModulesProviders */ = { isa = PBXGroup; children = ( @@ -879,7 +888,7 @@ outputFileListPaths = ( ); outputPaths = ( - "${SRCROOT}/../cpp/CommonCpp/grpc/grpc_client/lib.rs.cc", + "${SRCROOT}/../native_rust_library/lib.rs.cc", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -902,7 +911,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "${SRCROOT}/../../scripts/clean-up-rust-native-library.sh\n"; + shellScript = "${SRCROOT}/../../scripts/clean-up-native-rust-library.sh\n"; }; DB38BFA0686C805CE44F051F /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; @@ -1014,7 +1023,7 @@ CB38B48228771C7A00171182 /* NonBlockingLock.mm in Sources */, B7BEE749279B3FB6009CCA35 /* GRPCStreamHostObject.cpp in Sources */, 718DE99E2653D41C00365824 /* WorkerThread.cpp in Sources */, - 8B99AF6628D5024800EB5ADB /* lib.rs.cc in Sources */, + 8B99BAAE28D511FF00EB5ADB /* lib.rs.cc in Sources */, 71CA4AEC262F236100835C89 /* Tools.mm in Sources */, 71009A7B26FDCD72002C8453 /* Client.cpp in Sources */, 71762A75270D8AAE00F565ED /* PlatformSpecificTools.mm in Sources */, @@ -1118,7 +1127,7 @@ "$(inherited)", "$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS", "$(PODS_ROOT)/boost-for-react-native", - "$(SRCROOT)/../cpp/CommonCpp/grpc/grpc_client", + "$(SRCROOT)/../native_rust_library", ); INFOPLIST_FILE = Comm/Info.debug.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1216,7 +1225,7 @@ "\"${PODS_CONFIGURATION_BUILD_DIR}/react-native-safe-area-context\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/react-native-video\"", /usr/lib/swift, - "$(SRCROOT)/../cpp/CommonCpp/grpc/grpc_client/target/universal/release", + "$(SRCROOT)/../native_rust_library/target/universal/release", ); OTHER_CPLUSPLUSFLAGS = ( "-DFOLLY_MOBILE=1", @@ -1263,7 +1272,7 @@ "$(inherited)", "$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS", "$(PODS_ROOT)/boost-for-react-native", - "$(SRCROOT)/../cpp/CommonCpp/grpc/grpc_client", + "$(SRCROOT)/../native_rust_library", ); INFOPLIST_FILE = Comm/Info.release.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1352,7 +1361,7 @@ "\"${PODS_CONFIGURATION_BUILD_DIR}/react-native-safe-area-context\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/react-native-video\"", /usr/lib/swift, - "$(SRCROOT)/../cpp/CommonCpp/grpc/grpc_client/target/universal/release", + "$(SRCROOT)/../native_rust_library/target/universal/release", ); ONLY_ACTIVE_ARCH = YES; OTHER_CPLUSPLUSFLAGS = ( diff --git a/native/native_rust_library/.gitignore b/native/native_rust_library/.gitignore new file mode 100644 --- /dev/null +++ b/native/native_rust_library/.gitignore @@ -0,0 +1 @@ +target diff --git a/native/cpp/CommonCpp/grpc/grpc_client/Cargo.lock b/native/native_rust_library/Cargo.lock rename from native/cpp/CommonCpp/grpc/grpc_client/Cargo.lock rename to native/native_rust_library/Cargo.lock --- a/native/cpp/CommonCpp/grpc/grpc_client/Cargo.lock +++ b/native/native_rust_library/Cargo.lock @@ -4,9 +4,9 @@ [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "argon2" @@ -42,9 +42,9 @@ [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -59,9 +59,9 @@ [[package]] name = "axum" -version = "0.5.13" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9496f0c1d1afb7a2af4338bbe1d969cddfead41d87a9fb3aaa6d0bbc7af648" +checksum = "c9e3356844c4d6a6d6467b8da2cffb4a2820be256f50a3a386c9d152bab31043" dependencies = [ "async-trait", "axum-core", @@ -88,9 +88,9 @@ [[package]] name = "axum-core" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f44a0e6200e9d11a1cdc989e4b358f6e3d354fbf48478f345a17f4e43f8635" +checksum = "d9f0c0a60006f2a293d82d571f635042a72edf927539b7685bd62d361963839b" dependencies = [ "async-trait", "bytes", @@ -98,6 +98,8 @@ "http", "http-body", "mime", + "tower-layer", + "tower-service", ] [[package]] @@ -108,9 +110,9 @@ [[package]] name = "base64ct" -version = "1.0.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" +checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474" [[package]] name = "bitflags" @@ -124,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -153,9 +155,9 @@ [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" @@ -216,9 +218,9 @@ [[package]] name = "curve25519-dalek" -version = "3.2.0" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" dependencies = [ "byteorder", "digest 0.9.0", @@ -229,9 +231,9 @@ [[package]] name = "cxx" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c14d679239b1ccaad7acaf972a19b41b6c1d7a8cb942158294b4f11ec71bd8" +checksum = "8b7df2292959b7e22a5cb39d37b7e72b2c748b12f956cc409b529fddcdc8857b" dependencies = [ "cc", "cxxbridge-flags", @@ -241,9 +243,9 @@ [[package]] name = "cxx-build" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbee15c52b8d9132c62c341d2046885717e4a180eb9d3cd34c5a78f2669257" +checksum = "0806e5c64f74bd64b94d857b1c28cc3d493579a65f5f31e7d3451706d4025405" dependencies = [ "cc", "codespan-reporting", @@ -256,15 +258,15 @@ [[package]] name = "cxxbridge-flags" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fdfa84261f05a9b69c0afe03270f9f26d6899ca7df6f442563908b646e8a376" +checksum = "d2069b1573efd6e5901004e8fdca2e28bc6f47f86dc24da81182851e71cf3208" [[package]] name = "cxxbridge-macro" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0269826813dfbda75223169c774fede73401793e9af3970e4edbe93879782c1d" +checksum = "d980827d1ec28ea6e0db545fceaa611eb8e43f70eff8c1c33cc2c96ffa0f0476" dependencies = [ "proc-macro2", "quote", @@ -282,9 +284,9 @@ [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ "block-buffer 0.10.3", "crypto-common", @@ -304,9 +306,9 @@ [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "fastrand" @@ -331,36 +333,36 @@ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -400,32 +402,11 @@ "wasi 0.11.0+wasi-snapshot-preview1", ] -[[package]] -name = "grpc_client" -version = "0.1.0" -dependencies = [ - "argon2", - "curve25519-dalek", - "cxx", - "cxx-build", - "digest 0.9.0", - "lazy_static", - "opaque-ke", - "prost", - "rand", - "sha2", - "tokio", - "tokio-stream", - "tonic", - "tonic-build", - "tracing", -] - [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -511,9 +492,9 @@ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -578,18 +559,18 @@ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "d8bf247779e67a9082a4790b45e71ac7cfd1321331a5c856a74a9faebdab78d0" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "lazy_static" @@ -599,15 +580,15 @@ [[package]] name = "libc" -version = "0.2.126" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "link-cplusplus" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cae2cd7ba2f3f63938b9c724475dfb7b9861b545a90324476324ed21dbc8c8" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" dependencies = [ "cc", ] @@ -657,6 +638,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "native_rust_library" +version = "0.1.0" +dependencies = [ + "argon2", + "curve25519-dalek", + "cxx", + "cxx-build", + "digest 0.9.0", + "lazy_static", + "opaque-ke", + "prost", + "rand", + "sha2", + "tokio", + "tokio-stream", + "tonic", + "tonic-build", + "tracing", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -669,9 +671,9 @@ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "opaque-debug" @@ -704,15 +706,15 @@ checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core 0.6.3", + "rand_core 0.6.4", "subtle", ] [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "petgraph" @@ -726,18 +728,18 @@ [[package]] name = "pin-project" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", @@ -764,9 +766,9 @@ [[package]] name = "prettyplease" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffbe84bf1905c007253d1f10ffb85fbc8ca8624a40cff8f2ded6f36920e38e0" +checksum = "a49e86d2c26a24059894a3afa13fd17d063419b05dfb83f06d9c3566060c3f5a" dependencies = [ "proc-macro2", "syn", @@ -774,9 +776,9 @@ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] @@ -793,9 +795,9 @@ [[package]] name = "prost-build" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d49d928704208aba2cb1fb022ce1a319bdedcb03caf51ddf82734fa903407762" +checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" dependencies = [ "bytes", "heck", @@ -826,9 +828,9 @@ [[package]] name = "prost-types" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30bc806a29b347314be074ff0608ef8e547286e8ea68b061a2fe55689edc01f" +checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" dependencies = [ "bytes", "prost", @@ -836,9 +838,9 @@ [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -851,7 +853,7 @@ dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -861,7 +863,7 @@ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -875,9 +877,9 @@ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.7", ] @@ -917,15 +919,15 @@ [[package]] name = "scratch" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96311ef4a16462c757bb6a39152c40f58f31cd2602a40fceb937e2bc34e6cbab" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "serde" -version = "1.0.141" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7af873f2c95b99fcb0bd0fe622a43e29514658873c8ceba88c4cb88833a22500" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" [[package]] name = "sha2" @@ -951,9 +953,9 @@ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -967,9 +969,9 @@ [[package]] name = "syn" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", @@ -1019,9 +1021,9 @@ [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95" dependencies = [ "autocfg", "bytes", @@ -1070,9 +1072,9 @@ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -1084,9 +1086,9 @@ [[package]] name = "tonic" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "498f271adc46acce75d66f639e4d35b31b2394c295c82496727dafa16d465dd2" +checksum = "11cd56bdb54ef93935a6a79dbd1d91f1ebd4c64150fd61654031fd6b8b775c91" dependencies = [ "async-stream", "async-trait", @@ -1180,9 +1182,9 @@ [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "log", @@ -1204,9 +1206,9 @@ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -1235,21 +1237,21 @@ [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "version_check" @@ -1281,13 +1283,13 @@ [[package]] name = "which" -version = "4.2.5" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] @@ -1366,9 +1368,9 @@ [[package]] name = "zeroize" -version = "1.4.3" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" dependencies = [ "zeroize_derive", ] diff --git a/native/cpp/CommonCpp/grpc/grpc_client/Cargo.toml b/native/native_rust_library/Cargo.toml rename from native/cpp/CommonCpp/grpc/grpc_client/Cargo.toml rename to native/native_rust_library/Cargo.toml --- a/native/cpp/CommonCpp/grpc/grpc_client/Cargo.toml +++ b/native/native_rust_library/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "grpc_client" +name = "native_rust_library" version = "0.1.0" edition = "2021" license = "BSD-3-Clause" diff --git a/native/cpp/CommonCpp/grpc/grpc_client/build.rs b/native/native_rust_library/build.rs rename from native/cpp/CommonCpp/grpc/grpc_client/build.rs rename to native/native_rust_library/build.rs --- a/native/cpp/CommonCpp/grpc/grpc_client/build.rs +++ b/native/native_rust_library/build.rs @@ -1,5 +1,5 @@ fn main() { - tonic_build::compile_protos("../../../../../shared/protos/identity.proto") + tonic_build::compile_protos("../../shared/protos/identity.proto") .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e)); let _cxx_build = cxx_build::bridge("src/lib.rs").flag_if_supported("-std=c++14"); diff --git a/native/cpp/CommonCpp/grpc/grpc_client/src/identity_client.rs b/native/native_rust_library/src/identity_client.rs rename from native/cpp/CommonCpp/grpc/grpc_client/src/identity_client.rs rename to native/native_rust_library/src/identity_client.rs diff --git a/native/cpp/CommonCpp/grpc/grpc_client/src/lib.rs b/native/native_rust_library/src/lib.rs rename from native/cpp/CommonCpp/grpc/grpc_client/src/lib.rs rename to native/native_rust_library/src/lib.rs diff --git a/native/cpp/CommonCpp/grpc/grpc_client/src/opaque.rs b/native/native_rust_library/src/opaque.rs rename from native/cpp/CommonCpp/grpc/grpc_client/src/opaque.rs rename to native/native_rust_library/src/opaque.rs diff --git a/scripts/build-rust-native-library.sh b/scripts/build-rust-native-library.sh --- a/scripts/build-rust-native-library.sh +++ b/scripts/build-rust-native-library.sh @@ -7,7 +7,7 @@ # Note: This assumes a default `rustup` setup and default path. build_path="$HOME/.cargo/bin:/usr/local/bin:/usr/bin:/bin" # cd to Cargo project -cd "${SRCROOT}/../cpp/CommonCpp/grpc/grpc_client" || exit +cd "${SRCROOT}/../native_rust_library" || exit # Add iOS targets for cross-compilation env PATH="${build_path}" rustup target add aarch64-apple-ios env PATH="${build_path}" rustup target add x86_64-apple-ios @@ -22,6 +22,6 @@ unset CXXFLAGS # Copy the CXX files to the cargo project root to make them # available to XCode -cp "$(readlink target/cxxbridge/grpc_client/src/lib.rs.cc)" . -cp "$(readlink target/cxxbridge/grpc_client/src/lib.rs.h)" . +cp "$(readlink target/cxxbridge/native_rust_library/src/lib.rs.cc)" . +cp "$(readlink target/cxxbridge/native_rust_library/src/lib.rs.h)" . cp "$(readlink target/cxxbridge/rust/cxx.h)" . diff --git a/scripts/clean-up-native-rust-library.sh b/scripts/clean-up-native-rust-library.sh new file mode 100755 --- /dev/null +++ b/scripts/clean-up-native-rust-library.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +NATIVE_RUST_DIR="${SRCROOT}/../native_rust_library" +rm -vrf "${NATIVE_RUST_DIR}"/{cxx.h,lib.rs.{h,cc}} diff --git a/scripts/clean-up-rust-native-library.sh b/scripts/clean-up-rust-native-library.sh deleted file mode 100755 --- a/scripts/clean-up-rust-native-library.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -x -# cd to Cargo project -cd "${SRCROOT}/../cpp/CommonCpp/grpc/grpc_client" || exit -# Remove the generated files from root of Cargo project -rm lib.rs.cc