Remove unused exports from glue.{c,rs} && Fix some clippy warnings
This commit is contained in:
parent
1c79f646de
commit
e62fd400d7
|
@ -1,7 +1,8 @@
|
|||
#![allow(unreachable_code)]
|
||||
|
||||
use std::env;
|
||||
use std::io::{Error, ErrorKind, Result};
|
||||
use std::fs::File;
|
||||
use std::io::{Error, ErrorKind, Result, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
|
@ -96,51 +97,36 @@ fn build_glue<P: AsRef<Path> + std::fmt::Debug>(include_path: &P) {
|
|||
// If you're cross-compiling and using a non-vendored library then there is a chance
|
||||
// that the values selected here may be incorrect, but we have no way to determine
|
||||
// that here.
|
||||
fn generate_glue() -> std::io::Result<()> {
|
||||
use std::io::Write;
|
||||
fn generate_glue() -> Result<()> {
|
||||
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
let mut glue = std::fs::File::create(build_dir.join("glue.rs"))?;
|
||||
write!(
|
||||
let mut glue = File::create(build_dir.join("glue.rs"))?;
|
||||
writeln!(
|
||||
glue,
|
||||
"/* This file was generated by build/main.rs; do not modify by hand */\n"
|
||||
"/* This file was generated by build/main.rs; do not modify by hand */"
|
||||
)?;
|
||||
write!(glue, "use std::os::raw::*;\n")?;
|
||||
|
||||
// We can't statically determine the default paths.
|
||||
// It is possible though to use something like lazy_static! to create a new
|
||||
// lua context and extract that information.
|
||||
// For my (@wez) purposes, I actually don't want there to be a default path,
|
||||
// so I'm just leaving this blank for the moment.
|
||||
write!(glue, "pub const LUA_PATH_DEFAULT: &str = \"\";\n")?;
|
||||
write!(glue, "pub const LUA_CPATH_DEFAULT: &str = \"\";\n")?;
|
||||
|
||||
write!(
|
||||
glue,
|
||||
"#[cfg(windows)] pub const LUA_DIRSEP: &str = \"\\\\\";\n"
|
||||
)?;
|
||||
write!(glue, "#[cfg(unix)] pub const LUA_DIRSEP: &str = \"/\";\n")?;
|
||||
writeln!(glue, "use std::os::raw::*;")?;
|
||||
|
||||
writeln!(glue, "/* luaconf.h */")?;
|
||||
let pointer_bit_width: usize = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
|
||||
.unwrap()
|
||||
.parse()
|
||||
.unwrap();
|
||||
write!(
|
||||
writeln!(
|
||||
glue,
|
||||
"pub const LUA_EXTRASPACE: c_int = {} / 8;\n",
|
||||
"pub const LUA_EXTRASPACE: c_int = {} / 8;",
|
||||
pointer_bit_width
|
||||
)?;
|
||||
|
||||
// This is generally hardcoded to this size
|
||||
write!(glue, "pub const LUA_IDSIZE: c_int = 60;\n")?;
|
||||
|
||||
write!(glue, "pub const LUAL_BUFFERSIZE: c_int = 16 * ({} / 8) * std::mem::size_of::<LUA_NUMBER>() as c_int;\n", pointer_bit_width)?;
|
||||
writeln!(glue, "pub const LUA_IDSIZE: c_int = 60;")?;
|
||||
|
||||
// Unless the target is restricted, the defaults are 64 bit
|
||||
write!(glue, "pub type LUA_NUMBER = c_double;\n")?;
|
||||
write!(glue, "pub type LUA_INTEGER = i64;\n")?;
|
||||
write!(glue, "pub type LUA_UNSIGNED = u64;\n")?;
|
||||
writeln!(glue, "pub type LUA_NUMBER = c_double;")?;
|
||||
writeln!(glue, "pub type LUA_INTEGER = i64;")?;
|
||||
writeln!(glue, "pub type LUA_UNSIGNED = u64;")?;
|
||||
|
||||
let version = if cfg!(feature = "luajit") || cfg!(feature = "lua51") {
|
||||
writeln!(glue, "/* lua.h */")?;
|
||||
let version = if cfg!(any(feature = "luajit", feature = "lua51")) {
|
||||
(5, 1, 0)
|
||||
} else if cfg!(feature = "lua52") {
|
||||
(5, 2, 0)
|
||||
|
@ -151,43 +137,34 @@ fn generate_glue() -> std::io::Result<()> {
|
|||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
write!(
|
||||
writeln!(
|
||||
glue,
|
||||
"pub const LUA_VERSION_NUM: c_int = {};\n",
|
||||
"pub const LUA_VERSION_NUM: c_int = {};",
|
||||
(version.0 * 100) + version.1
|
||||
)?;
|
||||
write!(
|
||||
glue,
|
||||
"pub const LUA_VERSION: &str = \"Lua {}.{}\";\n",
|
||||
version.0, version.1
|
||||
)?;
|
||||
write!(
|
||||
glue,
|
||||
"pub const LUA_RELEASE: &str = \"Lua {}.{}.{}\";\n",
|
||||
version.0, version.1, version.2
|
||||
)?;
|
||||
|
||||
let max_stack = if pointer_bit_width >= 32 {
|
||||
1_000_000
|
||||
} else {
|
||||
15_000
|
||||
};
|
||||
write!(
|
||||
writeln!(
|
||||
glue,
|
||||
"pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;\n",
|
||||
"pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;",
|
||||
max_stack
|
||||
)?;
|
||||
|
||||
// These two are only defined in lua 5.1
|
||||
write!(glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;\n")?;
|
||||
write!(glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;\n")?;
|
||||
writeln!(glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;")?;
|
||||
writeln!(glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;")?;
|
||||
|
||||
writeln!(glue, "/* lauxlib.h */")?;
|
||||
// This is only defined in lua 5.3 and up, but we can always generate its value here,
|
||||
// even if we don't use it.
|
||||
// This matches the default definition in lauxlib.h
|
||||
write!(glue, "pub const LUAL_NUMSIZES: c_int = std::mem::size_of::<LUA_INTEGER>() as c_int * 16 + std::mem::size_of::<LUA_NUMBER>() as c_int;\n")?;
|
||||
writeln!(glue, "pub const LUAL_NUMSIZES: c_int = std::mem::size_of::<LUA_INTEGER>() as c_int * 16 + std::mem::size_of::<LUA_NUMBER>() as c_int;")?;
|
||||
|
||||
writeln!(glue, "/* lualib.h */")?;
|
||||
write!(
|
||||
glue,
|
||||
r#"
|
||||
|
|
|
@ -225,12 +225,8 @@ int main(int argc, const char **argv) {
|
|||
// == luaconf.h ==========================================================
|
||||
|
||||
RS_COMMENT("luaconf.h"),
|
||||
RS_STR("LUA_PATH_DEFAULT", LUA_PATH_DEFAULT),
|
||||
RS_STR("LUA_CPATH_DEFAULT", LUA_CPATH_DEFAULT),
|
||||
RS_STR("LUA_DIRSEP", LUA_DIRSEP),
|
||||
RS_INT("LUA_EXTRASPACE", LUA_EXTRASPACE),
|
||||
RS_INT("LUA_IDSIZE", LUA_IDSIZE),
|
||||
RS_INT("LUAL_BUFFERSIZE", LUAL_BUFFERSIZE),
|
||||
RS_TYPE("LUA_NUMBER",
|
||||
sizeof(LUA_NUMBER) > sizeof(float) ? "c_double" : "c_float"),
|
||||
RS_TYPE("LUA_INTEGER", rs_int_type(sizeof(LUA_INTEGER))),
|
||||
|
@ -244,8 +240,6 @@ int main(int argc, const char **argv) {
|
|||
|
||||
RS_COMMENT("lua.h"),
|
||||
RS_INT("LUA_VERSION_NUM", LUA_VERSION_NUM),
|
||||
RS_STR("LUA_VERSION", LUA_VERSION),
|
||||
RS_STR("LUA_RELEASE", LUA_RELEASE),
|
||||
RS_INT("LUA_REGISTRYINDEX", LUA_REGISTRYINDEX),
|
||||
#if LUA_VERSION_NUM == 501
|
||||
RS_INT("LUA_ENVIRONINDEX", LUA_ENVIRONINDEX),
|
||||
|
|
|
@ -32,11 +32,9 @@ use std::ptr;
|
|||
|
||||
use super::luaconf;
|
||||
|
||||
pub use super::glue::{LUA_RELEASE, LUA_VERSION, LUA_VERSION_NUM};
|
||||
|
||||
pub use super::glue::LUA_REGISTRYINDEX;
|
||||
#[cfg(any(feature = "lua51", feature = "luajit"))]
|
||||
pub use super::glue::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX};
|
||||
pub use super::glue::{LUA_REGISTRYINDEX, LUA_VERSION_NUM};
|
||||
|
||||
#[cfg(not(feature = "luajit"))]
|
||||
pub const LUA_SIGNATURE: &[u8] = b"\x1bLua";
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
//! Contains definitions from `luaconf.h`.
|
||||
|
||||
pub use super::glue::LUAL_BUFFERSIZE;
|
||||
pub use super::glue::LUA_INTEGER;
|
||||
pub use super::glue::LUA_NUMBER;
|
||||
pub use super::glue::LUA_UNSIGNED;
|
||||
|
|
Loading…
Reference in New Issue