Skip to content

Commit

Permalink
More comprehensive workaround for linker issue (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 28, 2021
1 parent e28897d commit 50d9aa4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
8 changes: 3 additions & 5 deletions crates/gen/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ impl Function {
TokenStream::new()
};

// TODO: need to generate libs until Rust supports dynamic linking against DLLs.
// This is actually the DLL name.
let mut link = self.signature.method.impl_map().unwrap().scope().name();
if link == "ext-ms-win-core-iuri-l1-1-0" {
link = "urlmon";
} else if link.starts_with("api-ms-win-core") {

// TODO: workaround for https://github.com/microsoft/windows-rs/issues/463
if link.contains("-ms-win-") || link == "D3DCOMPILER_47" {
link = "onecoreuap";
}

Expand Down
5 changes: 4 additions & 1 deletion crates/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ fn main() {
windows::win32::windows_programming::{
CloseHandle
},
windows::win32::com::{IUri, CreateUri},
windows::win32::com::CreateUri,
windows::win32::structured_storage::{CreateStreamOnHGlobal, STREAM_SEEK},
windows::win32::upnp::UIAnimationTransitionLibrary,
windows::win32::ldap::ldapsearch,
windows::win32::upnp::UIAnimationManager,
windows::win32::game_mode::HasExpandedResources,
windows::win32::debug::MiniDumpWriteDump,
windows::win32::direct3d11::D3DDisassemble11Trace,
);
}
43 changes: 43 additions & 0 deletions crates/tests/tests/win32.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use windows::Abi;

use tests::{
windows::win32::com::CreateUri,
windows::win32::debug::{MiniDumpWriteDump, MINIDUMP_TYPE},
windows::win32::direct3d11::D3DDisassemble11Trace,
windows::win32::direct3d12::D3D12_DEFAULT_BLEND_FACTOR_ALPHA,
windows::win32::direct3d_hlsl::D3DCOMPILER_DLL,
windows::win32::display_devices::RECT,
windows::win32::dxgi::{
CreateDXGIFactory1, IDXGIFactory7, DXGI_ADAPTER_FLAG, DXGI_FORMAT, DXGI_MODE_DESC,
DXGI_MODE_SCALING, DXGI_MODE_SCANLINE_ORDER, DXGI_RATIONAL,
},
windows::win32::game_mode::HasExpandedResources,
windows::win32::ldap::ldapsearch,
windows::win32::security::ACCESS_MODE,
windows::win32::structured_storage::{CreateStreamOnHGlobal, STREAM_SEEK},
Expand Down Expand Up @@ -246,6 +250,45 @@ fn com_inheritance() {
}
}

// Tests for https://github.com/microsoft/windows-rs/issues/463
#[test]
fn onecore_imports() -> windows::Result<()> {
unsafe {
let mut has_expanded_resources = 0;
HasExpandedResources(&mut has_expanded_resources).ok()?;

let mut uri = None;
let uri = CreateUri(
windows::HString::from("http://kennykerr.ca")
.as_wide()
.as_ptr(),
0,
0,
&mut uri,
)
.and_some(uri)?;

let mut port = 0;
uri.GetPort(&mut port).ok()?;
assert!(port == 80);

let result = MiniDumpWriteDump(
HANDLE(0),
0,
HANDLE(0),
MINIDUMP_TYPE::MiniDumpNormal,
std::ptr::null_mut(),
std::ptr::null_mut(),
std::ptr::null_mut(),
);
assert!(result.is_err());

assert!(D3DDisassemble11Trace(std::ptr::null_mut(), 0, None, 0, 0, 0, &mut None).is_err());

Ok(())
}
}

// TODO: light up BSTR as windows::BString

// #[test]
Expand Down

0 comments on commit 50d9aa4

Please sign in to comment.