Skip to content
Merged
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: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ jobs:
run: cargo clippy -p test_cfg_generic
- name: Clippy test_class_hierarchy
run: cargo clippy -p test_class_hierarchy
- name: Clippy test_collection_interop
run: cargo clippy -p test_collection_interop
- name: Clippy test_collections
run: cargo clippy -p test_collections
- name: Clippy test_component
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/raw-dylib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ jobs:
run: cargo test -p test_cfg_generic --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_class_hierarchy
run: cargo test -p test_class_hierarchy --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_collection_interop
run: cargo test -p test_collection_interop --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_collections
run: cargo test -p test_collections --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_component
Expand Down Expand Up @@ -260,10 +262,10 @@ jobs:
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_ref_params
run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
Expand Down Expand Up @@ -362,10 +364,10 @@ jobs:
run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnu
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_msvc
run: cargo test -p windows_x86_64_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Check diff
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ jobs:
run: cargo test -p test_cfg_generic --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_class_hierarchy
run: cargo test -p test_class_hierarchy --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_collection_interop
run: cargo test -p test_collection_interop --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_collections
run: cargo test -p test_collections --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_component
Expand Down Expand Up @@ -257,10 +259,10 @@ jobs:
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_ref_params
run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
Expand Down Expand Up @@ -359,10 +361,10 @@ jobs:
run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnu
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_msvc
run: cargo test -p windows_x86_64_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Check diff
Expand Down
27 changes: 27 additions & 0 deletions crates/tests/winrt/collection_interop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "test_collection_interop"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
doc = false
doctest = false

[dependencies.windows-core]
workspace = true

[dependencies.windows]
workspace = true
features = [
"Foundation_Collections",
]

[build-dependencies.windows-bindgen]
workspace = true

[build-dependencies]
cc = "1.0"

[build-dependencies.cppwinrt]
workspace = true
61 changes: 61 additions & 0 deletions crates/tests/winrt/collection_interop/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
fn main() {
if !cfg!(target_env = "msvc") {
return;
}

println!("cargo:rerun-if-changed=src/test.idl");
let metadata_dir = format!("{}\\System32\\WinMetadata", env!("windir"));
let mut command = std::process::Command::new("midlrt.exe");
println!("cargo:rerun-if-changed=src/interop.cpp");
println!("cargo:rustc-link-lib=onecoreuap");

command.args([
"/winrt",
"/nomidl",
"/h",
"nul",
"/metadata_dir",
&metadata_dir,
"/reference",
&format!("{metadata_dir}\\Windows.Foundation.winmd"),
"/winmd",
"test.winmd",
"src/test.idl",
]);

if !command.status().unwrap().success() {
panic!("Failed to run midlrt");
}

windows_bindgen::bindgen([
"--in",
"test.winmd",
&metadata_dir,
"--out",
"src/bindings.rs",
"--filter",
"Test",
"--implement",
"--flat",
"--reference",
"windows,skip-root,Windows",
]);

let include = std::env::var("OUT_DIR").unwrap();

cppwinrt::cppwinrt([
"-in",
"test.winmd",
&format!("{}\\System32\\WinMetadata", env!("windir")),
"-out",
&include,
]);

cc::Build::new()
.cpp(true)
.std("c++20")
.flag("/EHsc")
.file("src/interop.cpp")
.include(include)
.compile("interop");
}
198 changes: 198 additions & 0 deletions crates/tests/winrt/collection_interop/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
// Bindings generated by `windows-bindgen` 0.59.0

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_core::imp::define_interface!(ITest, ITest_Vtbl, 0xab9ee103_2921_5ff1_95b3_6b72ea1d289f);
impl windows_core::RuntimeType for ITest {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
windows_core::imp::interface_hierarchy!(ITest, windows_core::IUnknown, windows_core::IInspectable);
impl ITest {
pub fn TestIterable<P0>(&self, collection: P0, values: &[i32]) -> windows_core::Result<()>
where
P0: windows_core::Param<windows::Foundation::Collections::IIterable<i32>>,
{
let this = self;
unsafe {
(windows_core::Interface::vtable(this).TestIterable)(
windows_core::Interface::as_raw(this),
collection.param().abi(),
values.len().try_into().unwrap(),
values.as_ptr(),
)
.ok()
}
}
pub fn GetIterable(
&self,
values: &[i32],
) -> windows_core::Result<windows::Foundation::Collections::IIterable<i32>> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).GetIterable)(
windows_core::Interface::as_raw(this),
values.len().try_into().unwrap(),
values.as_ptr(),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
}
}
pub fn GetMapView(
&self,
values: &[i32],
) -> windows_core::Result<
windows::Foundation::Collections::IMapView<
i32,
windows::Foundation::Collections::IVectorView<i32>,
>,
> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).GetMapView)(
windows_core::Interface::as_raw(this),
values.len().try_into().unwrap(),
values.as_ptr(),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
}
}
}
impl windows_core::RuntimeName for ITest {
const NAME: &'static str = "Test.ITest";
}
pub trait ITest_Impl: windows_core::IUnknownImpl {
fn TestIterable(
&self,
collection: windows_core::Ref<'_, windows::Foundation::Collections::IIterable<i32>>,
values: &[i32],
) -> windows_core::Result<()>;
fn GetIterable(
&self,
values: &[i32],
) -> windows_core::Result<windows::Foundation::Collections::IIterable<i32>>;
fn GetMapView(
&self,
values: &[i32],
) -> windows_core::Result<
windows::Foundation::Collections::IMapView<
i32,
windows::Foundation::Collections::IVectorView<i32>,
>,
>;
}
impl ITest_Vtbl {
pub const fn new<Identity: ITest_Impl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn TestIterable<Identity: ITest_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
collection: *mut core::ffi::c_void,
values_array_size: u32,
values: *const i32,
) -> windows_core::HRESULT {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
ITest_Impl::TestIterable(
this,
core::mem::transmute_copy(&collection),
core::slice::from_raw_parts(
core::mem::transmute_copy(&values),
values_array_size as usize,
),
)
.into()
}
}
unsafe extern "system" fn GetIterable<Identity: ITest_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
values_array_size: u32,
values: *const i32,
result__: *mut *mut core::ffi::c_void,
) -> windows_core::HRESULT {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match ITest_Impl::GetIterable(
this,
core::slice::from_raw_parts(
core::mem::transmute_copy(&values),
values_array_size as usize,
),
) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
core::mem::forget(ok__);
windows_core::HRESULT(0)
}
Err(err) => err.into(),
}
}
}
unsafe extern "system" fn GetMapView<Identity: ITest_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
values_array_size: u32,
values: *const i32,
result__: *mut *mut core::ffi::c_void,
) -> windows_core::HRESULT {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match ITest_Impl::GetMapView(
this,
core::slice::from_raw_parts(
core::mem::transmute_copy(&values),
values_array_size as usize,
),
) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
core::mem::forget(ok__);
windows_core::HRESULT(0)
}
Err(err) => err.into(),
}
}
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<Identity, ITest, OFFSET>(),
TestIterable: TestIterable::<Identity, OFFSET>,
GetIterable: GetIterable::<Identity, OFFSET>,
GetMapView: GetMapView::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
iid == &<ITest as windows_core::Interface>::IID
}
}
#[repr(C)]
pub struct ITest_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub TestIterable: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut core::ffi::c_void,
u32,
*const i32,
) -> windows_core::HRESULT,
pub GetIterable: unsafe extern "system" fn(
*mut core::ffi::c_void,
u32,
*const i32,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
pub GetMapView: unsafe extern "system" fn(
*mut core::ffi::c_void,
u32,
*const i32,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}
Loading