Skip to content

Commit

Permalink
Merge branch 'master' into 0.53.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Feb 22, 2024
2 parents 579ce7a + 352bd45 commit d070fbc
Show file tree
Hide file tree
Showing 173 changed files with 43,106 additions and 21,971 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: web

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: 'pages'
cancel-in-progress: false

on:
pull_request:
push:
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
branches:
- master
workflow_dispatch:

jobs:
web:
name: web
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: current

- name: Install dependencies
run: npm install
working-directory: web/features

- name: Build project
run: npm run build
working-directory: web/features

- name: Stage website
run: |
mkdir -p web/build/features
cp -r web/features/build/* web/build/features
if: github.event_name != 'pull_request'

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: web/build
if: github.event_name != 'pull_request'

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
if: github.event_name != 'pull_request'
7 changes: 7 additions & 0 deletions crates/libs/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ features = ["full", "extra-traits"]
[dependencies.proc-macro2]
version = "1.0"
features = ["span-locations"]

[dependencies.serde]
version = "1.0.196"
features = ["derive"]

[dependencies.serde_json]
version = "1.0.113"
1 change: 0 additions & 1 deletion crates/libs/bindgen/src/rdl/from_reader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use crate::Result;
use tokens::{quote, to_ident, TokenStream};

pub fn from_reader(reader: &'static metadata::Reader, mut config: std::collections::BTreeMap<&str, &str>, output: &str) -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions crates/libs/bindgen/src/rdl/to_winmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::winmd::{self, writer};
use crate::Result;
use crate::winmd::writer;

// TODO: store span in winmd so that errors resolving type references can be traced back to file/line/column
use std::collections::HashMap;
Expand Down
22 changes: 17 additions & 5 deletions crates/libs/bindgen/src/rust/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ pub fn writer(writer: &Writer, def: metadata::Field) -> TokenStream {
}
} else {
let kind = writer.type_default_name(&ty);
let value = writer.value(&constant.value());
let mut value = writer.value(&constant.value());
let underlying_type = type_underlying_type(&ty);

let value = if underlying_type == constant_type {
value
if underlying_type == constant_type {
if is_signed_error(&ty) {
if let metadata::Value::I32(signed) = constant.value() {
value = format!("0x{:X}_u32 as _", signed).into();
}
}
} else {
quote! { #value as _ }
};
value = quote! { #value as _ };
}

if !writer.sys && type_has_replacement(&ty) {
quote! {
Expand Down Expand Up @@ -74,6 +78,14 @@ pub fn writer(writer: &Writer, def: metadata::Field) -> TokenStream {
}
}

fn is_signed_error(ty: &metadata::Type) -> bool {
match ty {
metadata::Type::HRESULT => true,
metadata::Type::TypeDef(def, _) => def.type_name() == metadata::TypeName::NTSTATUS,
_ => false,
}
}

fn initializer(writer: &Writer, def: metadata::Field) -> Option<TokenStream> {
let value = constant(def)?;
let mut input = value.as_str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl NTSTATUS {
}
#[inline]
pub const fn to_hresult(self) -> ::windows_core::HRESULT {
::windows_core::HRESULT(self.0 | 0x1000_0000)
::windows_core::HRESULT::from_nt(self.0)
}
#[inline]
pub fn ok(self) -> ::windows_core::Result<()> {
Expand Down
69 changes: 69 additions & 0 deletions crates/libs/bindgen/src/rust/index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use super::*;
use rust::cfg::*;
use serde::Serialize;
use std::collections::BTreeMap;
use windows_metadata::Item;

#[derive(Default, Serialize)]
struct Index {
namespace_map: Vec<String>,
feature_map: Vec<String>,
namespaces: BTreeMap<usize, Vec<IndexItem>>,
}

#[derive(Default, Serialize)]
struct IndexItem {
name: String,
features: Vec<usize>,
}

pub fn gen_index(writer: &Writer) -> String {
let mut feature_index = Index { ..Default::default() };

for namespace in writer.reader.namespaces() {
let namespace_idx = match feature_index.namespace_map.iter().position(|ns| ns == namespace) {
Some(idx) => idx,
None => {
feature_index.namespace_map.push(namespace.to_string());
feature_index.namespace_map.len() - 1
}
};

for item in writer.reader.namespace_items(namespace) {
let mut index_item = IndexItem { ..Default::default() };
let mut cfg = Cfg::default();
cfg.add_feature(namespace);

cfg = match item {
Item::Type(def) => {
index_item.name = def.name().to_string();
cfg.union(&type_def_cfg(writer, def, &[]))
}
Item::Const(field) => {
index_item.name = field.name().to_string();
cfg.union(&field_cfg(writer, field))
}
Item::Fn(method, _) => {
index_item.name = method.name().to_string();
cfg.union(&signature_cfg(writer, method))
}
};

let cfg_features = cfg_features(&cfg);
index_item.features = cfg_features
.iter()
.map(|feature| match feature_index.feature_map.iter().position(|f| f == feature) {
Some(idx) => idx,
None => {
feature_index.feature_map.push(feature.to_string());
feature_index.feature_map.len() - 1
}
})
.collect();

feature_index.namespaces.entry(namespace_idx).or_default().push(index_item);
}
}

serde_json::to_string(&feature_index).unwrap()
}
12 changes: 8 additions & 4 deletions crates/libs/bindgen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod extensions;
mod functions;
mod handles;
mod implements;
mod index;
mod interfaces;
mod iterators;
mod method_names;
Expand All @@ -16,9 +17,11 @@ mod structs;
mod try_format;
mod winrt_methods;
mod writer;

use super::*;
use crate::Result;
use index::*;
use rayon::prelude::*;
use writer::*;

pub fn from_reader(reader: &'static metadata::Reader, mut config: std::collections::BTreeMap<&str, &str>, output: &str) -> Result<()> {
let mut writer = Writer::new(reader, output);
Expand Down Expand Up @@ -102,7 +105,8 @@ fn gen_package(writer: &Writer) -> Result<()> {
Ok::<(), Error>(())
})?;

let cargo_toml = format!("{}/Cargo.toml", super::directory(directory));
let package_root = super::directory(directory);
let cargo_toml = format!("{package_root}/Cargo.toml");
let mut toml = String::new();

for line in read_file_lines(&cargo_toml)? {
Expand Down Expand Up @@ -130,14 +134,14 @@ fn gen_package(writer: &Writer) -> Result<()> {
}
}

write_to_file(&cargo_toml, toml)
write_to_file(&cargo_toml, toml)?;
write_to_file(&format!("{package_root}/features.json"), gen_index(writer))
}

use method_names::*;
use std::fmt::Write;
use tokens::*;
use try_format::*;
use writer::*;

fn namespace(writer: &Writer, tree: &Tree) -> String {
let writer = &mut writer.clone();
Expand Down
16 changes: 16 additions & 0 deletions crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,22 @@ fn const_ptrs(pointers: usize) -> TokenStream {
"*const ".repeat(pointers).into()
}

pub fn cfg_features(cfg: &cfg::Cfg) -> Vec<String> {
let mut compact = Vec::<&'static str>::new();
for feature in cfg.types.keys() {
if !feature.is_empty() {
for pos in 0..compact.len() {
if starts_with(feature, unsafe { compact.get_unchecked(pos) }) {
compact.remove(pos);
break;
}
}
compact.push(feature);
}
}
compact.into_iter().map(to_feature).collect()
}

fn to_feature(name: &str) -> String {
let mut feature = String::new();

Expand Down
1 change: 0 additions & 1 deletion crates/libs/bindgen/src/winmd/writer/tables.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(non_snake_case)]

use super::Write;
use super::*;

#[derive(Default)]
Expand Down
12 changes: 1 addition & 11 deletions crates/libs/core/windows.natvis → crates/libs/core/.natvis
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="windows_core::array::Array&lt;*&gt;">
<DisplayString>{{ len={len} }}</DisplayString>
Expand All @@ -11,17 +12,6 @@
</Expand>
</Type>

<Type Name="windows_result::error::Error">
<Expand>
<ExpandedItem>code</ExpandedItem>
<Item Name="[info]">info</Item>
</Expand>
</Type>

<Type Name="windows_result::hresult::HRESULT">
<DisplayString>{(HRESULT)__0}</DisplayString>
</Type>

<Type Name="windows_core::imp::ref_count::RefCount">
<DisplayString>{__0}</DisplayString>
</Type>
Expand Down
14 changes: 7 additions & 7 deletions crates/libs/core/src/imp/com_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ::core::fmt::Debug for AgileReferenceOptions {
f.debug_tuple("AgileReferenceOptions").field(&self.0).finish()
}
}
pub const CO_E_NOTINITIALIZED: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147221008i32);
pub const CO_E_NOTINITIALIZED: ::windows_core::HRESULT = ::windows_core::HRESULT(0x800401F0_u32 as _);
#[repr(C)]
pub struct DateTime {
pub UniversalTime: i64,
Expand Down Expand Up @@ -61,9 +61,9 @@ impl ::core::default::Default for DateTime {
unsafe { ::core::mem::zeroed() }
}
}
pub const E_BOUNDS: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147483637i32);
pub const E_NOINTERFACE: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147467262i32);
pub const E_OUTOFMEMORY: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147024882i32);
pub const E_BOUNDS: ::windows_core::HRESULT = ::windows_core::HRESULT(0x8000000B_u32 as _);
pub const E_NOINTERFACE: ::windows_core::HRESULT = ::windows_core::HRESULT(0x80004002_u32 as _);
pub const E_OUTOFMEMORY: ::windows_core::HRESULT = ::windows_core::HRESULT(0x8007000E_u32 as _);
::windows_core::imp::com_interface!(IAgileObject, IAgileObject_Vtbl, 0x94ea2b94_e9cc_49e0_c0ff_ee64ca8f5b90);
::windows_core::imp::interface_hierarchy!(IAgileObject, ::windows_core::IUnknown);
impl IAgileObject {}
Expand Down Expand Up @@ -696,7 +696,7 @@ pub struct IWeakReferenceSource_Vtbl {
pub base__: ::windows_core::IUnknown_Vtbl,
pub GetWeakReference: unsafe extern "system" fn(*mut ::core::ffi::c_void, *mut *mut ::core::ffi::c_void) -> ::windows_core::HRESULT,
}
pub const JSCRIPT_E_CANTEXECUTE: ::windows_core::HRESULT = ::windows_core::HRESULT(-1996357631i32);
pub const JSCRIPT_E_CANTEXECUTE: ::windows_core::HRESULT = ::windows_core::HRESULT(0x89020001_u32 as _);
#[repr(C)]
pub struct Point {
pub X: f32,
Expand Down Expand Up @@ -1035,7 +1035,7 @@ impl PropertyValue {
impl ::windows_core::RuntimeName for PropertyValue {
const NAME: &'static str = "Windows.Foundation.PropertyValue";
}
pub const RPC_E_DISCONNECTED: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147417848i32);
pub const RPC_E_DISCONNECTED: ::windows_core::HRESULT = ::windows_core::HRESULT(0x80010108_u32 as _);
#[repr(C)]
pub struct Rect {
pub X: f32,
Expand Down Expand Up @@ -1104,7 +1104,7 @@ impl ::core::default::Default for Size {
unsafe { ::core::mem::zeroed() }
}
}
pub const TYPE_E_TYPEMISMATCH: ::windows_core::HRESULT = ::windows_core::HRESULT(-2147316576i32);
pub const TYPE_E_TYPEMISMATCH: ::windows_core::HRESULT = ::windows_core::HRESULT(0x80028CA0_u32 as _);
#[repr(C)]
pub struct TimeSpan {
pub Duration: i64,
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs

#![doc(html_no_source)]
#![allow(non_snake_case)]
#![cfg_attr(windows_debugger_visualizer, debugger_visualizer(natvis_file = "../windows.natvis"))]
#![cfg_attr(windows_debugger_visualizer, debugger_visualizer(natvis_file = "../.natvis"))]

extern crate self as windows_core;

Expand Down
12 changes: 12 additions & 0 deletions crates/libs/core/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ where
Param::Owned(std::mem::transmute_copy(&self))
}
}

impl IntoParam<PCWSTR> for &BSTR {
unsafe fn into_param(self) -> Param<PCWSTR> {
Param::Owned(PCWSTR(self.as_ptr()))
}
}

impl IntoParam<PCWSTR> for &HSTRING {
unsafe fn into_param(self) -> Param<PCWSTR> {
Param::Owned(PCWSTR(self.as_ptr()))
}
}
4 changes: 4 additions & 0 deletions crates/libs/core/src/runtime_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ primitives! {
(f32, b"f4"),
(f64, b"f8")
}

impl RuntimeType for HSTRING {
const SIGNATURE: crate::imp::ConstBuffer = crate::imp::ConstBuffer::from_slice(b"string");
}
Loading

0 comments on commit d070fbc

Please sign in to comment.