Skip to content

Commit 429666e

Browse files
authored
Fix support for no_std (#3180)
1 parent 02c4f29 commit 429666e

File tree

11 files changed

+91
-32
lines changed

11 files changed

+91
-32
lines changed

.github/workflows/clippy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ jobs:
3434
uses: ./.github/actions/fix-environment
3535
- name: Clippy cppwinrt
3636
run: cargo clippy -p cppwinrt
37-
- name: Clippy no_std
38-
run: cargo clippy -p no_std
3937
- name: Clippy riddle
4038
run: cargo clippy -p riddle
4139
- name: Clippy sample_bits
@@ -204,6 +202,8 @@ jobs:
204202
run: cargo clippy -p test_metadata
205203
- name: Clippy test_msrv
206204
run: cargo clippy -p test_msrv
205+
- name: Clippy test_no_std
206+
run: cargo clippy -p test_no_std
207207
- name: Clippy test_no_use
208208
run: cargo clippy -p test_no_use
209209
- name: Clippy test_noexcept

.github/workflows/no_std.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: no_std
2+
3+
on:
4+
pull_request:
5+
push:
6+
paths-ignore:
7+
- '.github/ISSUE_TEMPLATE/**'
8+
branches:
9+
- master
10+
11+
env:
12+
RUSTFLAGS: -Dwarnings
13+
14+
jobs:
15+
check:
16+
strategy:
17+
matrix:
18+
rust: [stable, nightly]
19+
runs-on: windows-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
- name: Prepare
24+
run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
25+
- name: Check
26+
run: cargo check -p test_no_std

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ jobs:
5858
run: cargo clean
5959
- name: Test cppwinrt
6060
run: cargo test -p cppwinrt --target ${{ matrix.target }} ${{ matrix.etc }}
61-
- name: Test no_std
62-
run: cargo test -p no_std --target ${{ matrix.target }} ${{ matrix.etc }}
6361
- name: Test riddle
6462
run: cargo test -p riddle --target ${{ matrix.target }} ${{ matrix.etc }}
6563
- name: Test sample_bits
@@ -156,10 +154,10 @@ jobs:
156154
run: cargo test -p test_alternate_success_code --target ${{ matrix.target }} ${{ matrix.etc }}
157155
- name: Test test_arch
158156
run: cargo test -p test_arch --target ${{ matrix.target }} ${{ matrix.etc }}
159-
- name: Clean
160-
run: cargo clean
161157
- name: Test test_arch_feature
162158
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
159+
- name: Clean
160+
run: cargo clean
163161
- name: Test test_array
164162
run: cargo test -p test_array --target ${{ matrix.target }} ${{ matrix.etc }}
165163
- name: Test test_bcrypt
@@ -230,6 +228,8 @@ jobs:
230228
run: cargo test -p test_metadata --target ${{ matrix.target }} ${{ matrix.etc }}
231229
- name: Test test_msrv
232230
run: cargo test -p test_msrv --target ${{ matrix.target }} ${{ matrix.etc }}
231+
- name: Test test_no_std
232+
run: cargo test -p test_no_std --target ${{ matrix.target }} ${{ matrix.etc }}
233233
- name: Test test_no_use
234234
run: cargo test -p test_no_use --target ${{ matrix.target }} ${{ matrix.etc }}
235235
- name: Test test_noexcept

crates/libs/bindgen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,6 @@ fn extension(path: &str) -> &str {
292292
}
293293

294294
fn directory(path: &str) -> &str {
295-
path.rsplit_once(&['/', '\\'])
295+
path.rsplit_once(['/', '\\'])
296296
.map_or("", |(directory, _)| directory)
297297
}

crates/libs/bindgen/src/winmd/writer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ impl Writer {
4545
MethodList: 0,
4646
});
4747

48-
let name = name
49-
.rsplit_once(&['/', '\\'])
50-
.map_or(name, |(_, name)| name);
48+
let name = name.rsplit_once(['/', '\\']).map_or(name, |(_, name)| name);
5149

5250
writer.tables.Module.push(Module {
5351
Name: writer.strings.insert(name),

crates/libs/core/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ path = "../targets"
2424
[dependencies.windows-result]
2525
version = "0.2.0"
2626
path = "../result"
27+
default-features = false
2728

2829
[dependencies.windows-strings]
2930
version = "0.1.0"
3031
path = "../strings"
32+
default-features = false
3133

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

3638
[features]
3739
default = ["std"]
38-
std = []
40+
std = ["windows-result/std", "windows-strings/std"]

crates/libs/registry/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ path = "../targets"
2424
[dependencies.windows-result]
2525
version = "0.2.0"
2626
path = "../result"
27+
default-features = false
2728

2829
[dependencies.windows-strings]
2930
version = "0.1.0"
3031
path = "../strings"
32+
default-features = false

crates/libs/windows/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ default-target = "x86_64-pc-windows-msvc"
2626
targets = []
2727
rustdoc-args = ["--cfg", "docsrs"]
2828

29-
[dependencies]
30-
windows-core = { path = "../core", version = "0.58.0" }
31-
windows-targets = { path = "../targets", version = "0.52.6" }
29+
[dependencies.windows-core]
30+
version = "0.58.0"
31+
path = "../core"
32+
default-features = false
33+
34+
[dependencies.windows-targets]
35+
version = "0.52.6"
36+
path = "../targets"
3237

3338
[features]
3439
default = ["std"]

crates/libs/windows/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
1212
#![cfg_attr(not(feature = "docs"), doc(hidden))]
1313
// TODO: workaround for https://github.com/rust-lang/rust/issues/126169
1414
#![allow(unused)]
15+
#![cfg_attr(all(not(feature = "std")), no_std)]
1516

1617
#[allow(unused_extern_crates)]
1718
extern crate self as windows;

crates/tests/no_std/Cargo.toml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "no_std"
2+
name = "test_no_std"
33
version = "0.1.0"
44
edition = "2021"
55

@@ -11,11 +11,6 @@ doctest = false
1111
path = "../../libs/core"
1212
default-features = false
1313

14-
[dependencies.windows]
15-
path = "../../libs/windows"
16-
default-features = false
17-
features = ["implement"]
18-
1914
[dependencies.windows-registry]
2015
path = "../../libs/registry"
2116
default-features = false
@@ -24,5 +19,26 @@ default-features = false
2419
path = "../../libs/result"
2520
default-features = false
2621

22+
[dependencies.windows-strings]
23+
path = "../../libs/strings"
24+
default-features = false
25+
26+
[dependencies.windows-sys]
27+
path = "../../libs/sys"
28+
default-features = false
29+
30+
[dependencies.windows-targets]
31+
path = "../../libs/targets"
32+
default-features = false
33+
34+
[dependencies.windows-version]
35+
path = "../../libs/version"
36+
default-features = false
37+
38+
[dependencies.windows]
39+
path = "../../libs/windows"
40+
default-features = false
41+
features = ["implement"]
42+
2743
[lints]
2844
workspace = true

0 commit comments

Comments
 (0)