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

Add test component #1666

Merged
merged 33 commits into from
Apr 8, 2022
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
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,19 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Update toolchain
run: rustup update --no-self-update nightly && rustup default nightly
run: rustup update --no-self-update nightly && rustup default nightly-x86_64-pc-windows-msvc
- name: Install clippy
run: rustup component add clippy
- name: Configure environment
shell: pwsh
run: |
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64" >> $env:GITHUB_PATH
((Resolve-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\*\bin\Hostx64\x64")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
(Join-Path $env:GITHUB_WORKSPACE "target\debug\deps").ToString() >> $env:GITHUB_PATH
(Join-Path $env:GITHUB_WORKSPACE "target\test\debug\deps").ToString() >> $env:GITHUB_PATH
"INCLUDE=C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt" `
>> $env:GITHUB_ENV
- name: Run cargo clippy
run: |
cargo clippy -p windows-bindgen &&
Expand Down Expand Up @@ -138,6 +148,8 @@ jobs:
cargo clippy -p test_matrix3x2 &&
cargo clippy -p test_mshtml &&
cargo clippy -p test_nightly_class_factory &&
cargo clippy -p test_nightly_component &&
cargo clippy -p test_nightly_component_client &&
cargo clippy -p test_nightly_data_object &&
cargo clippy -p test_nightly_drop_target &&
cargo clippy -p test_nightly_identity &&
Expand Down
46 changes: 36 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Update toolchain
run: rustup update --no-self-update ${{ matrix.version }} && rustup default ${{ matrix.version }}
run: rustup update --no-self-update ${{ matrix.version }} && rustup default ${{ matrix.version }}-${{ matrix.target }}
- name: Add toolchain target
run: rustup target add ${{ matrix.target }}
- name: Install clippy
Expand All @@ -47,18 +47,41 @@ jobs:
ar = `"C:\\msys64\\mingw32\\bin\\ar.exe`"
"@
if: contains(matrix.target, 'windows-gnu')
- name: Configure environment for GNU toolchain
- name: Configure environment
shell: pwsh
run: |
if("${{ matrix.target }}" -eq "i686-pc-windows-gnu") {
$MingwPath = "C:\msys64\mingw32\bin"
} else {
$MingwPath = "C:\msys64\mingw64\bin"
switch -Wildcard ("${{ matrix.target }}")
{
"i686-pc-windows-gnu"
{
"C:\msys64\mingw32\bin" >> $env:GITHUB_PATH
}
"x86_64-pc-windows-gnu"
{
"C:\msys64\mingw64\bin" >> $env:GITHUB_PATH
}
"i686*"
{
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x86" >> $env:GITHUB_PATH
((Resolve-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\*\bin\Hostx86\x86")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
}
"x86_64*"
{
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64" >> $env:GITHUB_PATH
((Resolve-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\*\bin\Hostx64\x64")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
}
"*"
{
(Join-Path $env:GITHUB_WORKSPACE "target\debug\deps").ToString() >> $env:GITHUB_PATH
(Join-Path $env:GITHUB_WORKSPACE "target\test\debug\deps").ToString() >> $env:GITHUB_PATH
"INCLUDE=C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt" `
>> $env:GITHUB_ENV
}
}
$MingwPath | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
if: contains(matrix.target, 'windows-gnu')
- name: Test stable
run: |
run: >
cargo test --target ${{ matrix.target }} -p windows-bindgen &&
cargo test --target ${{ matrix.target }} -p windows-interface &&
cargo test --target ${{ matrix.target }} -p windows-metadata &&
Expand Down Expand Up @@ -112,7 +135,8 @@ jobs:
if: matrix.version == 'stable'

- name: Test nightly
run: |
shell: cmd
run: >
cargo test --target ${{ matrix.target }} -p windows-implement &&
cargo test --target ${{ matrix.target }} -p sample_com_uri &&
cargo test --target ${{ matrix.target }} -p sample_consent &&
Expand All @@ -136,6 +160,8 @@ jobs:
cargo test --target ${{ matrix.target }} -p sample_xaml_app &&
cargo test --target ${{ matrix.target }} -p sample_xml &&
cargo test --target ${{ matrix.target }} -p test_nightly_class_factory &&
cargo test --target ${{ matrix.target }} -p test_nightly_component &&
cargo test --target ${{ matrix.target }} -p test_nightly_component_client &&
cargo test --target ${{ matrix.target }} -p test_nightly_data_object &&
cargo test --target ${{ matrix.target }} -p test_nightly_drop_target &&
cargo test --target ${{ matrix.target }} -p test_nightly_identity &&
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode
.vs
.windows
target
packages
obj
Expand Down
17 changes: 17 additions & 0 deletions crates/tests/nightly_component/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "test_nightly_component"
version = "0.0.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies.windows]
path = "../../libs/windows"
features = [
"implement",
"Win32_Foundation",
]

[build-dependencies.windows-bindgen]
path = "../../libs/bindgen"
21 changes: 21 additions & 0 deletions crates/tests/nightly_component/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::fs::*;
use std::io::prelude::*;
use std::process::*;
use windows_bindgen::*;

fn main() -> std::io::Result<()> {
println!("cargo:rerun-if-changed=src/component.idl");
let metadata_dir = format!("{}\\System32\\WinMetadata", env!("windir"));
std::fs::create_dir_all(".windows/winmd")?;

Command::new("midlrt.exe").arg("/winrt").arg("/nomidl").arg("/h").arg("nul").arg("/metadata_dir").arg(&metadata_dir).arg("/reference").arg(format!("{}\\Windows.Foundation.winmd", metadata_dir)).arg("/winmd").arg(".windows/winmd/component.winmd").arg("src/component.idl").status()?;

let gen = Gen { namespace: "test_nightly_component", component: true, ..Default::default() };
let mut bindings = File::create("src/bindings.rs")?;
bindings.write_all(gen_namespace(&gen).as_bytes())?;
bindings.write_all(gen_namespace_impl(&gen).as_bytes())?;
drop(bindings);

Command::new("rustfmt").arg("src/bindings.rs").status()?;
Ok(())
}
145 changes: 145 additions & 0 deletions crates/tests/nightly_component/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals, clashing_extern_declarations, clippy::all)]
#[repr(transparent)]
pub struct Class(::windows::core::IUnknown);
impl Class {
pub fn new() -> ::windows::core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
}
fn IActivationFactory<R, F: FnOnce(&::windows::core::IActivationFactory) -> ::windows::core::Result<R>>(callback: F) -> ::windows::core::Result<R> {
static mut SHARED: ::windows::core::FactoryCache<Class, ::windows::core::IActivationFactory> = ::windows::core::FactoryCache::new();
unsafe { SHARED.call(callback) }
}
pub fn Property(&self) -> ::windows::core::Result<i32> {
let this = self;
unsafe {
let mut result__: i32 = ::core::mem::zeroed();
(::windows::core::Interface::vtable(this).Property)(::core::mem::transmute_copy(this), &mut result__).from_abi::<i32>(result__)
}
}
pub fn SetProperty(&self, value: i32) -> ::windows::core::Result<()> {
let this = self;
unsafe { (::windows::core::Interface::vtable(this).SetProperty)(::core::mem::transmute_copy(this), value).ok() }
}
}
impl ::core::clone::Clone for Class {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl ::core::cmp::PartialEq for Class {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for Class {}
impl ::core::fmt::Debug for Class {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("Class").field(&self.0).finish()
}
}
unsafe impl ::windows::core::RuntimeType for Class {
const SIGNATURE: ::windows::core::ConstBuffer = ::windows::core::ConstBuffer::from_slice(b"rc(test_nightly_component.Class;{9c2c130e-93de-591a-a879-912616487c8b})");
type DefaultType = ::core::option::Option<Self>;
fn from_default(from: &Self::DefaultType) -> ::windows::core::Result<Self> {
from.as_ref().cloned().ok_or(::windows::core::Error::OK)
}
}
unsafe impl ::windows::core::Interface for Class {
type Vtable = IClass_Vtbl;
const IID: ::windows::core::GUID = <IClass as ::windows::core::Interface>::IID;
}
impl ::windows::core::RuntimeName for Class {
const NAME: &'static str = "test_nightly_component.Class";
}
impl ::core::convert::From<Class> for ::windows::core::IUnknown {
fn from(value: Class) -> Self {
unsafe { ::core::mem::transmute(value) }
}
}
impl ::core::convert::From<&Class> for ::windows::core::IUnknown {
fn from(value: &Class) -> Self {
::core::convert::From::from(::core::clone::Clone::clone(value))
}
}
impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IUnknown> for Class {
fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IUnknown> {
::windows::core::Param::Owned(unsafe { ::core::mem::transmute(self) })
}
}
impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IUnknown> for &'a Class {
fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IUnknown> {
::windows::core::Param::Borrowed(unsafe { ::core::mem::transmute(self) })
}
}
impl ::core::convert::From<Class> for ::windows::core::IInspectable {
fn from(value: Class) -> Self {
unsafe { ::core::mem::transmute(value) }
}
}
impl ::core::convert::From<&Class> for ::windows::core::IInspectable {
fn from(value: &Class) -> Self {
::core::convert::From::from(::core::clone::Clone::clone(value))
}
}
impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IInspectable> for Class {
fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IInspectable> {
::windows::core::Param::Owned(unsafe { ::core::mem::transmute(self) })
}
}
impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IInspectable> for &'a Class {
fn into_param(self) -> ::windows::core::Param<'a, ::windows::core::IInspectable> {
::windows::core::Param::Borrowed(unsafe { ::core::mem::transmute(self) })
}
}
unsafe impl ::core::marker::Send for Class {}
unsafe impl ::core::marker::Sync for Class {}
#[doc(hidden)]
#[repr(transparent)]
pub struct IClass(::windows::core::IUnknown);
unsafe impl ::windows::core::Interface for IClass {
type Vtable = IClass_Vtbl;
const IID: ::windows::core::GUID = ::windows::core::GUID::from_u128(0x9c2c130e_93de_591a_a879_912616487c8b);
}
#[repr(C)]
#[doc(hidden)]
pub struct IClass_Vtbl {
pub base__: ::windows::core::IInspectableVtbl,
pub Property: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, result__: *mut i32) -> ::windows::core::HRESULT,
pub SetProperty: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, value: i32) -> ::windows::core::HRESULT,
}
pub trait IClass_Impl: Sized {
fn Property(&self) -> ::windows::core::Result<i32>;
fn SetProperty(&self, value: i32) -> ::windows::core::Result<()>;
}
impl ::windows::core::RuntimeName for IClass {
const NAME: &'static str = "test_nightly_component.IClass";
}
impl IClass_Vtbl {
pub const fn new<Identity: ::windows::core::IUnknownImpl, Impl: IClass_Impl, const OFFSET: isize>() -> IClass_Vtbl {
unsafe extern "system" fn Property<Identity: ::windows::core::IUnknownImpl, Impl: IClass_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, result__: *mut i32) -> ::windows::core::HRESULT {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut Identity;
let this = (*this).get_impl() as *mut Impl;
match (*this).Property() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
::core::result::Result::Err(err) => err.into(),
}
}
unsafe extern "system" fn SetProperty<Identity: ::windows::core::IUnknownImpl, Impl: IClass_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, value: i32) -> ::windows::core::HRESULT {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut Identity;
let this = (*this).get_impl() as *mut Impl;
(*this).SetProperty(value).into()
}
Self {
base__: ::windows::core::IInspectableVtbl::new::<Identity, IClass, OFFSET>(),
Property: Property::<Identity, Impl, OFFSET>,
SetProperty: SetProperty::<Identity, Impl, OFFSET>,
}
}
pub fn matches(iid: &windows::core::GUID) -> bool {
iid == &<IClass as ::windows::core::Interface>::IID
}
}
8 changes: 8 additions & 0 deletions crates/tests/nightly_component/src/component.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace test_nightly_component
{
runtimeclass Class
{
Class();
Int32 Property;
}
}
37 changes: 37 additions & 0 deletions crates/tests/nightly_component/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
mod bindings;
use std::mem::*;
use std::sync::*;
use windows::core::*;
use windows::Win32::Foundation::*;

#[implement(bindings::Class)]
struct Class(RwLock<i32>);
rylev marked this conversation as resolved.
Show resolved Hide resolved

impl bindings::IClass_Impl for Class {
fn Property(&self) -> Result<i32> {
let reader = self.0.read().unwrap();
Ok(*reader)
}
fn SetProperty(&self, value: i32) -> Result<()> {
let mut writer = self.0.write().unwrap();
*writer = value;
Ok(())
}
}

#[implement(IActivationFactory)]
struct ClassFactory;

impl IActivationFactory_Impl for ClassFactory {
fn ActivateInstance(&self) -> Result<IInspectable> {
Ok(Class(RwLock::new(0)).into())
}
}

#[no_mangle]
unsafe extern "stdcall" fn DllGetActivationFactory(_name: ManuallyDrop<HSTRING>, result: *mut *mut std::ffi::c_void) -> HRESULT {
// TODO: check class name
let factory: IActivationFactory = ClassFactory.into();
*result = transmute(factory);
S_OK
}
18 changes: 18 additions & 0 deletions crates/tests/nightly_component_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "test_nightly_component_client"
version = "0.0.0"
authors = ["Microsoft"]
edition = "2021"

[dependencies.windows]
path = "../../libs/windows"
features = [
"alloc",
"Win32_Foundation",
]

[build-dependencies.windows-bindgen]
path = "../../libs/bindgen"

[build-dependencies.test_nightly_component]
path = "../nightly_component"
18 changes: 18 additions & 0 deletions crates/tests/nightly_component_client/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::fs::*;
use std::io::prelude::*;
use std::process::*;
use windows_bindgen::*;

fn main() -> std::io::Result<()> {
create_dir_all(".windows/winmd")?;
copy("../nightly_component/.windows/winmd/component.winmd", ".windows/winmd/component.winmd")?;

let gen = Gen { namespace: "test_nightly_component", component: true, ..Default::default() };
let mut bindings = File::create("src/bindings.rs")?;
bindings.write_all(gen_namespace(&gen).as_bytes())?;
bindings.write_all(gen_namespace_impl(&gen).as_bytes())?;
drop(bindings);

Command::new("rustfmt").arg("src/bindings.rs").status()?;
Ok(())
}
Loading