Skip to content

Add no_std support#337

Open
CrazyboyQCD wants to merge 3 commits intogrovesNL:mainfrom
CrazyboyQCD:main
Open

Add no_std support#337
CrazyboyQCD wants to merge 3 commits intogrovesNL:mainfrom
CrazyboyQCD:main

Conversation

@CrazyboyQCD
Copy link
Copy Markdown

Based on #253.

@CrazyboyQCD CrazyboyQCD marked this pull request as draft February 19, 2025 00:56
@CrazyboyQCD CrazyboyQCD marked this pull request as ready for review February 19, 2025 01:01
@CrazyboyQCD CrazyboyQCD force-pushed the main branch 5 times, most recently from 9ec5cbf to f2ab494 Compare March 4, 2025 08:45
@CrazyboyQCD CrazyboyQCD requested a review from grovesNL March 7, 2025 06:04
@grovesNL
Copy link
Copy Markdown
Owner

grovesNL commented Mar 7, 2025

@CrazyboyQCD it looks like catch_unwind isn't needed anymore for this callback as of Rust 1.81, so we can remove it entirely (https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#abort-on-uncaught-panics-in-extern-c-functions) and keep the code the same between std and no_std

@CrazyboyQCD

This comment was marked as resolved.

Copy link
Copy Markdown

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

This is great! Just a couple small suggestions which would help with wgpu/#6826, specifically to get wasm32v1-none

@CrazyboyQCD CrazyboyQCD force-pushed the main branch 2 times, most recently from 69f3b23 to aed8dbe Compare June 19, 2025 01:41
Copy link
Copy Markdown

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Brilliant! I've confirmed this works on wasm32v1-none. One last suggestion: if you apply the below diff, then no_std will also work on native targets, like x86_64-unknown-none:

diff --git a/src/gl46.rs b/src/gl46.rs
index 83d416a..1d259a6 100644
--- a/src/gl46.rs
+++ b/src/gl46.rs
@@ -116,16 +116,7 @@
 //! * Individual GL commands are generally safe to use once they've been properly loaded for the current context, but this crate doesn't attempt to sort out what is safe and what's not. All GL commands are blanket marked as being `unsafe`.
 //! It's up to you to try and manage this unsafety! Sorry, but this crate just does what you tell it to.
 
-#[cfg(any(
-    all(
-        not(feature = "log"),
-        any(feature = "debug_trace_calls", feature = "debug_automatic_glGetError")
-    ),
-    not(feature = "chlorine"),
-))]
-extern crate std;
-
-use std::os::raw::*;
+use core::ffi::*;
 
 #[cfg(feature = "log")]
 #[allow(unused)]

Copy link
Copy Markdown

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Confirmed working on x86_64-unknown-none!

@CrazyboyQCD
Copy link
Copy Markdown
Author

@grovesNL
As no_std support changes the gl46.rs, and it is generated from script, it will be better to update it in the future.

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.

3 participants