From 396d1d7207b863c92f78ffc4f21c90b0627f95ad Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Tue, 9 Apr 2024 13:18:57 +0900 Subject: [PATCH] rust: Switch to new core::ffi types CStr is now here. This gets rid of three vendored deps, whee. Signed-off-by: Hector Martin --- .gitmodules | 9 --------- rust/Cargo.lock | 18 ------------------ rust/Cargo.toml | 5 ----- rust/src/chainload.rs | 7 +++---- rust/src/dlmalloc.rs | 10 +++++----- rust/src/lib.rs | 4 ++++ rust/vendor/cstr_core | 1 - rust/vendor/cty | 1 - rust/vendor/memchr | 1 - 9 files changed, 12 insertions(+), 44 deletions(-) delete mode 160000 rust/vendor/cstr_core delete mode 160000 rust/vendor/cty delete mode 160000 rust/vendor/memchr diff --git a/.gitmodules b/.gitmodules index a0a12a8c..5aa39f64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,18 +10,9 @@ [submodule "rust/vendor/cfg-if"] path = rust/vendor/cfg-if url = https://github.com/alexcrichton/cfg-if -[submodule "rust/vendor/cstr_core"] - path = rust/vendor/cstr_core - url = https://github.com/Amanieu/cstr_core -[submodule "rust/vendor/cty"] - path = rust/vendor/cty - url = https://github.com/japaric/cty [submodule "rust/vendor/uuid"] path = rust/vendor/uuid url = https://github.com/uuid-rs/uuid [submodule "rust/vendor/log"] path = rust/vendor/log url = https://github.com/rust-lang/log -[submodule "rust/vendor/memchr"] - path = rust/vendor/memchr - url = https://github.com/BurntSushi/memchr diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 87a9b30c..ac41e158 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -10,18 +10,6 @@ version = "1.3.2" name = "cfg-if" version = "1.0.0" -[[package]] -name = "cstr_core" -version = "0.2.5" -dependencies = [ - "cty", - "memchr", -] - -[[package]] -name = "cty" -version = "0.2.2" - [[package]] name = "fatfs" version = "0.4.0" @@ -37,16 +25,10 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "memchr" -version = "2.4.1" - [[package]] name = "rust" version = "0.1.0" dependencies = [ - "cstr_core", - "cty", "fatfs", "uuid", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 352dde01..39229e9e 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -12,15 +12,10 @@ crate-type = [ "staticlib" ] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] fatfs = { path = "vendor/rust-fatfs", default-features = false, features = ["lfn", "alloc"] } -cstr_core = "0.2.5" uuid = { version = "1.7.0", default-features = false } -cty = "0.2.2" [patch.crates-io] uuid = { path = "vendor/uuid" } -cty = { path = "vendor/cty" } -cstr_core = { path = "vendor/cstr_core" } -memchr = { path = "vendor/memchr" } log = { path = "vendor/log" } bitflags = { path = "vendor/bitflags" } cfg-if = { path = "vendor/cfg-if" } diff --git a/rust/src/chainload.rs b/rust/src/chainload.rs index 093158d9..22b7315f 100644 --- a/rust/src/chainload.rs +++ b/rust/src/chainload.rs @@ -1,13 +1,12 @@ // SPDX-License-Identifier: MIT #![deny(unsafe_op_in_unsafe_fn)] +use crate::c_size_t; use crate::gpt; use crate::nvme; use crate::println; use alloc::vec::Vec; -use core::ffi::c_void; -use cstr_core::CStr; -use cty::*; +use core::ffi::{c_char, c_int, c_void, CStr}; use fatfs::{FileSystem, FsOptions, Read, Seek, SeekFrom}; use uuid::Uuid; @@ -81,7 +80,7 @@ fn load_image(spec: &str) -> Result, Error> { pub unsafe extern "C" fn rust_load_image( raw_spec: *const c_char, image: *mut *mut c_void, - size: *mut size_t, + size: *mut c_size_t, ) -> c_int { let spec = unsafe { CStr::from_ptr(raw_spec).to_str().unwrap() }; diff --git a/rust/src/dlmalloc.rs b/rust/src/dlmalloc.rs index e60b2d1f..e994eb98 100644 --- a/rust/src/dlmalloc.rs +++ b/rust/src/dlmalloc.rs @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT +use crate::c_size_t; use core::alloc::{GlobalAlloc, Layout}; -use core::ffi::c_void; +use core::ffi::{c_int, c_void}; use core::ptr; -use cty::*; extern "C" { - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc_in_place(p: *mut c_void, size: size_t) -> *mut c_void; + pub fn malloc(size: c_size_t) -> *mut c_void; + pub fn realloc_in_place(p: *mut c_void, size: c_size_t) -> *mut c_void; pub fn free(p: *mut c_void); - pub fn posix_memalign(p: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int; + pub fn posix_memalign(p: *mut *mut c_void, alignment: c_size_t, size: c_size_t) -> c_int; } pub struct DLMalloc; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 713a695c..23ffd7a2 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -15,6 +15,10 @@ pub mod print; use crate::dlmalloc::DLMalloc; +// This is unstable in core::ffi, let's just declare it ourselves +#[allow(non_camel_case_types)] +type c_size_t = usize; + #[global_allocator] static GLOBAL: DLMalloc = dlmalloc::DLMalloc; diff --git a/rust/vendor/cstr_core b/rust/vendor/cstr_core deleted file mode 160000 index 35e44d2a..00000000 --- a/rust/vendor/cstr_core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 35e44d2a128f29a52ac0a43baa2d9238bd7239dd diff --git a/rust/vendor/cty b/rust/vendor/cty deleted file mode 160000 index dcc347dc..00000000 --- a/rust/vendor/cty +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dcc347dc8afb74906719e68e2f48e3ff38dcc76f diff --git a/rust/vendor/memchr b/rust/vendor/memchr deleted file mode 160000 index 8e1da98f..00000000 --- a/rust/vendor/memchr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e1da98fee06d66c13e66c330e3a3dd6ccf0e3a0