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 windows-strings crate #3125

Merged
merged 12 commits into from
Jun 25, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ jobs:
run: cargo clippy -p test_standalone
- name: Clippy test_string_param
run: cargo clippy -p test_string_param
- name: Clippy test_strings
run: cargo clippy -p test_strings
- name: Clippy test_structs
run: cargo clippy -p test_structs
- name: Clippy test_sys
Expand Down Expand Up @@ -288,6 +290,8 @@ jobs:
run: cargo clippy -p windows-registry
- name: Clippy windows-result
run: cargo clippy -p windows-result
- name: Clippy windows-strings
run: cargo clippy -p windows-strings
- name: Clippy windows-sys
run: cargo clippy -p windows-sys
- name: Clippy windows-targets
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/msrv-windows-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
strategy:
matrix:
rust: [1.60.0, stable, nightly]
runs-on:
- windows-latest
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/msrv-windows-strings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: windows-strings

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

env:
RUSTFLAGS: -Dwarnings

jobs:
check:
strategy:
matrix:
rust: [1.60.0, stable, nightly]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Check
run: cargo check -p windows-strings --all-features
5 changes: 1 addition & 4 deletions .github/workflows/msrv-windows-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
strategy:
matrix:
rust: [1.60.0, stable, nightly]
runs-on:
- windows-latest
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/msrv-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
strategy:
matrix:
rust: [1.70.0, stable, nightly]
runs-on:
- windows-2022
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/no-default-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
run: cargo check -p windows-registry --no-default-features
- name: Check windows-result
run: cargo check -p windows-result --no-default-features
- name: Check windows-strings
run: cargo check -p windows-strings --no-default-features
- name: Check windows-sys
run: cargo check -p windows-sys --no-default-features
- name: Check windows-targets
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ jobs:
run: cargo clean
- name: Test test_string_param
run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_strings
run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_structs
run: cargo test -p test_structs --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_sys
Expand Down Expand Up @@ -316,6 +318,8 @@ jobs:
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-result
run: cargo test -p windows-result --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-strings
run: cargo test -p windows-strings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-sys
run: cargo test -p windows-sys --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows-targets
Expand Down
56 changes: 0 additions & 56 deletions crates/libs/core/.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,4 @@
<Type Name="windows_core::imp::ref_count::RefCount">
<DisplayString>{__0}</DisplayString>
</Type>

<Type Name="windows_core::strings::hstring::HSTRING">
<Intrinsic Name="header" Expression="(windows_core::strings::hstring::Header *)__0.tag" />
<Intrinsic Name="is_empty" Expression="__0.tag == 0" />
<DisplayString Condition="is_empty()">""</DisplayString>
<DisplayString>{header()->data,[header()->len]su}</DisplayString>

<Expand>
<Item Name="[len]">is_empty() ? (unsigned int)0 : header()->len</Item>
<Item Name="[ref_count]" Condition="!is_empty()">header()->count</Item>
<Item Name="[flags]" Condition="!is_empty()">header()->flags</Item>
<Synthetic Name="[chars]" Condition="!is_empty()">
<Expand>
<ArrayItems>
<Size>header()->len</Size>
<ValuePointer>(char16_t*)header()->data</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="windows_core::strings::pstr::PSTR">
<AlternativeType Name="windows_core::strings::pcstr::PCSTR" />
<Intrinsic Name="len" Expression="strlen(((char*)__0))" />
<DisplayString>{(char*)__0,[len()]s8}</DisplayString>
<Expand>
<Item Name="[len]">len()</Item>
<Synthetic Name="[chars]">
<Expand>
<ArrayItems>
<Size>len()</Size>
<ValuePointer>(char*)__0</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="windows_core::strings::pwstr::PWSTR">
<AlternativeType Name="windows_core::strings::pcwstr::PCWSTR" />
<Intrinsic Name="len" Expression="wcslen(((WCHAR*)__0))" />
<DisplayString>{(char16_t*)__0,[len()]su}</DisplayString>

<Expand>
<Item Name="[len]">len()</Item>
<Synthetic Name="[chars]">
<Expand>
<ArrayItems>
<Size>len()</Size>
<ValuePointer>(char16_t*)__0</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>
</AutoVisualizer>
4 changes: 4 additions & 0 deletions crates/libs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ path = "../targets"
version = "0.1.1"
path = "../result"

[dependencies.windows-strings]
version = "0.1.0"
path = "../strings"

[dependencies]
windows-implement = { path = "../implement", version = "0.57.0" }
windows-interface = { path = "../interface", version = "0.57.0" }
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fn main() {
WaitForSingleObject(event, 0);
CloseHandle(event);

MessageBoxA(0, s!("Ansi"), s!("Caption"), MB_OK);
MessageBoxW(0, w!("Wide"), w!("Caption"), MB_OK);
MessageBoxA(0 as _, s!("Ansi"), s!("Caption"), MB_OK);
MessageBoxW(0 as _, w!("Wide"), w!("Caption"), MB_OK);
}
}
```
3 changes: 0 additions & 3 deletions crates/libs/core/src/imp/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ windows_targets::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mu
windows_targets::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
windows_targets::link!("ole32.dll" "system" fn PropVariantClear(pvar : *mut PROPVARIANT) -> HRESULT);
windows_targets::link!("ole32.dll" "system" fn PropVariantCopy(pvardest : *mut PROPVARIANT, pvarsrc : *const PROPVARIANT) -> HRESULT);
windows_targets::link!("oleaut32.dll" "system" fn SysAllocStringLen(strin : PCWSTR, ui : u32) -> BSTR);
windows_targets::link!("oleaut32.dll" "system" fn SysFreeString(bstrstring : BSTR));
windows_targets::link!("oleaut32.dll" "system" fn SysStringLen(pbstr : BSTR) -> u32);
windows_targets::link!("oleaut32.dll" "system" fn VariantClear(pvarg : *mut VARIANT) -> HRESULT);
windows_targets::link!("oleaut32.dll" "system" fn VariantCopy(pvargdest : *mut VARIANT, pvargsrc : *const VARIANT) -> HRESULT);
windows_targets::link!("propsys.dll" "system" fn PropVariantCompareEx(propvar1 : *const PROPVARIANT, propvar2 : *const PROPVARIANT, unit : PROPVAR_COMPARE_UNIT, flags : PROPVAR_COMPARE_FLAGS) -> i32);
Expand Down
5 changes: 2 additions & 3 deletions crates/libs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate self as windows_core;
#[macro_use]
extern crate alloc;

use alloc::{boxed::Box, string::String, vec::Vec};
use alloc::boxed::Box;

#[doc(hidden)]
pub mod imp;
Expand All @@ -38,7 +38,6 @@ mod r#ref;
mod runtime_name;
mod runtime_type;
mod scoped_interface;
mod strings;
mod r#type;
mod unknown;
mod variant;
Expand All @@ -63,13 +62,13 @@ pub use r#type::*;
pub use runtime_name::*;
pub use runtime_type::*;
pub use scoped_interface::*;
pub use strings::*;
pub use unknown::*;
pub use variant::*;
pub use weak::*;
pub use windows_implement::implement;
pub use windows_interface::interface;
pub use windows_result::*;
pub use windows_strings::*;

/// Attempts to load the factory object for the given WinRT class.
/// This can be used to access COM interfaces implemented on a Windows Runtime class factory.
Expand Down
62 changes: 62 additions & 0 deletions crates/libs/strings/.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="windows_strings::hstring::HSTRING">
<Intrinsic Name="header" Expression="(windows_strings::hstring::Header *)__0.tag" />
<Intrinsic Name="is_empty" Expression="__0.tag == 0" />
<DisplayString Condition="is_empty()">""</DisplayString>
<DisplayString>{header()->data,[header()->len]su}</DisplayString>

<Expand>
<Item Name="[len]">is_empty() ? (unsigned int)0 : header()->len</Item>
<Item Name="[ref_count]" Condition="!is_empty()">header()->count</Item>
<Item Name="[flags]" Condition="!is_empty()">header()->flags</Item>
<Synthetic Name="[chars]" Condition="!is_empty()">
<Expand>
<ArrayItems>
<Size>header()->len</Size>
<ValuePointer>(char16_t*)header()->data</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="windows_strings::pstr::PSTR">
<AlternativeType Name="windows_strings::pcstr::PCSTR" />
<Intrinsic Name="len" Expression="strlen(((char*)__0))" />
<DisplayString>{(char*)__0,[len()]s8}</DisplayString>
<Expand>
<Item Name="[len]">len()</Item>
<Synthetic Name="[chars]">
<Expand>
<ArrayItems>
<Size>len()</Size>
<ValuePointer>(char*)__0</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="windows_strings::pwstr::PWSTR">
<AlternativeType Name="windows_strings::pcwstr::PCWSTR" />
<Intrinsic Name="len" Expression="wcslen(((WCHAR*)__0))" />
<DisplayString>{(char16_t*)__0,[len()]su}</DisplayString>

<Expand>
<Item Name="[len]">len()</Item>
<Synthetic Name="[chars]">
<Expand>
<ArrayItems>
<Size>len()</Size>
<ValuePointer>(char16_t*)__0</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="windows_strings::ref_count::RefCount">
<DisplayString>{__0}</DisplayString>
</Type>
</AutoVisualizer>
30 changes: 30 additions & 0 deletions crates/libs/strings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "windows-strings"
version = "0.1.0"
authors = ["Microsoft"]
edition = "2021"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
description = "Rust for Windows"
repository = "https://github.com/microsoft/windows-rs"
readme = "readme.md"
categories = ["os::windows-apis"]

[lints]
workspace = true

[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
targets = []

[dependencies.windows-targets]
version = "0.52.5"
path = "../targets"

[dependencies.windows-result]
version = "0.1.1"
path = "../result"

[features]
default = ["std"]
std = []
Loading