Vendor dependencies
Let's see how I like this workflow.
This commit is contained in:
parent
34d1830413
commit
9c435dc440
7500 changed files with 1665121 additions and 99 deletions
18
vendor/cxx/src/symbols/exception.rs
vendored
Normal file
18
vendor/cxx/src/symbols/exception.rs
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#![cfg(feature = "alloc")]
|
||||
|
||||
use crate::result::PtrLen;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
use core::ptr::NonNull;
|
||||
use core::slice;
|
||||
|
||||
#[export_name = "cxxbridge1$exception"]
|
||||
unsafe extern "C" fn exception(ptr: *const u8, len: usize) -> PtrLen {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
let string = String::from_utf8_lossy(slice);
|
||||
let len = string.len();
|
||||
let raw_str = Box::into_raw(string.into_owned().into_boxed_str());
|
||||
let raw_u8 = raw_str.cast::<u8>();
|
||||
let nonnull = unsafe { NonNull::new_unchecked(raw_u8) };
|
||||
PtrLen { ptr: nonnull, len }
|
||||
}
|
||||
5
vendor/cxx/src/symbols/mod.rs
vendored
Normal file
5
vendor/cxx/src/symbols/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod exception;
|
||||
mod rust_slice;
|
||||
mod rust_str;
|
||||
mod rust_string;
|
||||
mod rust_vec;
|
||||
20
vendor/cxx/src/symbols/rust_slice.rs
vendored
Normal file
20
vendor/cxx/src/symbols/rust_slice.rs
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use crate::rust_slice::RustSlice;
|
||||
use core::mem::MaybeUninit;
|
||||
use core::ptr::{self, NonNull};
|
||||
|
||||
#[export_name = "cxxbridge1$slice$new"]
|
||||
unsafe extern "C" fn slice_new(this: &mut MaybeUninit<RustSlice>, ptr: NonNull<()>, len: usize) {
|
||||
let this = this.as_mut_ptr();
|
||||
let rust_slice = RustSlice::from_raw_parts(ptr, len);
|
||||
unsafe { ptr::write(this, rust_slice) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$slice$ptr"]
|
||||
unsafe extern "C" fn slice_ptr(this: &RustSlice) -> NonNull<()> {
|
||||
this.as_non_null_ptr()
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$slice$len"]
|
||||
unsafe extern "C" fn slice_len(this: &RustSlice) -> usize {
|
||||
this.len()
|
||||
}
|
||||
43
vendor/cxx/src/symbols/rust_str.rs
vendored
Normal file
43
vendor/cxx/src/symbols/rust_str.rs
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#[cfg(feature = "alloc")]
|
||||
use alloc::string::String;
|
||||
use core::mem::MaybeUninit;
|
||||
use core::ptr;
|
||||
use core::slice;
|
||||
use core::str;
|
||||
|
||||
#[export_name = "cxxbridge1$str$new"]
|
||||
unsafe extern "C" fn str_new(this: &mut MaybeUninit<&str>) {
|
||||
let this = this.as_mut_ptr();
|
||||
unsafe { ptr::write(this, "") }
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[export_name = "cxxbridge1$str$ref"]
|
||||
unsafe extern "C" fn str_ref<'a>(this: &mut MaybeUninit<&'a str>, string: &'a String) {
|
||||
let this = this.as_mut_ptr();
|
||||
let s = string.as_str();
|
||||
unsafe { ptr::write(this, s) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$str$from"]
|
||||
unsafe extern "C" fn str_from(this: &mut MaybeUninit<&str>, ptr: *const u8, len: usize) -> bool {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
match str::from_utf8(slice) {
|
||||
Ok(s) => {
|
||||
let this = this.as_mut_ptr();
|
||||
unsafe { ptr::write(this, s) }
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$str$ptr"]
|
||||
unsafe extern "C" fn str_ptr(this: &&str) -> *const u8 {
|
||||
this.as_ptr()
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$str$len"]
|
||||
unsafe extern "C" fn str_len(this: &&str) -> usize {
|
||||
this.len()
|
||||
}
|
||||
114
vendor/cxx/src/symbols/rust_string.rs
vendored
Normal file
114
vendor/cxx/src/symbols/rust_string.rs
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#![cfg(feature = "alloc")]
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::String;
|
||||
use core::mem::{ManuallyDrop, MaybeUninit};
|
||||
use core::ptr;
|
||||
use core::slice;
|
||||
use core::str;
|
||||
|
||||
#[export_name = "cxxbridge1$string$new"]
|
||||
unsafe extern "C" fn string_new(this: &mut MaybeUninit<String>) {
|
||||
let this = this.as_mut_ptr();
|
||||
let new = String::new();
|
||||
unsafe { ptr::write(this, new) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$clone"]
|
||||
unsafe extern "C" fn string_clone(this: &mut MaybeUninit<String>, other: &String) {
|
||||
let this = this.as_mut_ptr();
|
||||
let clone = other.clone();
|
||||
unsafe { ptr::write(this, clone) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$from_utf8"]
|
||||
unsafe extern "C" fn string_from_utf8(
|
||||
this: &mut MaybeUninit<String>,
|
||||
ptr: *const u8,
|
||||
len: usize,
|
||||
) -> bool {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
match str::from_utf8(slice) {
|
||||
Ok(s) => {
|
||||
let this = this.as_mut_ptr();
|
||||
let owned = s.to_owned();
|
||||
unsafe { ptr::write(this, owned) }
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$from_utf8_lossy"]
|
||||
unsafe extern "C" fn string_from_utf8_lossy(
|
||||
this: &mut MaybeUninit<String>,
|
||||
ptr: *const u8,
|
||||
len: usize,
|
||||
) {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
let owned = String::from_utf8_lossy(slice).into_owned();
|
||||
let this = this.as_mut_ptr();
|
||||
unsafe { ptr::write(this, owned) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$from_utf16"]
|
||||
unsafe extern "C" fn string_from_utf16(
|
||||
this: &mut MaybeUninit<String>,
|
||||
ptr: *const u16,
|
||||
len: usize,
|
||||
) -> bool {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
match String::from_utf16(slice) {
|
||||
Ok(s) => {
|
||||
let this = this.as_mut_ptr();
|
||||
unsafe { ptr::write(this, s) }
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$from_utf16_lossy"]
|
||||
unsafe extern "C" fn string_from_utf16_lossy(
|
||||
this: &mut MaybeUninit<String>,
|
||||
ptr: *const u16,
|
||||
len: usize,
|
||||
) {
|
||||
let slice = unsafe { slice::from_raw_parts(ptr, len) };
|
||||
let owned = String::from_utf16_lossy(slice);
|
||||
let this = this.as_mut_ptr();
|
||||
unsafe { ptr::write(this, owned) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$drop"]
|
||||
unsafe extern "C" fn string_drop(this: &mut ManuallyDrop<String>) {
|
||||
unsafe { ManuallyDrop::drop(this) }
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$ptr"]
|
||||
unsafe extern "C" fn string_ptr(this: &String) -> *const u8 {
|
||||
this.as_ptr()
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$len"]
|
||||
unsafe extern "C" fn string_len(this: &String) -> usize {
|
||||
this.len()
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$capacity"]
|
||||
unsafe extern "C" fn string_capacity(this: &String) -> usize {
|
||||
this.capacity()
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$reserve_additional"]
|
||||
unsafe extern "C" fn string_reserve_additional(this: &mut String, additional: usize) {
|
||||
this.reserve(additional);
|
||||
}
|
||||
|
||||
#[export_name = "cxxbridge1$string$reserve_total"]
|
||||
unsafe extern "C" fn string_reserve_total(this: &mut String, new_cap: usize) {
|
||||
if new_cap > this.capacity() {
|
||||
let additional = new_cap - this.len();
|
||||
this.reserve(additional);
|
||||
}
|
||||
}
|
||||
91
vendor/cxx/src/symbols/rust_vec.rs
vendored
Normal file
91
vendor/cxx/src/symbols/rust_vec.rs
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#![cfg(feature = "alloc")]
|
||||
|
||||
use crate::c_char::c_char;
|
||||
use crate::rust_string::RustString;
|
||||
use crate::rust_vec::RustVec;
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
|
||||
macro_rules! rust_vec_shims {
|
||||
($segment:expr, $ty:ty) => {
|
||||
const_assert_eq!(mem::size_of::<[usize; 3]>(), mem::size_of::<RustVec<$ty>>());
|
||||
const_assert_eq!(mem::size_of::<Vec<$ty>>(), mem::size_of::<RustVec<$ty>>());
|
||||
const_assert_eq!(mem::align_of::<Vec<$ty>>(), mem::align_of::<RustVec<$ty>>());
|
||||
|
||||
const _: () = {
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$new")]
|
||||
unsafe extern "C" fn __new(this: *mut RustVec<$ty>) {
|
||||
unsafe { ptr::write(this, RustVec::new()) }
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$drop")]
|
||||
unsafe extern "C" fn __drop(this: *mut RustVec<$ty>) {
|
||||
unsafe { ptr::drop_in_place(this) }
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$len")]
|
||||
unsafe extern "C" fn __len(this: *const RustVec<$ty>) -> usize {
|
||||
unsafe { &*this }.len()
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$capacity")]
|
||||
unsafe extern "C" fn __capacity(this: *const RustVec<$ty>) -> usize {
|
||||
unsafe { &*this }.capacity()
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$data")]
|
||||
unsafe extern "C" fn __data(this: *const RustVec<$ty>) -> *const $ty {
|
||||
unsafe { &*this }.as_ptr()
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$reserve_total")]
|
||||
unsafe extern "C" fn __reserve_total(this: *mut RustVec<$ty>, new_cap: usize) {
|
||||
unsafe { &mut *this }.reserve_total(new_cap);
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$set_len")]
|
||||
unsafe extern "C" fn __set_len(this: *mut RustVec<$ty>, len: usize) {
|
||||
unsafe { (*this).set_len(len) }
|
||||
}
|
||||
}
|
||||
attr! {
|
||||
#[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$truncate")]
|
||||
unsafe extern "C" fn __truncate(this: *mut RustVec<$ty>, len: usize) {
|
||||
unsafe { (*this).truncate(len) }
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! rust_vec_shims_for_primitive {
|
||||
($ty:ident) => {
|
||||
rust_vec_shims!(stringify!($ty), $ty);
|
||||
};
|
||||
}
|
||||
|
||||
rust_vec_shims_for_primitive!(bool);
|
||||
rust_vec_shims_for_primitive!(u8);
|
||||
rust_vec_shims_for_primitive!(u16);
|
||||
rust_vec_shims_for_primitive!(u32);
|
||||
rust_vec_shims_for_primitive!(u64);
|
||||
rust_vec_shims_for_primitive!(usize);
|
||||
rust_vec_shims_for_primitive!(i8);
|
||||
rust_vec_shims_for_primitive!(i16);
|
||||
rust_vec_shims_for_primitive!(i32);
|
||||
rust_vec_shims_for_primitive!(i64);
|
||||
rust_vec_shims_for_primitive!(isize);
|
||||
rust_vec_shims_for_primitive!(f32);
|
||||
rust_vec_shims_for_primitive!(f64);
|
||||
|
||||
rust_vec_shims!("char", c_char);
|
||||
rust_vec_shims!("string", RustString);
|
||||
rust_vec_shims!("str", &str);
|
||||
Loading…
Add table
Add a link
Reference in a new issue