Skip to content

Support running on Linux/WSL targets #1863

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

Merged
merged 4 commits into from
Jul 5, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ jobs:

cargo_sys:
name: Check windows-sys
runs-on: windows-2019
strategy:
matrix:
rust: [1.46.0, stable, nightly]
runs-on:
- windows-2019
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -59,10 +62,13 @@ jobs:

cargo_windows:
name: Check windows
runs-on: windows-2019
strategy:
matrix:
rust: [1.59.0, stable, nightly]
runs-on:
- windows-2019
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
99 changes: 32 additions & 67 deletions crates/libs/bindgen/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
Some(link) => quote! { #[link(name = #link, kind = "static")] },
None => {
if gen.namespace.starts_with("Windows.") {
quote! { #[link(name = "windows")] }
quote! { #[cfg_attr(windows, link(name = "windows"))] }
} else {
let impl_map = gen.reader.method_def_impl_map(def).expect("ImplMap not found");
let scope = gen.reader.impl_map_scope(impl_map);
Expand All @@ -75,17 +75,12 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints T: ::windows::core::Interface>(#params) -> ::windows::core::Result<T> {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
let mut result__ = ::core::option::Option::None;
#name(#args).and_some(result__)
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
let mut result__ = ::core::option::Option::None;
#name(#args).and_some(result__)
}
}
}
Expand All @@ -98,16 +93,11 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints T: ::windows::core::Interface>(#params result__: *mut ::core::option::Option<T>) -> ::windows::core::Result<()> {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#name(#args).ok()
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
#name(#args).ok()
}
}
}
Expand All @@ -124,17 +114,12 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) -> ::windows::core::Result<#return_type_tokens> {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
let mut result__ = ::core::mem::MaybeUninit::<#abi_return_type_tokens>::zeroed();
#name(#args ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<#return_type_tokens>(result__)
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
let mut result__ = ::core::mem::MaybeUninit::<#abi_return_type_tokens>::zeroed();
#name(#args ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<#return_type_tokens>(result__)
}
}
}
Expand All @@ -147,16 +132,11 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) -> ::windows::core::Result<()> {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#name(#args).ok()
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
#name(#args).ok()
}
}
}
Expand All @@ -171,17 +151,12 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) -> ::windows::core::Result<#return_type> {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) -> #return_type;
}
let result__ = #name(#args);
(!result__.is_invalid()).then(||result__).ok_or_else(::windows::core::Error::from_win32)
#link_attr
extern "system" {
fn #name(#(#abi_params),*) -> #return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
let result__ = #name(#args);
(!result__.is_invalid()).then(||result__).ok_or_else(::windows::core::Error::from_win32)
}
}
} else {
Expand All @@ -193,16 +168,11 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) #abi_return_type {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
::core::mem::transmute(#name(#args))
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
::core::mem::transmute(#name(#args))
}
}
}
Expand All @@ -217,16 +187,11 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) #does_not_return {
#[cfg(windows)]
{
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #does_not_return;
}
#name(#args)
#link_attr
extern "system" {
fn #name(#(#abi_params),*) #does_not_return;
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
#name(#args)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn namespace(gen: &Gen, tree: &Tree) -> String {
if !methods.is_empty() {
let methods = methods.values();
functions = vec![quote! {
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#(#methods)*
}
Expand Down
3 changes: 2 additions & 1 deletion crates/libs/metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ default-target = "x86_64-pc-windows-msvc"
targets = []

[dependencies.windows-sys]
version = "0.36.1"
path = "../sys"
version = "0.38"
features = [
"Win32_System_SystemServices",
"Win32_System_Diagnostics_Debug",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_AI_MachineLearning_DirectML\"`, `\"Win32_Graphics_Direct3D12\"`*"]
#[cfg(feature = "Win32_Graphics_Direct3D12")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_AI_MachineLearning_WinML\"`*"]
pub fn MLCreateOperatorRegistry(registry: *mut IMLOperatorRegistry) -> ::windows_sys::core::HRESULT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
pub fn DRMAcquireAdvisories(hlicensestorage: u32, wszlicense: ::windows_sys::core::PCWSTR, wszurl: ::windows_sys::core::PCWSTR, pvcontext: *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Data/Xml/XmlLite/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`, `\"Win32_System_Com\"`*"]
#[cfg(feature = "Win32_System_Com")]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/AllJoyn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_BiometricFramework\"`*"]
pub fn WinBioAcquireFocus() -> ::windows_sys::core::HRESULT;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Bluetooth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Bluetooth\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_DeviceAccess\"`*"]
pub fn CreateDeviceAccessInstance(deviceinterfacepath: ::windows_sys::core::PCWSTR, desiredaccess: u32, createasync: *mut ICreateDeviceAccessAsync) -> ::windows_sys::core::HRESULT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_DeviceAndDriverInstallation\"`*"]
pub fn CMP_WaitNoPendingInstallEvents(dwtimeout: u32) -> u32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_DeviceQuery\"`*"]
pub fn DevCloseObjectQuery(hdevquery: *const HDEVQUERY__);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Display/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Display\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Enumeration_Pnp\"`*"]
pub fn SwDeviceClose(hswdevice: HSWDEVICE);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Fax/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Fax\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_HumanInterfaceDevice\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_PortableDevices\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Sensors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Sensors\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com_StructuredStorage\"`, `\"Win32_UI_Shell_PropertiesSystem\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com_StructuredStorage", feature = "Win32_UI_Shell_PropertiesSystem"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_SerialCommunication\"`*"]
pub fn ComDBClaimNextFreePort(hcomdb: HCOMDB, comnumber: *mut u32) -> i32;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Tapi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Tapi\"`, `\"Win32_System_Com\"`*"]
#[cfg(feature = "Win32_System_Com")]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Devices/Usb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_Usb\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Devices_WebServicesOnDevices\"`*"]
pub fn WSDAllocateLinkedMemory(pparent: *mut ::core::ffi::c_void, cbsize: usize) -> *mut ::core::ffi::c_void;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Foundation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Foundation\"`*"]
pub fn CloseHandle(hobject: HANDLE) -> BOOL;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Gaming/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Gaming\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Globalization/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Globalization\"`*"]
pub fn CompareStringA(locale: u32, dwcmpflags: u32, lpstring1: *const i8, cchcount1: i32, lpstring2: *const i8, cchcount2: i32) -> i32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_CompositionSwapchain\"`*"]
pub fn CreatePresentationFactory(d3ddevice: ::windows_sys::core::IUnknown, riid: *const ::windows_sys::core::GUID, presentationfactory: *mut *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Graphics/DXCore/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_DXCore\"`*"]
pub fn DXCoreCreateAdapterFactory(riid: *const ::windows_sys::core::GUID, ppvfactory: *mut *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/sys/src/Windows/Win32/Graphics/Direct2D/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "Win32_Graphics_Direct2D_Common")]
pub mod Common;
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_Direct2D\"`, `\"Foundation_Numerics\"`*"]
#[cfg(feature = "Foundation_Numerics")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_Direct3D_Dxc\"`*"]
pub fn DxcCreateInstance(rclsid: *const ::windows_sys::core::GUID, riid: *const ::windows_sys::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_Direct3D_Fxc\"`*"]
pub fn D3DCompile(psrcdata: *const ::core::ffi::c_void, srcdatasize: usize, psourcename: ::windows_sys::core::PCSTR, pdefines: *const super::D3D_SHADER_MACRO, pinclude: super::ID3DInclude, pentrypoint: ::windows_sys::core::PCSTR, ptarget: ::windows_sys::core::PCSTR, flags1: u32, flags2: u32, ppcode: *mut super::ID3DBlob, pperrormsgs: *mut super::ID3DBlob) -> ::windows_sys::core::HRESULT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_Direct3D10\"`, `\"Win32_Graphics_Direct3D\"`*"]
#[cfg(feature = "Win32_Graphics_Direct3D")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[link(name = "windows")]
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
#[doc = "*Required features: `\"Win32_Graphics_Direct3D11\"`, `\"Win32_Foundation\"`, `\"Win32_Graphics_Direct3D\"`, `\"Win32_Graphics_Dxgi\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Dxgi"))]
Expand Down
Loading