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

no-std support in wgpu-core #6926

Draft
wants to merge 20 commits into
base: trunk
Choose a base branch
from

Conversation

brody4hire
Copy link
Contributor

@brody4hire brody4hire commented Jan 16, 2025

STATUS: INITIAL DRAFT with blocking TODO items multiple XXX todo items; documentation TODO; CI failures are expected at this point

MAJOR BLOCKING ITEMS:

  • I would highly recommend resolving no-std support in dependencies first: naga, wgpu-hal
  • review & hopefully merge preparation PRs listed below

Connections


Description

no-std support in wgpu-core (per title), with help from new "std" feature

NOTE that this is based on recent preparation PRs listed above, hopefully they will be reviewed & merged soon. I would like to rebase this once the preparation PRs are hopefully approved & merged.

/cc @bushrat011899 - many thanks for your recent contributions


Testing

  • cargo build --no-default-features -p wgpu-core - XXX TODO KNOWN BUILD FAILURE NOT DETECTED BY CI TESTING (NEED TO FIX THIS)
  • cargo build --all-features -p wgpu-core
  • cargo build --all-features -p wgpu
  • cargo test --no-default-features -p wgpu-core - XXX TODO KNOWN FAILURE NOT DETECTED BY CI TESTING (NEED TO FIX THIS)
  • cargo test --all-features -p wgpu-core
  • cargo test --all-features -p wgpu
  • cargo xtask test (I had to set CXXFLAGS in my environment on macOS, looks like a known issue with bindgen - XXX I would like to investigate & resolve this)

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.
  • check for & resolve any CI failures (if possible)
  • update any other documentation (feature documentation from Cargo.toml, for example)
  • Resolve or defer all XXX todo items in these changes

@jimblandy jimblandy changed the title DRAFT: no-std support in wgpu-core - with multiple TODO items DO NOT MERGE no-std support in wgpu-core Jan 16, 2025
@jimblandy
Copy link
Member

jimblandy commented Jan 16, 2025

@brodycj Thanks for looking into this! no_std support is something we've been talking about, so it's great to have someone take a shot.

I've tweaked the PR title. Simply marking the PR as "draft" will make GitHub prevent us from accidentally merging it, and we won't bother with a formal review until it's out of draft. We can save the flashing lights and sirens for something else. :)

Comment on lines 252 to 259
#[cfg(any(feature = "std", test))]
pub(crate) use super::std::sync::*;
pub(crate) use core::sync::*;
// XXX TBD ??? - UPDATE FOR std vs test ???
// XXX TBD NAMING - ???
// XXX TODO UNCOMMENT - XXX XXX THIS COMMENTED-OUT IMPORT SHOULD TRIGGER CI BUILD FAILURE
// #[cfg(not(any(feature = "std", test)))]
// pub(crate) use crate::OnceCell as OnceLock;
Copy link
Contributor Author

@brody4hire brody4hire Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy that the existing CI did not fail for the missing import I injected for no-std build. I think we need to add cargo build --no-default-feaures or at least add cargo test --no-default-features to detect this kind of missing import issue. I would like to propose a solution for this.


P.S. The following build & test steps WILL catch this missing import (I am trying these with custom CXXFLAGS on my mac, cannot tell for sure for all cases if custom CXXFLAGS is needed or not on my mac):

  • cargo build --no-default-features -p wgpu-core
  • cargo check --no-default-features -p wgpu-core
  • cargo test --no-default-features -p wgpu-core
  • cargo clippy --no-default-features -p wgpu-core

The following build & test steps WILL NOT catch this missing import (I am trying these with custom CXXFLAGS on my mac as well):

  • cargo build --no-default-features
  • cargo check --no-default-features
  • cargo test --no-default-features (this DOES show a single test failure in back::msl::writer::test_stack_size but does NOT seem to catch the missing import here)
  • cargo clippy --no-default-features

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is expected. --no-default-features will only apply to the root crate (at least as far as I'm aware) and not any member crates. There is a CI check no_std task which was setup in the no_std for wgpu-types PR. That task is the one that should be expanded to include wgpu-core, etc.

Comment on lines 275 to 280
#[cfg(any(feature = "std", test))]
pub(crate) use std::error;
// XXX TODO UNCOMMENT - XXX XXX THIS COMMENTED-OUT IMPORT SHOULD TRIGGER CI BUILD FAILURE
// XXX TBD THIS IMPORT (IF UNCOMMENTED) IS EXPECTED TO BREAK MSRV - XXX TODO CI SHOULD DETECT THIS
// #[cfg(not(any(feature = "std", test)))]
// pub(crate) use core::error;
Copy link
Contributor Author

@brody4hire brody4hire Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: I think we need to update the MSRV build test to test with no features, no default features as well, otherwise MSRV build test would not catch expected issue with using core::error. (I don't think the now-stablized error_in_core feature is supported by the current MSRV.)


CI should have failed with the missing import for no-std build - see https://github.com/gfx-rs/wgpu/pull/6926/files#r1919365322 (I will propose a solution for this)


@wgpu @ wgpu maintainers my apologies for so much noise from notifications on this PR - I may raise a PR on my own fork to keep this under better control.


P.S. Moving forward, I am thinking to just add no-std build check / clippy check sub-step for wgpu-core like was done for wgpu-types, which I have now done for this PR. It may be ideal to add cargo test for wgpu-core with no-std as well.

CI failure for missing import for no-std now shows up for commit a1edb9c - expected CI failure shows up for multiple platforms, for example: https://github.com/gfx-rs/wgpu/actions/runs/12821635378/job/35753212859?pr=6926


Extra P.S. Thanks to Fitzgerald for pointing out my mistake with the random user - oops with apologies

I would actually downvote changing the notification settings, just my personal opinion - IMHO - I would personally rather see all notifications that are normally expected, should be able to mute or unsubsribe myself if needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just pung a random user lol - don't worry about it, we can always change notification settings

cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features

# Check with all features except "std".
# check wgpu-core with no features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-core --no-default-features
Copy link
Contributor Author

@brody4hire brody4hire Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang this is not failing the way I expected: https://github.com/gfx-rs/wgpu/actions/runs/12820839400/job/35751074262?pr=6926

The following command I copy-pasted from the build log reproduces on my macBook (I needed to do rustup target add x86_64-unknown-none first):

cargo clippy --target x86_64-unknown-none  -p wgpu-core --no-default-features

I would like to fix this, if possible.


P.S. I / we may need to update naga for no-std before this failure can be resolved - skipping for now, adding another, similar temporary sub-step to (hopefully) detect missing import(s) for no-std

@brody4hire brody4hire mentioned this pull request Jan 17, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants