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

Fix support for no_std #3180

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 2 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
uses: ./.github/actions/fix-environment
- name: Clippy cppwinrt
run: cargo clippy -p cppwinrt
- name: Clippy no_std
run: cargo clippy -p no_std
- name: Clippy riddle
run: cargo clippy -p riddle
- name: Clippy sample_bits
Expand Down Expand Up @@ -204,6 +202,8 @@ jobs:
run: cargo clippy -p test_metadata
- name: Clippy test_msrv
run: cargo clippy -p test_msrv
- name: Clippy test_no_std
run: cargo clippy -p test_no_std
- name: Clippy test_no_use
run: cargo clippy -p test_no_use
- name: Clippy test_noexcept
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/no_std.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: no_std

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

env:
RUSTFLAGS: -Dwarnings

jobs:
check:
strategy:
matrix:
rust: [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 test_no_std
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ jobs:
run: cargo clean
- name: Test cppwinrt
run: cargo test -p cppwinrt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test no_std
run: cargo test -p no_std --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test riddle
run: cargo test -p riddle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_bits
Expand Down Expand Up @@ -156,10 +154,10 @@ jobs:
run: cargo test -p test_alternate_success_code --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_arch
run: cargo test -p test_arch --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_array
run: cargo test -p test_array --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_bcrypt
Expand Down Expand Up @@ -230,6 +228,8 @@ jobs:
run: cargo test -p test_metadata --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_msrv
run: cargo test -p test_msrv --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_no_std
run: cargo test -p test_no_std --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_no_use
run: cargo test -p test_no_use --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_noexcept
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 @@ -292,6 +292,6 @@ fn extension(path: &str) -> &str {
}

fn directory(path: &str) -> &str {
path.rsplit_once(&['/', '\\'])
path.rsplit_once(['/', '\\'])
.map_or("", |(directory, _)| directory)
}
4 changes: 1 addition & 3 deletions crates/libs/bindgen/src/winmd/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ impl Writer {
MethodList: 0,
});

let name = name
.rsplit_once(&['/', '\\'])
.map_or(name, |(_, name)| name);
let name = name.rsplit_once(['/', '\\']).map_or(name, |(_, name)| name);

writer.tables.Module.push(Module {
Name: writer.strings.insert(name),
Expand Down
4 changes: 3 additions & 1 deletion crates/libs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ path = "../targets"
[dependencies.windows-result]
version = "0.2.0"
path = "../result"
default-features = false

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

[dependencies]
windows-implement = { path = "../implement", version = "0.58.0" }
windows-interface = { path = "../interface", version = "0.58.0" }

[features]
default = ["std"]
std = []
std = ["windows-result/std", "windows-strings/std"]
2 changes: 2 additions & 0 deletions crates/libs/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ path = "../targets"
[dependencies.windows-result]
version = "0.2.0"
path = "../result"
default-features = false

[dependencies.windows-strings]
version = "0.1.0"
path = "../strings"
default-features = false
11 changes: 8 additions & 3 deletions crates/libs/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ default-target = "x86_64-pc-windows-msvc"
targets = []
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
windows-core = { path = "../core", version = "0.58.0" }
windows-targets = { path = "../targets", version = "0.52.6" }
[dependencies.windows-core]
version = "0.58.0"
path = "../core"
default-features = false

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

[features]
default = ["std"]
Expand Down
1 change: 1 addition & 0 deletions crates/libs/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#![cfg_attr(not(feature = "docs"), doc(hidden))]
// TODO: workaround for https://github.com/rust-lang/rust/issues/126169
#![allow(unused)]
#![cfg_attr(all(not(feature = "std")), no_std)]

#[allow(unused_extern_crates)]
extern crate self as windows;
Expand Down
28 changes: 22 additions & 6 deletions crates/tests/no_std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "no_std"
name = "test_no_std"
version = "0.1.0"
edition = "2021"

Expand All @@ -11,11 +11,6 @@ doctest = false
path = "../../libs/core"
default-features = false

[dependencies.windows]
path = "../../libs/windows"
default-features = false
features = ["implement"]

[dependencies.windows-registry]
path = "../../libs/registry"
default-features = false
Expand All @@ -24,5 +19,26 @@ default-features = false
path = "../../libs/result"
default-features = false

[dependencies.windows-strings]
path = "../../libs/strings"
default-features = false

[dependencies.windows-sys]
path = "../../libs/sys"
default-features = false

[dependencies.windows-targets]
path = "../../libs/targets"
default-features = false

[dependencies.windows-version]
path = "../../libs/version"
default-features = false

[dependencies.windows]
path = "../../libs/windows"
default-features = false
features = ["implement"]

[lints]
workspace = true
31 changes: 19 additions & 12 deletions crates/tests/no_std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
//! Test for `#![no_std]` crates.
//!
//! Compiling this crate verifies that the Windows crates can be compiled with their "std"
//! feature disabled.
//! feature disabled. The tricky part is that `cargo test` depends on `std` so testing
//! `no_std` requires using `cargo check` instead. That's what the `no_std.yml` is for.

#![no_std]

#[cfg(test)]
mod tests {
use windows::core::{implement, ComObject};
#[windows::core::implement]
struct App;

#[implement]
struct App {}
#[cfg(not(test))]
fn _test() {
// Pull in something from each library crate that supports `no_std` to ensure they don't
// accidentally depend on `std`.
let _ = windows_core::ComObject::new(App);
let _ = windows_registry::CURRENT_USER.create("software\\windows-rs");
let _ = windows_result::HRESULT(0);
let _ = windows_strings::BSTR::new();
let _ = windows_sys::core::GUID::from_u128(0);
let _ = windows_version::OsVersion::current();
let _ = windows::core::ComObject::new(App);
}

// Compilation is sufficient to test.
#[test]
fn basic() {
let object = ComObject::new(App {});
drop(object);
}
#[cfg_attr(not(test), panic_handler)]
fn _panic(_: &core::panic::PanicInfo<'_>) -> ! {
kennykerr marked this conversation as resolved.
Show resolved Hide resolved
loop {}
}