From 206cb6365310e2cf9dfc74bdfc5d83fbcfad84db Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sun, 13 Aug 2023 20:38:48 +0200 Subject: [PATCH 01/24] Constification --- src/error/hosting_result.rs | 28 ++++++++++++++-------------- src/hostfxr/context.rs | 10 +++++----- src/hostfxr/library.rs | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/error/hosting_result.rs b/src/error/hosting_result.rs index dab5e38..2750d8a 100644 --- a/src/error/hosting_result.rs +++ b/src/error/hosting_result.rs @@ -16,7 +16,7 @@ pub struct HostingResult(pub Result); impl HostingResult { /// Creates a new [`HostingResult`] from the raw status code. #[allow(clippy::cast_possible_wrap)] - pub fn from_status_code(code: u32) -> Self { + pub const fn from_status_code(code: u32) -> Self { if code as i32 >= 0 { Self::from_success(HostingSuccess::from_status_code(code)) } else { @@ -25,18 +25,18 @@ impl HostingResult { } /// Creates a new successful [`HostingResult`] from the give [`HostingSuccess`]. - pub fn from_success(success: HostingSuccess) -> Self { + pub const fn from_success(success: HostingSuccess) -> Self { Self(Ok(success)) } /// Creates a new erroneous [`HostingResult`] from the give [`HostingError`]. - pub fn from_error(error: HostingError) -> Self { + pub const fn from_error(error: HostingError) -> Self { Self(Err(error)) } /// Tries to create a new [`HostingResult`] from the raw status code if it is known. /// Otherwise returns the given value as an [`Err`]. - pub fn known_from_status_code(code: u32) -> Result { + pub const fn known_from_status_code(code: u32) -> Result { if let Ok(success) = HostingSuccess::known_from_status_code(code) { Ok(Self::from_success(success)) } else if let Ok(error) = HostingError::known_from_status_code(code) { @@ -172,7 +172,7 @@ pub enum HostingSuccess { impl HostingSuccess { /// Creates a new [`HostingSuccess`] from the raw status code. #[must_use] - pub fn from_status_code(code: u32) -> Self { + pub const fn from_status_code(code: u32) -> Self { match Self::known_from_status_code(code) { Ok(s) => s, Err(code) => Self::Unknown(code), @@ -181,7 +181,7 @@ impl HostingSuccess { /// Tries to create a new [`HostingSuccess`] from the raw status code if it is known. /// Otherwise returns the given value as an [`Err`]. - pub fn known_from_status_code(code: u32) -> Result { + pub const fn known_from_status_code(code: u32) -> Result { match code { c if c == bindings::StatusCode::Success as u32 => Ok(Self::Success), c if c == bindings::StatusCode::Success_DifferentRuntimeProperties as u32 => { @@ -196,7 +196,7 @@ impl HostingSuccess { /// Returns the underlying status code value. #[must_use] - pub fn value(&self) -> u32 { + pub const fn value(&self) -> u32 { match self { Self::Success => bindings::StatusCode::Success as u32, Self::DifferentRuntimeProperties => { @@ -211,13 +211,13 @@ impl HostingSuccess { /// Returns whether the status code of this success has a known meaning. #[must_use] - pub fn is_known(&self) -> bool { + pub const fn is_known(&self) -> bool { !self.is_unknown() } /// Returns whether the status code of this success has a unknown meaning. #[must_use] - pub fn is_unknown(&self) -> bool { + pub const fn is_unknown(&self) -> bool { matches!(self, Self::Unknown(_)) } } @@ -500,7 +500,7 @@ impl std::error::Error for HostingError {} impl HostingError { /// Creates a new [`HostingError`] from the raw status code. - pub fn from_status_code(code: u32) -> Self { + pub const fn from_status_code(code: u32) -> Self { match Self::known_from_status_code(code) { Ok(s) => s, Err(code) => Self::Unknown(code), @@ -509,7 +509,7 @@ impl HostingError { /// Tries to create a new [`HostingError`] from the raw status code if it is known. /// Otherwise returns the given value as an [`Err`]. - pub fn known_from_status_code(code: u32) -> Result { + pub const fn known_from_status_code(code: u32) -> Result { match code { c if c == bindings::StatusCode::InvalidArgFailure as u32 => Ok(Self::InvalidArgFailure), c if c == bindings::StatusCode::CoreHostLibLoadFailure as u32 => { @@ -613,7 +613,7 @@ impl HostingError { /// Returns the underlying status code value. #[must_use] - pub fn value(&self) -> u32 { + pub const fn value(&self) -> u32 { match self { Self::InvalidArgFailure => bindings::StatusCode::InvalidArgFailure as u32, Self::CoreHostLibLoadFailure => bindings::StatusCode::CoreHostLibLoadFailure as u32, @@ -676,13 +676,13 @@ impl HostingError { /// Returns whether the status code of this error has a known meaning. #[must_use] - pub fn is_known(&self) -> bool { + pub const fn is_known(&self) -> bool { !self.is_unknown() } /// Returns whether the status code of this error has a unknown meaning. #[must_use] - pub fn is_unknown(&self) -> bool { + pub const fn is_unknown(&self) -> bool { matches!(self, Self::Unknown(_)) } } diff --git a/src/hostfxr/context.rs b/src/hostfxr/context.rs index 411d4e5..ac2ca33 100644 --- a/src/hostfxr/context.rs +++ b/src/hostfxr/context.rs @@ -59,13 +59,13 @@ impl HostfxrHandle { /// - The given raw handle has to be non-null. /// - The given handle has to be valid and has to represent a hostfxr context. #[must_use] - pub unsafe fn new_unchecked(ptr: hostfxr_handle) -> Self { + pub const unsafe fn new_unchecked(ptr: hostfxr_handle) -> Self { Self(unsafe { NonNull::new_unchecked(ptr.cast_mut()) }) } /// Returns the raw underlying handle. #[must_use] - pub fn as_raw(&self) -> hostfxr_handle { + pub const fn as_raw(&self) -> hostfxr_handle { self.0.as_ptr() } } @@ -123,7 +123,7 @@ impl HostfxrContext { /// Gets the underlying handle to the hostfxr context. #[must_use] - pub fn handle(&self) -> HostfxrHandle { + pub const fn handle(&self) -> HostfxrHandle { self.handle } @@ -140,12 +140,12 @@ impl HostfxrContext { /// # Note /// #[must_use] - pub fn is_primary(&self) -> bool { + pub const fn is_primary(&self) -> bool { self.is_primary } #[must_use] - pub(crate) fn library(&self) -> &SharedHostfxrLibrary { + pub(crate) const fn library(&self) -> &SharedHostfxrLibrary { &self.hostfxr } diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index bb7f8e4..7f35e08 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -67,7 +67,7 @@ pub struct AppOrHostingResult(i32); impl AppOrHostingResult { /// Gets the raw value of the result. #[must_use] - pub fn value(&self) -> i32 { + pub const fn value(&self) -> i32 { self.0 } From 0c2e22c55762cfb69e035c219413f08ac6f4e944 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sun, 13 Aug 2023 20:39:36 +0200 Subject: [PATCH 02/24] Add support for loading older hostfxrs with newer feature flags --- Cargo.toml | 2 +- src/hostfxr/context.rs | 6 +++--- src/hostfxr/library.rs | 5 +++-- src/hostfxr/library1_0.rs | 4 +++- src/hostfxr/library2_1.rs | 8 +++++--- src/hostfxr/library3_0.rs | 6 ++++-- src/hostfxr/library6_0.rs | 4 +++- src/hostfxr/runtime_property.rs | 10 +++++----- 8 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c7ed96..3279bee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["nethost", "hostfxr", "dotnet", "bindings", "coreclr"] num_enum = { version = "0.6", default-features = false } thiserror = { version = "1.0", default-features = false } derive_more = { version = "0.99", features = ["deref", "from", "display"], default-features = false } -hostfxr-sys = { version = "0.9", features = ["enum-map", "undocumented"], default-features = false } +hostfxr-sys = { version = "0.10", features = ["enum-map", "undocumented", "wrapper", "optional-apis"], default-features = false } coreclr-hosting-shared = { version = "0.1", default-features = false } destruct-drop = { version = "0.2", default-features = false } ffi-opaque = { version = "2.0", default-features = false } diff --git a/src/hostfxr/context.rs b/src/hostfxr/context.rs index ac2ca33..63225c8 100644 --- a/src/hostfxr/context.rs +++ b/src/hostfxr/context.rs @@ -185,7 +185,7 @@ impl HostfxrContext { r#type, delegate.as_mut_ptr(), ) - }; + }.unwrap(); HostingResult::from(result).into_result()?; @@ -303,7 +303,7 @@ impl HostfxrContext { /// Internal non-consuming version of [`close`](HostfxrContext::close) unsafe fn _close(&self) -> Result { - let result = unsafe { self.hostfxr.hostfxr_close(self.handle.as_raw()) }; + let result = unsafe { self.hostfxr.hostfxr_close(self.handle.as_raw()) }.unwrap(); HostingResult::from(result).into_result() } } @@ -315,7 +315,7 @@ impl HostfxrContext { /// If the app was successfully run, the exit code of the application. Otherwise, the error code result. #[must_use] pub fn run_app(self) -> AppOrHostingResult { - let result = unsafe { self.hostfxr.hostfxr_run_app(self.handle.as_raw()) }; + let result = unsafe { self.hostfxr.hostfxr_run_app(self.handle.as_raw()) }.unwrap(); AppOrHostingResult::from(result) } } diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index 7f35e08..cec04ca 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -1,5 +1,5 @@ use crate::{ - dlopen2::wrapper::Container, error::HostingResult, nethost::LoadHostfxrError, + dlopen2::wrapper::Container, error::{HostingResult, HostingError}, nethost::LoadHostfxrError, pdcstring::PdCString, }; use derive_more::From; @@ -10,8 +10,9 @@ use std::{ rc::Rc, }; -pub(crate) type HostfxrLibrary = Container; +pub(crate) type HostfxrLibrary = Container; pub(crate) type SharedHostfxrLibrary = Rc; +pub(crate) const UNSUPPORTED_HOST_VERSION_ERROR_CODE: i32 = HostingError::HostApiUnsupportedVersion.value() as i32; /// A struct representing a loaded hostfxr library. #[derive(Clone, From)] diff --git a/src/hostfxr/library1_0.rs b/src/hostfxr/library1_0.rs index 62cbb1f..6dd0ee2 100644 --- a/src/hostfxr/library1_0.rs +++ b/src/hostfxr/library1_0.rs @@ -3,6 +3,8 @@ use crate::{ pdcstring::PdCStr, }; +use super::UNSUPPORTED_HOST_VERSION_ERROR_CODE; + impl Hostfxr { /// Run an application. /// @@ -48,7 +50,7 @@ impl Hostfxr { let result = unsafe { self.lib .hostfxr_main(args.len().try_into().unwrap(), args.as_ptr()) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); AppOrHostingResult::from(result) } diff --git a/src/hostfxr/library2_1.rs b/src/hostfxr/library2_1.rs index 0a8c2e6..4137adf 100644 --- a/src/hostfxr/library2_1.rs +++ b/src/hostfxr/library2_1.rs @@ -17,6 +17,8 @@ use std::{ ptr, slice, }; +use super::UNSUPPORTED_HOST_VERSION_ERROR_CODE; + impl Hostfxr { /// Run an application. /// @@ -61,7 +63,7 @@ impl Hostfxr { dotnet_root.as_ptr(), app_path.as_ptr(), ) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); Ok(AppOrHostingResult::from(result)) } @@ -91,7 +93,7 @@ impl Hostfxr { flags, resolve_sdk2_callback, ) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); HostingResult::from(result).into_result()?; let sdk_path = RESOLVE_SDK2_DATA @@ -159,7 +161,7 @@ impl Hostfxr { buffer.spare_capacity_mut().len().try_into().unwrap(), &mut required_buffer_size, ) - }; + }.unwrap_or_else(|| HostingError::HostApiUnsupportedVersion.value() as i32); HostingResult::from(result).into_result()?; unsafe { buffer.set_len(required_buffer_size.try_into().unwrap()) }; diff --git a/src/hostfxr/library3_0.rs b/src/hostfxr/library3_0.rs index e5d2648..92faa7a 100644 --- a/src/hostfxr/library3_0.rs +++ b/src/hostfxr/library3_0.rs @@ -9,6 +9,8 @@ use crate::{ }; use std::{iter, mem::MaybeUninit, ptr}; +use super::UNSUPPORTED_HOST_VERSION_ERROR_CODE; + impl Hostfxr { /// Initializes the hosting components for a dotnet command line running an application /// @@ -236,7 +238,7 @@ impl Hostfxr { parameters, hostfxr_handle.as_mut_ptr(), ) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); let success_code = HostingResult::from(result).into_result()?; @@ -363,7 +365,7 @@ impl Hostfxr { parameters, hostfxr_handle.as_mut_ptr(), ) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); let success_code = HostingResult::from(result).into_result()?; diff --git a/src/hostfxr/library6_0.rs b/src/hostfxr/library6_0.rs index 6e9eab7..8ef40cb 100644 --- a/src/hostfxr/library6_0.rs +++ b/src/hostfxr/library6_0.rs @@ -7,6 +7,8 @@ use crate::{ }; use std::{ffi::c_void, mem::MaybeUninit, path::PathBuf, ptr, slice}; +use super::UNSUPPORTED_HOST_VERSION_ERROR_CODE; + /// Information about the current dotnet environment loaded using [Hostfxr::get_dotnet_environment_info]. #[derive(Debug, Clone)] pub struct EnvironmentInfo { @@ -110,7 +112,7 @@ impl Hostfxr { get_dotnet_environment_info_callback, info.as_mut_ptr().cast(), ) - }; + }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); HostingResult::from(result).into_result()?; let info = unsafe { MaybeUninit::assume_init(info) }; Ok(info) diff --git a/src/hostfxr/runtime_property.rs b/src/hostfxr/runtime_property.rs index e4a2ea9..c2c80ec 100644 --- a/src/hostfxr/runtime_property.rs +++ b/src/hostfxr/runtime_property.rs @@ -21,7 +21,7 @@ impl HostfxrContext { name.as_ref().as_ptr(), value.as_mut_ptr(), ) - }; + }.unwrap(); HostingResult::from(result).into_result()?; Ok(unsafe { PdCStr::from_str_ptr(value.assume_init()) }) @@ -39,7 +39,7 @@ impl HostfxrContext { name.as_ref().as_ptr(), value.as_ref().as_ptr(), ) - }; + }.unwrap(); HostingResult::from(result).into_result().map(|_| ()) } @@ -54,7 +54,7 @@ impl HostfxrContext { name.as_ref().as_ptr(), ptr::null(), ) - }; + }.unwrap(); HostingResult::from(result).into_result().map(|_| ()) } @@ -69,7 +69,7 @@ impl HostfxrContext { ptr::null_mut(), ptr::null_mut(), ) - }; + }.unwrap(); // ignore buffer too small error as the first call is only to get the required buffer size. match HostingResult::from(result).into_result() { @@ -88,7 +88,7 @@ impl HostfxrContext { keys.as_mut_ptr(), values.as_mut_ptr(), ) - }; + }.unwrap(); HostingResult::from(result).into_result()?; unsafe { keys.set_len(count) }; From 7c227d581ce1d2d4ec198e396dd36460380591a1 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sun, 13 Aug 2023 20:44:32 +0200 Subject: [PATCH 03/24] Fix clippy warnings --- src/hostfxr/library.rs | 4 +++- src/hostfxr/library2_1.rs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index cec04ca..a9cc6f5 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -12,7 +12,9 @@ use std::{ pub(crate) type HostfxrLibrary = Container; pub(crate) type SharedHostfxrLibrary = Rc; -pub(crate) const UNSUPPORTED_HOST_VERSION_ERROR_CODE: i32 = HostingError::HostApiUnsupportedVersion.value() as i32; +#[allow(clippy::cast_possible_wrap)] +pub(crate) const UNSUPPORTED_HOST_VERSION_ERROR_CODE: i32 = + HostingError::HostApiUnsupportedVersion.value() as i32; /// A struct representing a loaded hostfxr library. #[derive(Clone, From)] diff --git a/src/hostfxr/library2_1.rs b/src/hostfxr/library2_1.rs index 4137adf..e43af27 100644 --- a/src/hostfxr/library2_1.rs +++ b/src/hostfxr/library2_1.rs @@ -161,7 +161,8 @@ impl Hostfxr { buffer.spare_capacity_mut().len().try_into().unwrap(), &mut required_buffer_size, ) - }.unwrap_or_else(|| HostingError::HostApiUnsupportedVersion.value() as i32); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); HostingResult::from(result).into_result()?; unsafe { buffer.set_len(required_buffer_size.try_into().unwrap()) }; From 854246b3ca89bf2fcee4e0eb301dc79aa978879c Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:52 +0200 Subject: [PATCH 04/24] Cargo fmt --- src/hostfxr/context.rs | 3 ++- src/hostfxr/library.rs | 4 +++- src/hostfxr/library1_0.rs | 3 ++- src/hostfxr/library2_1.rs | 6 ++++-- src/hostfxr/library3_0.rs | 6 ++++-- src/hostfxr/library6_0.rs | 3 ++- src/hostfxr/runtime_property.rs | 15 ++++++++++----- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/hostfxr/context.rs b/src/hostfxr/context.rs index 63225c8..570672a 100644 --- a/src/hostfxr/context.rs +++ b/src/hostfxr/context.rs @@ -185,7 +185,8 @@ impl HostfxrContext { r#type, delegate.as_mut_ptr(), ) - }.unwrap(); + } + .unwrap(); HostingResult::from(result).into_result()?; diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index a9cc6f5..eda1bb3 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -1,5 +1,7 @@ use crate::{ - dlopen2::wrapper::Container, error::{HostingResult, HostingError}, nethost::LoadHostfxrError, + dlopen2::wrapper::Container, + error::{HostingError, HostingResult}, + nethost::LoadHostfxrError, pdcstring::PdCString, }; use derive_more::From; diff --git a/src/hostfxr/library1_0.rs b/src/hostfxr/library1_0.rs index 6dd0ee2..d2dedf2 100644 --- a/src/hostfxr/library1_0.rs +++ b/src/hostfxr/library1_0.rs @@ -50,7 +50,8 @@ impl Hostfxr { let result = unsafe { self.lib .hostfxr_main(args.len().try_into().unwrap(), args.as_ptr()) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); AppOrHostingResult::from(result) } diff --git a/src/hostfxr/library2_1.rs b/src/hostfxr/library2_1.rs index e43af27..199bc52 100644 --- a/src/hostfxr/library2_1.rs +++ b/src/hostfxr/library2_1.rs @@ -63,7 +63,8 @@ impl Hostfxr { dotnet_root.as_ptr(), app_path.as_ptr(), ) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); Ok(AppOrHostingResult::from(result)) } @@ -93,7 +94,8 @@ impl Hostfxr { flags, resolve_sdk2_callback, ) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); HostingResult::from(result).into_result()?; let sdk_path = RESOLVE_SDK2_DATA diff --git a/src/hostfxr/library3_0.rs b/src/hostfxr/library3_0.rs index 92faa7a..4fb7004 100644 --- a/src/hostfxr/library3_0.rs +++ b/src/hostfxr/library3_0.rs @@ -238,7 +238,8 @@ impl Hostfxr { parameters, hostfxr_handle.as_mut_ptr(), ) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); let success_code = HostingResult::from(result).into_result()?; @@ -365,7 +366,8 @@ impl Hostfxr { parameters, hostfxr_handle.as_mut_ptr(), ) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); let success_code = HostingResult::from(result).into_result()?; diff --git a/src/hostfxr/library6_0.rs b/src/hostfxr/library6_0.rs index 8ef40cb..7fae8c2 100644 --- a/src/hostfxr/library6_0.rs +++ b/src/hostfxr/library6_0.rs @@ -112,7 +112,8 @@ impl Hostfxr { get_dotnet_environment_info_callback, info.as_mut_ptr().cast(), ) - }.unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); + } + .unwrap_or(UNSUPPORTED_HOST_VERSION_ERROR_CODE); HostingResult::from(result).into_result()?; let info = unsafe { MaybeUninit::assume_init(info) }; Ok(info) diff --git a/src/hostfxr/runtime_property.rs b/src/hostfxr/runtime_property.rs index c2c80ec..598830f 100644 --- a/src/hostfxr/runtime_property.rs +++ b/src/hostfxr/runtime_property.rs @@ -21,7 +21,8 @@ impl HostfxrContext { name.as_ref().as_ptr(), value.as_mut_ptr(), ) - }.unwrap(); + } + .unwrap(); HostingResult::from(result).into_result()?; Ok(unsafe { PdCStr::from_str_ptr(value.assume_init()) }) @@ -39,7 +40,8 @@ impl HostfxrContext { name.as_ref().as_ptr(), value.as_ref().as_ptr(), ) - }.unwrap(); + } + .unwrap(); HostingResult::from(result).into_result().map(|_| ()) } @@ -54,7 +56,8 @@ impl HostfxrContext { name.as_ref().as_ptr(), ptr::null(), ) - }.unwrap(); + } + .unwrap(); HostingResult::from(result).into_result().map(|_| ()) } @@ -69,7 +72,8 @@ impl HostfxrContext { ptr::null_mut(), ptr::null_mut(), ) - }.unwrap(); + } + .unwrap(); // ignore buffer too small error as the first call is only to get the required buffer size. match HostingResult::from(result).into_result() { @@ -88,7 +92,8 @@ impl HostfxrContext { keys.as_mut_ptr(), values.as_mut_ptr(), ) - }.unwrap(); + } + .unwrap(); HostingResult::from(result).into_result()?; unsafe { keys.set_len(count) }; From 05aedb0f4fc222df19feee729102933cb6dd8b06 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:52 +0200 Subject: [PATCH 05/24] Bump version to 0.16.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3279bee..19ee549 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "netcorehost" -version = "0.15.1" +version = "0.16.0" description = "A Rust library for hosting the .NET Core runtime." readme = "README.md" repository = "https://github.com/OpenByteDev/netcorehost" From 9fb93dc258f7e3d79ba43a58909d985c331823e7 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:53 +0200 Subject: [PATCH 06/24] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 19ee549..896d464 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ categories = ["api-bindings", "external-ffi-bindings"] keywords = ["nethost", "hostfxr", "dotnet", "bindings", "coreclr"] [dependencies] -num_enum = { version = "0.6", default-features = false } +num_enum = { version = "0.7", default-features = false } thiserror = { version = "1.0", default-features = false } derive_more = { version = "0.99", features = ["deref", "from", "display"], default-features = false } hostfxr-sys = { version = "0.10", features = ["enum-map", "undocumented", "wrapper", "optional-apis"], default-features = false } From 73ef91654afc6495ded7fcf8915f8beb50b13350 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:53 +0200 Subject: [PATCH 07/24] Fix #33 --- src/hostfxr/context.rs | 8 +++++--- src/hostfxr/library.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hostfxr/context.rs b/src/hostfxr/context.rs index 570672a..9eceee6 100644 --- a/src/hostfxr/context.rs +++ b/src/hostfxr/context.rs @@ -24,7 +24,7 @@ use std::{ marker::PhantomData, mem::{self, ManuallyDrop, MaybeUninit}, ptr::NonNull, - rc::Rc, + cell::Cell }; #[cfg(feature = "net8_0")] @@ -85,9 +85,11 @@ pub struct HostfxrContext { is_primary: bool, runtime_delegates: EnumMap>, context_type: PhantomData, - not_thread_safe: PhantomData>, + not_sync: PhantomData> } +unsafe impl Send for HostfxrContext {} + impl Debug for HostfxrContext { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("HostfxrContext") @@ -117,7 +119,7 @@ impl HostfxrContext { is_primary, runtime_delegates: EnumMap::default(), context_type: PhantomData, - not_thread_safe: PhantomData, + not_sync: PhantomData, } } diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index eda1bb3..267c113 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -9,11 +9,11 @@ use std::{ env::consts::EXE_SUFFIX, ffi::OsString, path::{Path, PathBuf}, - rc::Rc, + sync::Arc, }; pub(crate) type HostfxrLibrary = Container; -pub(crate) type SharedHostfxrLibrary = Rc; +pub(crate) type SharedHostfxrLibrary = Arc; #[allow(clippy::cast_possible_wrap)] pub(crate) const UNSUPPORTED_HOST_VERSION_ERROR_CODE: i32 = HostingError::HostApiUnsupportedVersion.value() as i32; From 065f942c3de74b170a83770211246690754d9373 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:53 +0200 Subject: [PATCH 08/24] Cargo fmt --- src/hostfxr/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/context.rs b/src/hostfxr/context.rs index 9eceee6..5263cf5 100644 --- a/src/hostfxr/context.rs +++ b/src/hostfxr/context.rs @@ -19,12 +19,12 @@ use crate::{ }; use std::{ + cell::Cell, ffi::c_void, fmt::{self, Debug}, marker::PhantomData, mem::{self, ManuallyDrop, MaybeUninit}, ptr::NonNull, - cell::Cell }; #[cfg(feature = "net8_0")] @@ -85,7 +85,7 @@ pub struct HostfxrContext { is_primary: bool, runtime_delegates: EnumMap>, context_type: PhantomData, - not_sync: PhantomData> + not_sync: PhantomData>, } unsafe impl Send for HostfxrContext {} From eb0a9bc73f08b48979199950bd60d6fa5f0fa823 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:53 +0200 Subject: [PATCH 09/24] Fix clippy warnings --- src/hostfxr/mod.rs | 3 +++ src/pdcstring/impl/other/mod.rs | 2 ++ src/pdcstring/impl/windows/mod.rs | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/hostfxr/mod.rs b/src/hostfxr/mod.rs index 3aa7b7f..8c4d1cd 100644 --- a/src/hostfxr/mod.rs +++ b/src/hostfxr/mod.rs @@ -5,6 +5,7 @@ pub use library::*; mod library1_0; #[cfg(feature = "netcore1_0")] #[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore1_0")))] +#[allow(unused)] pub use library1_0::*; #[cfg(feature = "netcore2_1")] @@ -17,6 +18,7 @@ pub use library2_1::*; mod library3_0; #[cfg(feature = "netcore3_0")] #[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))] +#[allow(unused)] pub use library3_0::*; #[cfg(feature = "net6_0")] @@ -41,6 +43,7 @@ pub use delegate_loader::*; mod runtime_property; #[cfg(feature = "netcore3_0")] #[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))] +#[allow(unused)] pub use runtime_property::*; #[cfg(feature = "netcore3_0")] diff --git a/src/pdcstring/impl/other/mod.rs b/src/pdcstring/impl/other/mod.rs index e61a55a..5fd8865 100644 --- a/src/pdcstring/impl/other/mod.rs +++ b/src/pdcstring/impl/other/mod.rs @@ -7,9 +7,11 @@ mod pdcstr; pub use pdcstr::*; mod pdcstring; +#[allow(unused)] pub use pdcstring::*; mod error; +#[allow(unused)] pub use error::*; mod ext; diff --git a/src/pdcstring/impl/windows/mod.rs b/src/pdcstring/impl/windows/mod.rs index 27d29eb..ff421c6 100644 --- a/src/pdcstring/impl/windows/mod.rs +++ b/src/pdcstring/impl/windows/mod.rs @@ -7,9 +7,11 @@ mod pdcstr; pub use pdcstr::*; mod pdcstring; +#[allow(unused)] pub use pdcstring::*; mod error; +#[allow(unused)] pub use error::*; mod ext; From 97bbee935fd43a032ffc8868cb1b58475f34369d Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:53 +0200 Subject: [PATCH 10/24] Fix tests --- tests/manual_close_frees_lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/manual_close_frees_lib.rs b/tests/manual_close_frees_lib.rs index e61f4b5..d2cf1aa 100644 --- a/tests/manual_close_frees_lib.rs +++ b/tests/manual_close_frees_lib.rs @@ -1,6 +1,6 @@ #![cfg(feature = "netcore3_0")] -use std::rc::Rc; +use std::sync::Arc; use netcorehost::nethost; use rusty_fork::rusty_fork_test; @@ -18,7 +18,7 @@ rusty_fork_test! { .initialize_for_runtime_config(common::test_runtime_config_path()) .unwrap(); - let weak = Rc::downgrade(&hostfxr.lib); + let weak = Arc::downgrade(&hostfxr.lib); drop(hostfxr); context.close().unwrap(); From 519af483d87b66128ad655424166cd6befd3b2b7 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:54 +0200 Subject: [PATCH 11/24] Fix nightly clippy lints --- src/hostfxr/library2_1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/library2_1.rs b/src/hostfxr/library2_1.rs index 199bc52..4495b38 100644 --- a/src/hostfxr/library2_1.rs +++ b/src/hostfxr/library2_1.rs @@ -184,8 +184,8 @@ impl Hostfxr { } thread_local! { - static GET_AVAILABLE_SDKS_DATA: RefCell>> = RefCell::new(None); - static RESOLVE_SDK2_DATA: RefCell> = RefCell::new(None); + static GET_AVAILABLE_SDKS_DATA: RefCell>> = const { RefCell::new(None) }; + static RESOLVE_SDK2_DATA: RefCell> = const { RefCell::new(None) }; } extern "C" fn get_available_sdks_callback(sdk_count: i32, sdks_ptr: *const *const char_t) { From e3627245eb584192528bf8da947280e92a6017b0 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:54 +0200 Subject: [PATCH 12/24] Try to fix github ci --- tests/environment_info.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/environment_info.rs b/tests/environment_info.rs index 1dd4593..0b6e55a 100644 --- a/tests/environment_info.rs +++ b/tests/environment_info.rs @@ -2,7 +2,7 @@ use netcorehost::{ hostfxr::{EnvironmentInfo, FrameworkInfo, SdkInfo}, nethost, }; -use std::{collections::HashMap, path::PathBuf, process::Command}; +use std::{collections::HashMap, path::{Path, PathBuf}, process::Command, str::FromStr}; #[path = "common.rs"] mod common; @@ -21,7 +21,11 @@ fn get_dotnet_environment_info() { } fn get_expected_environment_info() -> EnvironmentInfo { - let output = Command::new("dotnet").arg("--info").output().unwrap(); + let dotnet_path = option_env!("DOTNET_ROOT") + .map(|root| Path::new(root).join("dotnet")) + .unwrap_or_else(|| PathBuf::from_str("dotnet").unwrap()); + dbg!(&dotnet_path); + let output = Command::new(dotnet_path).arg("--info").output().unwrap(); assert!(output.status.success()); let output = String::from_utf8_lossy(&output.stdout); From cdab890fe53705a36c13dc63173877069b4906a7 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:17:54 +0200 Subject: [PATCH 13/24] Try to fix github ci --- tests/environment_info.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/environment_info.rs b/tests/environment_info.rs index 1dd4593..b5d2b10 100644 --- a/tests/environment_info.rs +++ b/tests/environment_info.rs @@ -2,7 +2,7 @@ use netcorehost::{ hostfxr::{EnvironmentInfo, FrameworkInfo, SdkInfo}, nethost, }; -use std::{collections::HashMap, path::PathBuf, process::Command}; +use std::{collections::HashMap, path::{Path, PathBuf}, process::Command, str::FromStr}; #[path = "common.rs"] mod common; @@ -10,7 +10,13 @@ mod common; #[test] #[cfg(feature = "net6_0")] fn get_dotnet_environment_info() { - let hostfxr = nethost::load_hostfxr().unwrap(); + use netcorehost::pdcstring::PdCString; + + let hostfxr = if let Some(dotnet_root) = option_env!("DOTNET_ROOT") { + nethost::load_hostfxr_with_dotnet_root(PdCString::from_str(dotnet_root).unwrap()) + } else { + nethost::load_hostfxr() + }.unwrap(); let actual_env = hostfxr.get_dotnet_environment_info().unwrap(); let expected_env = get_expected_environment_info(); @@ -21,7 +27,10 @@ fn get_dotnet_environment_info() { } fn get_expected_environment_info() -> EnvironmentInfo { - let output = Command::new("dotnet").arg("--info").output().unwrap(); + let dotnet_path = option_env!("DOTNET_ROOT") + .map(|root| Path::new(root).join("dotnet")) + .unwrap_or_else(|| PathBuf::from_str("dotnet").unwrap()); + let output = Command::new(dotnet_path).arg("--info").output().unwrap(); assert!(output.status.success()); let output = String::from_utf8_lossy(&output.stdout); From 99c54b886c40a6ced61e25b8d9f2fccc80aceb90 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:08 +0200 Subject: [PATCH 14/24] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c27611..7cdbebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: fail-fast: false matrix: toolchain: ["beta"] - target: ["aarch64-unknown-linux-gnu", "armv7-unknown-linux-gnueabihf", "aarch64-pc-windows-msvc"] + target: ["aarch64-unknown-linux-gnu", "armv7-unknown-linux-gnueabihf"] steps: - uses: actions/checkout@v3 From eec25f2765a8abb100dcc5baebd688a91bf47eee Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:08 +0200 Subject: [PATCH 15/24] Cargo fmt --- tests/environment_info.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/environment_info.rs b/tests/environment_info.rs index b5d2b10..ccbc96c 100644 --- a/tests/environment_info.rs +++ b/tests/environment_info.rs @@ -2,7 +2,12 @@ use netcorehost::{ hostfxr::{EnvironmentInfo, FrameworkInfo, SdkInfo}, nethost, }; -use std::{collections::HashMap, path::{Path, PathBuf}, process::Command, str::FromStr}; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, + process::Command, + str::FromStr, +}; #[path = "common.rs"] mod common; @@ -16,7 +21,8 @@ fn get_dotnet_environment_info() { nethost::load_hostfxr_with_dotnet_root(PdCString::from_str(dotnet_root).unwrap()) } else { nethost::load_hostfxr() - }.unwrap(); + } + .unwrap(); let actual_env = hostfxr.get_dotnet_environment_info().unwrap(); let expected_env = get_expected_environment_info(); From da1517b4b4137ce19cd4985d822004438c04a091 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:09 +0200 Subject: [PATCH 16/24] Try to fix ci --- src/hostfxr/library.rs | 10 ++++++++++ src/hostfxr/library6_0.rs | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index 267c113..1b94d07 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -62,6 +62,16 @@ impl Hostfxr { pub fn load_with_nethost() -> Result { crate::nethost::load_hostfxr() } + + /// Returns the path to the dotnet root. + pub fn get_dotnet_root(&self) -> PathBuf { + self.get_dotnet_exe().parent().unwrap().to_owned() + } + + /// Returns the path to the dotnet executable of the same installation as hostfxr. + pub fn get_dotnet_exe(&self) -> PathBuf { + self.dotnet_exe.to_os_string().into() + } } /// Either the exit code of the app if it ran successful, otherwise the error from the hosting components. diff --git a/src/hostfxr/library6_0.rs b/src/hostfxr/library6_0.rs index 7fae8c2..cc64ca8 100644 --- a/src/hostfxr/library6_0.rs +++ b/src/hostfxr/library6_0.rs @@ -3,7 +3,7 @@ use hostfxr_sys::hostfxr_dotnet_environment_info; use crate::{ error::{HostingError, HostingResult}, hostfxr::Hostfxr, - pdcstring::PdCStr, + pdcstring::{PdCStr, PdCString}, }; use std::{ffi::c_void, mem::MaybeUninit, path::PathBuf, ptr, slice}; @@ -104,10 +104,12 @@ impl Hostfxr { /// then it will also enumerate SDKs and frameworks from the global install location. #[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net6_0")))] pub fn get_dotnet_environment_info(&self) -> Result { + let dotnet_root = PdCString::from_os_str(self.get_dotnet_root()).ok(); + let dotnet_root_ptr = dotnet_root.as_ref().map_or_else(ptr::null, |p| p.as_ptr()); let mut info = MaybeUninit::::uninit(); let result = unsafe { self.lib.hostfxr_get_dotnet_environment_info( - ptr::null(), + dotnet_root_ptr, ptr::null_mut(), get_dotnet_environment_info_callback, info.as_mut_ptr().cast(), From 70b653a43429b1a63009908d32dfd27b2d4ff386 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:09 +0200 Subject: [PATCH 17/24] Fix clippy warnings --- src/hostfxr/library.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index 1b94d07..e72d86c 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -64,12 +64,12 @@ impl Hostfxr { } /// Returns the path to the dotnet root. - pub fn get_dotnet_root(&self) -> PathBuf { + #[must_use] pub fn get_dotnet_root(&self) -> PathBuf { self.get_dotnet_exe().parent().unwrap().to_owned() } /// Returns the path to the dotnet executable of the same installation as hostfxr. - pub fn get_dotnet_exe(&self) -> PathBuf { + #[must_use] pub fn get_dotnet_exe(&self) -> PathBuf { self.dotnet_exe.to_os_string().into() } } From c3145a1891ef9519d95995aae8ff6a2997326f56 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:09 +0200 Subject: [PATCH 18/24] Update error output of trybuild test --- .../pdcstr-compile-fail.windows.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr b/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr index 9bf60d2..5292fa8 100644 --- a/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr +++ b/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr @@ -6,7 +6,7 @@ error[E0080]: evaluation of constant value failed | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 | 3 | let _ = netcorehost::pdcstr!("\0"); @@ -14,7 +14,7 @@ note: erroneous constant used | = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 | 3 | let _ = netcorehost::pdcstr!("\0"); @@ -30,7 +30,7 @@ error[E0080]: evaluation of constant value failed | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 | 4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); @@ -38,7 +38,7 @@ note: erroneous constant used | = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 | 4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); @@ -54,7 +54,7 @@ error[E0080]: evaluation of constant value failed | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 | 5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); @@ -62,7 +62,7 @@ note: erroneous constant used | = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 | 5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); From e66282053a621958514df8d7283b262ef92521ce Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:09 +0200 Subject: [PATCH 19/24] Cargo fmt --- src/hostfxr/library.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hostfxr/library.rs b/src/hostfxr/library.rs index e72d86c..d4f82d3 100644 --- a/src/hostfxr/library.rs +++ b/src/hostfxr/library.rs @@ -64,12 +64,14 @@ impl Hostfxr { } /// Returns the path to the dotnet root. - #[must_use] pub fn get_dotnet_root(&self) -> PathBuf { + #[must_use] + pub fn get_dotnet_root(&self) -> PathBuf { self.get_dotnet_exe().parent().unwrap().to_owned() } /// Returns the path to the dotnet executable of the same installation as hostfxr. - #[must_use] pub fn get_dotnet_exe(&self) -> PathBuf { + #[must_use] + pub fn get_dotnet_exe(&self) -> PathBuf { self.dotnet_exe.to_os_string().into() } } From dacd12e2c35630023cb0e2a8fca54de5fb76c51f Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:09 +0200 Subject: [PATCH 20/24] Bump version to 0.17 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 896d464..d4c0f9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "netcorehost" -version = "0.16.0" +version = "0.17.0" description = "A Rust library for hosting the .NET Core runtime." readme = "README.md" repository = "https://github.com/OpenByteDev/netcorehost" From bc563e4ec601a9028f75364eedf1e71d7e2e3b18 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:10 +0200 Subject: [PATCH 21/24] Fix clippy warnings --- src/error/hosting_result.rs | 6 +++--- src/nethost.rs | 10 +++++----- src/pdcstring/impl/traits.rs | 1 + src/pdcstring/shared.rs | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/error/hosting_result.rs b/src/error/hosting_result.rs index 2750d8a..94b3131 100644 --- a/src/error/hosting_result.rs +++ b/src/error/hosting_result.rs @@ -1,5 +1,5 @@ use std::convert::TryFrom; -#[cfg(any(nightly, feature = "nightly"))] +#[cfg(feature = "nightly")] use std::ops::{ControlFlow, FromResidual, Try}; use crate::bindings; @@ -116,7 +116,7 @@ impl From for HostingResult { } } -#[cfg(any(nightly, feature = "nightly"))] +#[cfg(feature = "nightly")] impl Try for HostingResult { type Output = HostingSuccess; type Residual = HostingError; @@ -131,7 +131,7 @@ impl Try for HostingResult { } } -#[cfg(any(nightly, feature = "nightly"))] +#[cfg(feature = "nightly")] impl FromResidual for HostingResult { fn from_residual(r: HostingError) -> Self { HostingResult(Err(r)) diff --git a/src/nethost.rs b/src/nethost.rs index d440b4a..90ffaba 100644 --- a/src/nethost.rs +++ b/src/nethost.rs @@ -112,20 +112,20 @@ pub enum LoadHostfxrError { } const unsafe fn maybe_uninit_slice_assume_init_ref(slice: &[MaybeUninit]) -> &[T] { - #[cfg(any(nightly, feature = "nightly"))] + #[cfg(feature = "nightly")] unsafe { MaybeUninit::slice_assume_init_ref(slice) } - #[cfg(not(any(nightly, feature = "nightly")))] + #[cfg(not(feature = "nightly"))] unsafe { - &*(slice as *const [MaybeUninit] as *const [T]) + &*(std::ptr::from_ref::<[MaybeUninit]>(slice) as *const [T]) } } fn maybe_uninit_uninit_array() -> [MaybeUninit; LEN] { - #[cfg(any(nightly, feature = "nightly"))] + #[cfg(feature = "nightly")] return MaybeUninit::::uninit_array::(); - #[cfg(not(any(nightly, feature = "nightly")))] + #[cfg(not(feature = "nightly"))] unsafe { MaybeUninit::<[MaybeUninit; LEN]>::uninit().assume_init() } diff --git a/src/pdcstring/impl/traits.rs b/src/pdcstring/impl/traits.rs index 0d699e4..441d7b1 100644 --- a/src/pdcstring/impl/traits.rs +++ b/src/pdcstring/impl/traits.rs @@ -36,4 +36,5 @@ pub(crate) trait ToStringErrorInner: Debug + Display + Error + Clone { fn index(&self) -> Option; } +#[allow(dead_code)] pub(crate) trait MissingNulTerminatorInner: Debug + Display + Error + Clone {} diff --git a/src/pdcstring/shared.rs b/src/pdcstring/shared.rs index 6dd0672..2b76bf1 100644 --- a/src/pdcstring/shared.rs +++ b/src/pdcstring/shared.rs @@ -67,13 +67,13 @@ impl PdCStr { pub(crate) fn from_inner(inner: &PdCStrInnerImpl) -> &Self { // Safety: // Safe because PdCStr has the same layout as PdCStrInnerImpl - unsafe { &*(inner as *const PdCStrInnerImpl as *const PdCStr) } + unsafe { &*(std::ptr::from_ref::(inner) as *const PdCStr) } } #[inline] pub(crate) fn as_inner(&self) -> &PdCStrInnerImpl { // Safety: // Safe because PdCStr has the same layout as PdCStrInnerImpl - unsafe { &*(self as *const PdCStr as *const PdCStrInnerImpl) } + unsafe { &*(std::ptr::from_ref::(self) as *const PdCStrInnerImpl) } } /// Returns a raw pointer to the string. From 85211535bf432294751089c9cc22d5d3e181c7bd Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:10 +0200 Subject: [PATCH 22/24] Update dependencies --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4c0f9b..46a075a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,16 +15,16 @@ keywords = ["nethost", "hostfxr", "dotnet", "bindings", "coreclr"] num_enum = { version = "0.7", default-features = false } thiserror = { version = "1.0", default-features = false } derive_more = { version = "0.99", features = ["deref", "from", "display"], default-features = false } -hostfxr-sys = { version = "0.10", features = ["enum-map", "undocumented", "wrapper", "optional-apis"], default-features = false } +hostfxr-sys = { version = "0.11", features = ["enum-map", "undocumented", "wrapper", "optional-apis"], default-features = false } coreclr-hosting-shared = { version = "0.1", default-features = false } destruct-drop = { version = "0.2", default-features = false } ffi-opaque = { version = "2.0", default-features = false } -enum-map = { version = "2.6", default-features = false } -once_cell = { version = "1.18", default-features = false } -nethost-sys = { version = ">=0.6.2", optional = true, default-features = false } +enum-map = { version = "2.7", default-features = false } +once_cell = { version = "1.19", default-features = false } +nethost-sys = { version = "0.7", optional = true, default-features = false } [target.'cfg(windows)'.dependencies] -widestring = { version = "1.0", features = ["std"], default-features = false } +widestring = { version = "1.1", features = ["std"], default-features = false } [target.'cfg(not(windows))'.dependencies] cstr = { version = "0.2", default-features = false } @@ -33,7 +33,7 @@ cstr = { version = "0.2", default-features = false } trybuild = "1.0" current_platform = "0.2" glob = "0.3" -widestring = "1.0" +widestring = "1.1" rusty-fork = "0.3" path-absolutize = "3.1" From 4150fd45e0571aca3ae2b002d081527df94ec67b Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:10 +0200 Subject: [PATCH 23/24] Update net version features --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46a075a..6cd5908 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ rusty-fork = "0.3" path-absolutize = "3.1" [features] -default = ["nethost-download", "net7_0"] +default = ["nethost-download", "net8_0"] nethost-download = ["nethost", "nethost-sys/download-nuget"] nethost = ["nethost-sys"] nightly = [] @@ -51,7 +51,8 @@ net5_0 = ["hostfxr-sys/net5_0", "netcore3_0"] net6_0 = ["hostfxr-sys/net6_0", "net5_0"] net7_0 = ["hostfxr-sys/net7_0", "net6_0"] net8_0 = ["hostfxr-sys/net8_0", "net7_0"] -latest = ["hostfxr-sys/latest", "net8_0"] +net9_0 = ["hostfxr-sys/net8_0", "net8_0"] +latest = ["hostfxr-sys/latest", "net9_0"] # Prevent downloading nethost library when building on docs.rs. [package.metadata.docs.rs] From db23f1f5a00749f9812eb2410b6d78a098fbc5a6 Mon Sep 17 00:00:00 2001 From: OpenByte Date: Sat, 13 Jul 2024 21:18:10 +0200 Subject: [PATCH 24/24] Update trybuild output --- .../pdcstr-compile-fail.windows.stderr | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr b/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr index 5292fa8..70f9e64 100644 --- a/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr +++ b/tests/macro-build-tests/pdcstr-compile-fail.windows.stderr @@ -6,29 +6,29 @@ error[E0080]: evaluation of constant value failed | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant encountered - --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 +error[E0080]: evaluation of constant value failed + --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 | -3 | let _ = netcorehost::pdcstr!("\0"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid NUL value found in string literal', $DIR/tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 | - = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant encountered - --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 +error[E0080]: evaluation of constant value failed + --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 | -3 | let _ = netcorehost::pdcstr!("\0"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid NUL value found in string literal', $DIR/tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 | - = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0080]: evaluation of constant value failed - --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 +note: erroneous constant encountered + --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 | -4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid NUL value found in string literal', $DIR/tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 +5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 @@ -39,26 +39,26 @@ note: erroneous constant encountered = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 + --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 | -4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 | let _ = netcorehost::pdcstr!("\0"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0080]: evaluation of constant value failed - --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 +note: erroneous constant encountered + --> tests/macro-build-tests/pdcstr-compile-fail.rs:3:13 | -5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid NUL value found in string literal', $DIR/tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 +3 | let _ = netcorehost::pdcstr!("\0"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> tests/macro-build-tests/pdcstr-compile-fail.rs:5:13 + --> tests/macro-build-tests/pdcstr-compile-fail.rs:4:13 | -5 | let _ = netcorehost::pdcstr!("somerandomteststring\0somerandomteststring"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +4 | let _ = netcorehost::pdcstr!("somerandomteststring\0"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this note originates in the macro `$crate::pdcstring::windows::widestring::u16cstr` which comes from the expansion of the macro `netcorehost::pdcstr` (in Nightly builds, run with -Z macro-backtrace for more info)