From 429666eb724f4a0378974d67adf38c45ce7d78d4 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 29 Jul 2024 16:46:09 -0700 Subject: [PATCH] Fix support for `no_std` (#3180) --- .github/workflows/clippy.yml | 4 +-- .github/workflows/no_std.yml | 26 ++++++++++++++++ .github/workflows/test.yml | 8 ++--- crates/libs/bindgen/src/lib.rs | 2 +- crates/libs/bindgen/src/winmd/writer/mod.rs | 4 +-- crates/libs/core/Cargo.toml | 4 ++- crates/libs/registry/Cargo.toml | 2 ++ crates/libs/windows/Cargo.toml | 11 +++++-- crates/libs/windows/src/lib.rs | 1 + crates/tests/no_std/Cargo.toml | 28 +++++++++++++---- crates/tests/no_std/src/lib.rs | 33 +++++++++++++-------- 11 files changed, 91 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/no_std.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 57988144fd..870c2323ad 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -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 @@ -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 diff --git a/.github/workflows/no_std.yml b/.github/workflows/no_std.yml new file mode 100644 index 0000000000..9ada778bf7 --- /dev/null +++ b/.github/workflows/no_std.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84c509d81a..b9b4dc918e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -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 diff --git a/crates/libs/bindgen/src/lib.rs b/crates/libs/bindgen/src/lib.rs index a331c476e3..e9db3a17b9 100644 --- a/crates/libs/bindgen/src/lib.rs +++ b/crates/libs/bindgen/src/lib.rs @@ -292,6 +292,6 @@ fn extension(path: &str) -> &str { } fn directory(path: &str) -> &str { - path.rsplit_once(&['/', '\\']) + path.rsplit_once(['/', '\\']) .map_or("", |(directory, _)| directory) } diff --git a/crates/libs/bindgen/src/winmd/writer/mod.rs b/crates/libs/bindgen/src/winmd/writer/mod.rs index b485d7edf3..299eb206b6 100644 --- a/crates/libs/bindgen/src/winmd/writer/mod.rs +++ b/crates/libs/bindgen/src/winmd/writer/mod.rs @@ -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), diff --git a/crates/libs/core/Cargo.toml b/crates/libs/core/Cargo.toml index 25fabae905..d49853bff8 100644 --- a/crates/libs/core/Cargo.toml +++ b/crates/libs/core/Cargo.toml @@ -24,10 +24,12 @@ 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" } @@ -35,4 +37,4 @@ windows-interface = { path = "../interface", version = "0.58.0" } [features] default = ["std"] -std = [] +std = ["windows-result/std", "windows-strings/std"] diff --git a/crates/libs/registry/Cargo.toml b/crates/libs/registry/Cargo.toml index b4384601c2..eea2b849f3 100644 --- a/crates/libs/registry/Cargo.toml +++ b/crates/libs/registry/Cargo.toml @@ -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 diff --git a/crates/libs/windows/Cargo.toml b/crates/libs/windows/Cargo.toml index 0e23e071e5..d4e0c3cadf 100644 --- a/crates/libs/windows/Cargo.toml +++ b/crates/libs/windows/Cargo.toml @@ -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"] diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index a60efae38d..01e207a06d 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -12,6 +12,7 @@ Learn more about Rust for Windows here: ) -> ! { + loop {} }