Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving from com-rs to tinycom #36

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default-target = "x86_64-pc-windows-msvc"

[dependencies]
libloading = "0.7.0"
com-rs = "0.2.1"
tinycom = "0.1.0"
bitflags = "1.2.1"
widestring = "0.5.0"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::os::{HRESULT, LPCWSTR, LPWSTR};
pub(crate) use crate::unknown::IDxcUnknownShim;
use com_rs::{com_interface, iid, IUnknown, IID};
use std::ffi::c_void;
use tinycom::{com_interface, iid, IUnknown, IID};

pub type DxcCreateInstanceProc =
extern "system" fn(rclsid: &IID, riid: &IID, ppv: *mut *mut c_void) -> HRESULT;
Expand Down
2 changes: 1 addition & 1 deletion src/intellisense/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::os::{BSTR, HRESULT, LPCSTR, LPSTR};
pub(crate) use crate::unknown::IDxcUnknownShim;
use bitflags::bitflags;
use com_rs::{com_interface, iid, IUnknown};
use tinycom::{com_interface, iid, IUnknown};

bitflags! {
pub struct DxcGlobalOptions : u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/intellisense/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::intellisense::ffi::*;
use crate::os::{CoTaskMemFree, BSTR, LPSTR};
use crate::utils::Result;
use crate::wrapper::Dxc;
use com_rs::ComPtr;
use std::ffi::CString;
use tinycom::ComPtr;

#[derive(Debug)]
pub struct DxcIntellisense {
Expand Down
5 changes: 1 addition & 4 deletions src/unknown.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#[cfg(not(windows))]
use crate::os::HRESULT;
use com_rs::{com_interface, IUnknown, IID};

extern "C" {
static IID_IUnknown: IID;
}
use tinycom::{com_interface, IID_IUnknown, IUnknown};

#[cfg(not(windows))]
// Steal the interface ID from IUnknown:
Expand Down
5 changes: 0 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ impl HRESULT {
///
/// Note that `v` is passed by value and is not a closure that is executed
/// lazily. Use the short-circuiting `?` operator for such cases:
/// ```no_run
/// let mut blob: ComPtr<IDxcBlob> = ComPtr::new();
/// unsafe { self.inner.get_result(blob.as_mut_ptr()) }.result()?;
/// Ok(DxcBlob::new(blob))
/// ```
pub fn result_with_success<T>(self, v: T) -> Result<T> {
if self.is_err() {
Err(HassleError::Win32Error(self))
Expand Down
36 changes: 18 additions & 18 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use crate::ffi::*;
use crate::os::{HRESULT, LPCWSTR, LPWSTR, WCHAR};
use crate::utils::{from_wide, to_wide, HassleError, Result};
use com_rs::ComPtr;
use libloading::{Library, Symbol};
use std::path::{Path, PathBuf};
use std::pin::Pin;
use tinycom::ComPtr;

#[derive(Debug)]
pub struct DxcBlob {
Expand Down Expand Up @@ -113,17 +113,17 @@ pub trait DxcIncludeHandler {
#[repr(C)]
struct DxcIncludeHandlerWrapperVtbl {
query_interface: extern "system" fn(
*const com_rs::IUnknown,
&com_rs::IID,
*const tinycom::IUnknown,
&tinycom::IID,
*mut *mut core::ffi::c_void,
) -> HRESULT,
add_ref: extern "system" fn(*const com_rs::IUnknown) -> HRESULT,
release: extern "system" fn(*const com_rs::IUnknown) -> HRESULT,
) -> tinycom::HResult,
add_ref: extern "system" fn(*const tinycom::IUnknown) -> tinycom::HResult,
release: extern "system" fn(*const tinycom::IUnknown) -> tinycom::HResult,
#[cfg(not(windows))]
complete_object_destructor: extern "system" fn(*const com_rs::IUnknown) -> HRESULT,
complete_object_destructor: extern "system" fn(*const tinycom::IUnknown) -> tinycom::HResult,
#[cfg(not(windows))]
deleting_destructor: extern "system" fn(*const com_rs::IUnknown) -> HRESULT,
load_source: extern "system" fn(*mut com_rs::IUnknown, LPCWSTR, *mut *mut IDxcBlob) -> HRESULT,
deleting_destructor: extern "system" fn(*const tinycom::IUnknown) -> tinycom::HResult,
load_source: extern "system" fn(*mut tinycom::IUnknown, LPCWSTR, *mut *mut IDxcBlob) -> tinycom::HResult,
}

#[repr(C)]
Expand All @@ -136,22 +136,22 @@ struct DxcIncludeHandlerWrapper<'a, 'i> {

impl<'a, 'i> DxcIncludeHandlerWrapper<'a, 'i> {
extern "system" fn query_interface(
_me: *const com_rs::IUnknown,
_rrid: &com_rs::IID,
_me: *const tinycom::IUnknown,
_rrid: &tinycom::IID,
_ppv_obj: *mut *mut core::ffi::c_void,
) -> HRESULT {
HRESULT(0) // dummy impl
) -> tinycom::HResult {
0 // dummy impl
}

extern "system" fn dummy(_me: *const com_rs::IUnknown) -> HRESULT {
HRESULT(0) // dummy impl
extern "system" fn dummy(_me: *const tinycom::IUnknown) -> tinycom::HResult {
0 // dummy impl
}

extern "system" fn load_source(
me: *mut com_rs::IUnknown,
me: *mut tinycom::IUnknown,
filename: LPCWSTR,
include_source: *mut *mut IDxcBlob,
) -> HRESULT {
) -> tinycom::HResult {
let me = me.cast::<DxcIncludeHandlerWrapper>();

let filename = crate::utils::from_wide(filename);
Expand Down Expand Up @@ -476,7 +476,7 @@ fn dxcompiler_lib_name() -> &'static Path {

#[cfg(any(target_os = "linux", target_os = "android"))]
fn dxcompiler_lib_name() -> &'static Path {
Path::new("./libdxcompiler.so")
Path::new("libdxcompiler.so")
}

#[cfg(target_os = "macos")]
Expand Down