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

make crate no_std compatible #530

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ An OpenGL function pointer loader for the Rust Programming Language.

```toml
[dependencies]
gl = "0.14.0"
gl = "0.15.0"
```

### gl_generator
Expand All @@ -33,7 +33,7 @@ Code generators for creating bindings to the Khronos OpenGL APIs.

```toml
[build-dependencies]
gl_generator = "0.14.0"
gl_generator = "0.15.0"
```

### khronos_api
Expand Down
4 changes: 2 additions & 2 deletions gl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gl"
version = "0.14.0"
version = "0.15.0"
authors = [
"Brendan Zabarauskas <bjzaba@yahoo.com.au>",
"Corey Richardson",
Expand All @@ -17,7 +17,7 @@ categories = ["api-bindings", "rendering::graphics-api"]
keywords = ["gl", "egl", "opengl", "khronos"]

[build-dependencies]
gl_generator = { version = "0.14.0", path = "../gl_generator" }
gl_generator = { version = "0.15.0", path = "../gl_generator" }

[dev-dependencies]
glutin = "0.24"
2 changes: 1 addition & 1 deletion gl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ An OpenGL function pointer loader for the Rust Programming Language.

```toml
[dependencies]
gl = "0.14.0"
gl = "0.15.0"
```

## Basic usage
Expand Down
2 changes: 1 addition & 1 deletion gl_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gl_generator"
version = "0.14.1"
version = "0.15.0"
authors = [
"Brendan Zabarauskas <bjzaba@yahoo.com.au>",
"Corey Richardson",
Expand Down
4 changes: 2 additions & 2 deletions gl_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add this to your `Cargo.toml`:

```toml
[build-dependencies]
gl_generator = "0.14.0"
gl_generator = "0.15.0"
```

Under the `[package]` section, add:
Expand Down Expand Up @@ -71,7 +71,7 @@ The `build.rs` file will generate all the OpenGL functions in a file named,

### Global generator

The global generator is the one used by default by the `gl` crate. See the
The global generator is the one used by default by the `gl` crate. See the
[README](https://github.com/brendanzab/gl-rs/tree/master/gl) for more details.

### Struct generator
Expand Down
27 changes: 15 additions & 12 deletions gl_generator/generators/debug_struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ where
writeln!(
dest,
r#"
mod __gl_imports {{
pub use std::mem;
pub use std::marker::Send;
pub use std::os::raw;
}}
pub mod __gl_imports {{
"#
)
)?;

super::write_cty_aliases(dest)?;

writeln!(dest, r#"
pub use core::mem;
pub use core::marker::Send;
}}"#)
}

/// Creates a `types` module which contains all the type aliases.
Expand Down Expand Up @@ -96,17 +99,17 @@ where
#[derive(Clone)]
pub struct FnPtr {{
/// The function pointer that will be used when calling the function.
f: *const __gl_imports::raw::c_void,
f: *const __gl_imports::c_void,
/// True if the pointer points to a real function, false if points to a `panic!` fn.
is_loaded: bool,
}}

impl FnPtr {{
/// Creates a `FnPtr` from a load attempt.
fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{
fn new(ptr: *const __gl_imports::c_void) -> FnPtr {{
if ptr.is_null() {{
FnPtr {{
f: missing_fn_panic as *const __gl_imports::raw::c_void,
f: missing_fn_panic as *const __gl_imports::c_void,
is_loaded: false
}}
}} else {{
Expand Down Expand Up @@ -185,12 +188,12 @@ where
/// let gl = Gl::load_with(|s| glfw.get_proc_address(s));
/// ~~~
#[allow(dead_code, unused_variables)]
pub fn load_with<F>(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{
pub fn load_with<F>(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::c_void {{
#[inline(never)]
fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void,
fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::c_void,
symbol: &'static str,
symbols: &[&'static str])
-> *const __gl_imports::raw::c_void {{
-> *const __gl_imports::c_void {{
let mut ptr = loadfn(symbol);
if ptr.is_null() {{
for &sym in symbols {{
Expand Down
36 changes: 20 additions & 16 deletions gl_generator/generators/global_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ fn write_header<W>(dest: &mut W) -> io::Result<()>
where
W: io::Write,
{

writeln!(
dest,
r#"
mod __gl_imports {{
pub use std::mem;
pub use std::os::raw;
}}
pub mod __gl_imports {{
"#
)
)?;

super::write_cty_aliases(dest)?;

writeln!(dest, r#"
pub use core::mem;
}}"#)
}

/// Creates the metaloadfn function for fallbacks
Expand All @@ -63,9 +67,9 @@ where
dest,
r#"
#[inline(never)]
fn metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void,
fn metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::c_void,
symbol: &'static str,
fallbacks: &[&'static str]) -> *const __gl_imports::raw::c_void {{
fallbacks: &[&'static str]) -> *const __gl_imports::c_void {{
let mut ptr = loadfn(symbol);
if ptr.is_null() {{
for &sym in fallbacks {{
Expand Down Expand Up @@ -156,16 +160,16 @@ where
#[allow(missing_copy_implementations)]
pub struct FnPtr {{
/// The function pointer that will be used when calling the function.
f: *const __gl_imports::raw::c_void,
f: *const __gl_imports::c_void,
/// True if the pointer points to a real function, false if points to a `panic!` fn.
is_loaded: bool,
}}

impl FnPtr {{
/// Creates a `FnPtr` from a load attempt.
pub fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{
pub fn new(ptr: *const __gl_imports::c_void) -> FnPtr {{
if ptr.is_null() {{
FnPtr {{ f: missing_fn_panic as *const __gl_imports::raw::c_void, is_loaded: false }}
FnPtr {{ f: missing_fn_panic as *const __gl_imports::c_void, is_loaded: false }}
}} else {{
FnPtr {{ f: ptr, is_loaded: true }}
}}
Expand All @@ -184,15 +188,15 @@ where
"mod storage {{
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
use super::__gl_imports::raw;
use super::__gl_imports;
use super::FnPtr;"
)?;

for c in &registry.cmds {
writeln!(
dest,
"pub static mut {name}: FnPtr = FnPtr {{
f: super::missing_fn_panic as *const raw::c_void,
f: super::missing_fn_panic as *const c_void,
is_loaded: false
}};",
name = c.proto.ident
Expand Down Expand Up @@ -231,7 +235,7 @@ where
#[allow(non_snake_case)]
pub mod {fnname} {{
use super::{{storage, metaloadfn}};
use super::__gl_imports::raw;
use super::__gl_imports;
use super::FnPtr;

#[inline]
Expand All @@ -241,7 +245,7 @@ where
}}

#[allow(dead_code)]
pub fn load_with<F>(mut loadfn: F) where F: FnMut(&'static str) -> *const raw::c_void {{
pub fn load_with<F>(mut loadfn: F) where F: FnMut(&'static str) -> *const c_void {{
unsafe {{
storage::{fnname} = FnPtr::new(metaloadfn(&mut loadfn, "{symbol}", {fallbacks}))
}}
Expand Down Expand Up @@ -290,9 +294,9 @@ where
/// gl::load_with(|s| glfw.get_proc_address(s));
/// ~~~
#[allow(dead_code)]
pub fn load_with<F>(mut loadfn: F) where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{
pub fn load_with<F>(mut loadfn: F) where F: FnMut(&'static str) -> *const __gl_imports::c_void {{
#[inline(never)]
fn inner(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void) {{
fn inner(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::c_void) {{
")?;

for c in &registry.cmds {
Expand Down
10 changes: 10 additions & 0 deletions gl_generator/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ where
)
}

/// Generate a "cty" module with C type definitions in order
/// to be no_std compatible
fn write_cty_aliases<W>(dest: &mut W) -> io::Result<()>
where
W: io::Write,
{
writeln!(dest, "{}", include_str!("templates/types/cty.rs"))?;
Ok(())
}

/// Generates all the type aliases for a namespace.
///
/// Aliases are either `pub type = ...` or `#[repr(C)] pub struct ... { ... }` and contain all the
Expand Down
13 changes: 8 additions & 5 deletions gl_generator/generators/static_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ where
writeln!(
dest,
r#"
mod __gl_imports {{
pub use std::mem;
pub use std::os::raw;
}}
pub mod __gl_imports {{
"#
)
)?;

super::write_cty_aliases(dest)?;

writeln!(dest, r#"
pub use core::mem;
}}"#)
}

/// Creates a `types` module which contains all the type aliases.
Expand Down
15 changes: 9 additions & 6 deletions gl_generator/generators/static_struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ where
writeln!(
dest,
r#"
mod __gl_imports {{
pub use std::mem;
pub use std::os::raw;
}}
pub mod __gl_imports {{
"#
)
)?;

super::write_cty_aliases(dest)?;

writeln!(dest, r#"
pub use core::mem;
}}"#)
}

/// Creates a `types` module which contains all the type aliases.
Expand Down Expand Up @@ -108,7 +111,7 @@ where
"impl {api} {{
/// Stub function.
#[allow(dead_code)]
pub fn load_with<F>(mut _loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{
pub fn load_with<F>(mut _loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::c_void {{
{api}
}}",
api = super::gen_struct_name(registry.api),
Expand Down
27 changes: 15 additions & 12 deletions gl_generator/generators/struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ where
writeln!(
dest,
r#"
mod __gl_imports {{
pub use std::mem;
pub use std::marker::Send;
pub use std::os::raw;
}}
pub mod __gl_imports {{
"#
)
)?;

super::write_cty_aliases(dest)?;

writeln!(dest, r#"
pub use core::mem;
pub use core::marker::Send;
}}"#)
}

/// Creates a `types` module which contains all the type aliases.
Expand Down Expand Up @@ -96,17 +99,17 @@ where
#[derive(Clone)]
pub struct FnPtr {{
/// The function pointer that will be used when calling the function.
f: *const __gl_imports::raw::c_void,
f: *const __gl_imports::c_void,
/// True if the pointer points to a real function, false if points to a `panic!` fn.
is_loaded: bool,
}}

impl FnPtr {{
/// Creates a `FnPtr` from a load attempt.
fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{
fn new(ptr: *const __gl_imports::c_void) -> FnPtr {{
if ptr.is_null() {{
FnPtr {{
f: missing_fn_panic as *const __gl_imports::raw::c_void,
f: missing_fn_panic as *const __gl_imports::c_void,
is_loaded: false
}}
}} else {{
Expand Down Expand Up @@ -185,12 +188,12 @@ where
/// let gl = Gl::load_with(|s| glfw.get_proc_address(s));
/// ~~~
#[allow(dead_code, unused_variables)]
pub fn load_with<F>(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{
pub fn load_with<F>(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::c_void {{
#[inline(never)]
fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void,
fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::c_void,
symbol: &'static str,
symbols: &[&'static str])
-> *const __gl_imports::raw::c_void {{
-> *const __gl_imports::c_void {{
let mut ptr = loadfn(symbol);
if ptr.is_null() {{
for &sym in symbols {{
Expand Down
Loading