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

The big 2018 cleanup #507

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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 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.21.0"
4 changes: 2 additions & 2 deletions gl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&out_dir).join("bindings.rs")).unwrap();

Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(GlobalGenerator, &mut file)
Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::Yes, [])
.write_bindings(GlobalGenerator::default(), &mut file)
.unwrap();
}
4 changes: 3 additions & 1 deletion gl_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "gl_generator"
version = "0.14.0"
version = "0.15.0"
authors = [
"Brendan Zabarauskas <bjzaba@yahoo.com.au>",
"Corey Richardson",
"Arseny Kapoulkine",
"Lokathor <zefria@gmail.com>",
]
description = "Code generators for creating bindings to the Khronos OpenGL APIs."
license = "Apache-2.0"
Expand All @@ -14,6 +15,7 @@ repository = "https://github.com/brendanzab/gl-rs/"
readme = "README.md"
categories = ["api-bindings", "rendering::graphics-api"]
keywords = ["gl", "egl", "opengl", "khronos"]
edition = "2018"

[lib]
name = "gl_generator"
Expand Down
4 changes: 2 additions & 2 deletions gl_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn main() {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("bindings.rs")).unwrap();

Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(GlobalGenerator, &mut file)
Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::Yes, [])
.write_bindings(GlobalGenerator::default(), &mut file)
.unwrap();
}
```
Expand Down
105 changes: 74 additions & 31 deletions gl_generator/generators/mod.rs → gl_generator/generators.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
// Copyright 2015 Brendan Zabarauskas and the gl-rs developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use registry::{Cmd, Enum, Registry};
// some stuff in here is dead if you don't turn on the unstable feature.
#![allow(dead_code)]

use crate::registry::{Api, Cmd, Enum, Registry};
use std::io;
use Api;

pub mod debug_struct_gen;
pub mod global_gen;
pub mod static_gen;
pub mod static_struct_gen;
Expand Down Expand Up @@ -50,37 +37,57 @@ pub fn gen_enum_item<W>(enm: &Enum, types_prefix: &str, dest: &mut W) -> io::Res
where
W: io::Write,
{
writeln!(dest,
"#[allow(dead_code, non_upper_case_globals)] pub const {ident}: {types_prefix}{ty} = {value}{cast_suffix};",
// TODO: remove the types_prefix thing? Seems silly, doesn't seem user
// configurable.
writeln!(
dest,
"pub const {ident}: {types_prefix}{ty} = {value}{cast_suffix};",
ident = enm.ident,
types_prefix = if enm.ty == "&'static str" { "" } else { types_prefix },
types_prefix = if enm.ty == "&'static str" {
""
} else {
types_prefix
},
ty = enm.ty,
value = enm.value,
cast_suffix = match enm.cast {
true => format!(" as {}{}", types_prefix, enm.ty),
false => String::new(),
cast_suffix = if enm.cast {
format!(" as {}{}", types_prefix, enm.ty)
} else {
String::new()
},
)
}

/// Generates all the type aliases for a namespace.
///
/// Aliases are either `pub type = ...` or `#[repr(C)] pub struct ... { ... }` and contain all the
/// things that we can't obtain from the XML files.
/// Aliases are either `pub type = ...` or `#[repr(C)] pub struct ... { ... }`
/// and contain all the things that we can't obtain from the XML files.
pub fn gen_types<W>(api: Api, dest: &mut W) -> io::Result<()>
where
W: io::Write,
{
if let Api::Egl = api {
try!(writeln!(dest, "{}", include_str!("templates/types/egl.rs")));
writeln!(
dest,
"{}",
include_str!("generators/templates/types/egl.rs")
)?;
return Ok(());
}

try!(writeln!(dest, "{}", include_str!("templates/types/gl.rs")));
writeln!(dest, "{}", include_str!("generators/templates/types/gl.rs"))?;

match api {
Api::Glx => try!(writeln!(dest, "{}", include_str!("templates/types/glx.rs"))),
Api::Wgl => try!(writeln!(dest, "{}", include_str!("templates/types/wgl.rs"))),
Api::Glx => writeln!(
dest,
"{}",
include_str!("generators/templates/types/glx.rs")
)?,
Api::Wgl => writeln!(
dest,
"{}",
include_str!("generators/templates/types/wgl.rs")
)?,
_ => {},
}

Expand All @@ -96,9 +103,9 @@ pub fn gen_parameters(cmd: &Cmd, with_idents: bool, with_types: bool) -> Vec<Str
if with_idents && with_types {
format!("{}: {}", binding.ident, binding.ty)
} else if with_types {
format!("{}", binding.ty)
binding.ty.to_string()
} else if with_idents {
format!("{}", binding.ident)
binding.ident.to_string()
} else {
panic!()
}
Expand All @@ -117,3 +124,39 @@ pub fn gen_symbol_name(api: Api, cmd: &str) -> String {
Api::Egl => format!("egl{}", cmd),
}
}

/// Writes all types into their own sub-module.
pub fn write_type_aliases<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
where
W: io::Write,
Lokathor marked this conversation as resolved.
Show resolved Hide resolved
{
writeln!(
dest,
r#"pub use types::*;
pub mod types {{
use super::*;"#
)?;

gen_types(registry.api(), dest)?;

writeln!(dest, "}}")
}

/// Writes all consts into their own sub-module.
fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()>
where
W: io::Write,
{
writeln!(
dest,
r#"pub use consts::*;
pub mod consts {{
use super::*;"#
)?;

for enm in registry.enums() {
gen_enum_item(enm, "", dest)?;
}

writeln!(dest, "}}")
}
Loading