1
1
#![ allow( unreachable_code) ]
2
2
3
3
use std:: env;
4
- use std:: io:: { Error , ErrorKind , Result } ;
4
+ use std:: fs:: File ;
5
+ use std:: io:: { Error , ErrorKind , Result , Write } ;
5
6
use std:: path:: { Path , PathBuf } ;
6
7
use std:: process:: Command ;
7
8
@@ -96,51 +97,36 @@ fn build_glue<P: AsRef<Path> + std::fmt::Debug>(include_path: &P) {
96
97
// If you're cross-compiling and using a non-vendored library then there is a chance
97
98
// that the values selected here may be incorrect, but we have no way to determine
98
99
// that here.
99
- fn generate_glue ( ) -> std:: io:: Result < ( ) > {
100
- use std:: io:: Write ;
100
+ fn generate_glue ( ) -> Result < ( ) > {
101
101
let build_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
102
- let mut glue = std :: fs :: File :: create ( build_dir. join ( "glue.rs" ) ) ?;
103
- write ! (
102
+ let mut glue = File :: create ( build_dir. join ( "glue.rs" ) ) ?;
103
+ writeln ! (
104
104
glue,
105
- "/* This file was generated by build/main.rs; do not modify by hand */\n "
105
+ "/* This file was generated by build/main.rs; do not modify by hand */"
106
106
) ?;
107
- write ! ( glue, "use std::os::raw::*;\n " ) ?;
108
-
109
- // We can't statically determine the default paths.
110
- // It is possible though to use something like lazy_static! to create a new
111
- // lua context and extract that information.
112
- // For my (@wez) purposes, I actually don't want there to be a default path,
113
- // so I'm just leaving this blank for the moment.
114
- write ! ( glue, "pub const LUA_PATH_DEFAULT: &str = \" \" ;\n " ) ?;
115
- write ! ( glue, "pub const LUA_CPATH_DEFAULT: &str = \" \" ;\n " ) ?;
116
-
117
- write ! (
118
- glue,
119
- "#[cfg(windows)] pub const LUA_DIRSEP: &str = \" \\ \\ \" ;\n "
120
- ) ?;
121
- write ! ( glue, "#[cfg(unix)] pub const LUA_DIRSEP: &str = \" /\" ;\n " ) ?;
107
+ writeln ! ( glue, "use std::os::raw::*;" ) ?;
122
108
109
+ writeln ! ( glue, "/* luaconf.h */" ) ?;
123
110
let pointer_bit_width: usize = env:: var ( "CARGO_CFG_TARGET_POINTER_WIDTH" )
124
111
. unwrap ( )
125
112
. parse ( )
126
113
. unwrap ( ) ;
127
- write ! (
114
+ writeln ! (
128
115
glue,
129
- "pub const LUA_EXTRASPACE: c_int = {} / 8;\n " ,
116
+ "pub const LUA_EXTRASPACE: c_int = {} / 8;" ,
130
117
pointer_bit_width
131
118
) ?;
132
119
133
120
// This is generally hardcoded to this size
134
- write ! ( glue, "pub const LUA_IDSIZE: c_int = 60;\n " ) ?;
135
-
136
- write ! ( glue, "pub const LUAL_BUFFERSIZE: c_int = 16 * ({} / 8) * std::mem::size_of::<LUA_NUMBER>() as c_int;\n " , pointer_bit_width) ?;
121
+ writeln ! ( glue, "pub const LUA_IDSIZE: c_int = 60;" ) ?;
137
122
138
123
// Unless the target is restricted, the defaults are 64 bit
139
- write ! ( glue, "pub type LUA_NUMBER = c_double;\n " ) ?;
140
- write ! ( glue, "pub type LUA_INTEGER = i64;\n " ) ?;
141
- write ! ( glue, "pub type LUA_UNSIGNED = u64;\n " ) ?;
124
+ writeln ! ( glue, "pub type LUA_NUMBER = c_double;" ) ?;
125
+ writeln ! ( glue, "pub type LUA_INTEGER = i64;" ) ?;
126
+ writeln ! ( glue, "pub type LUA_UNSIGNED = u64;" ) ?;
142
127
143
- let version = if cfg ! ( feature = "luajit" ) || cfg ! ( feature = "lua51" ) {
128
+ writeln ! ( glue, "/* lua.h */" ) ?;
129
+ let version = if cfg ! ( any( feature = "luajit" , feature = "lua51" ) ) {
144
130
( 5 , 1 , 0 )
145
131
} else if cfg ! ( feature = "lua52" ) {
146
132
( 5 , 2 , 0 )
@@ -151,43 +137,34 @@ fn generate_glue() -> std::io::Result<()> {
151
137
} else {
152
138
unreachable ! ( ) ;
153
139
} ;
154
-
155
- write ! (
140
+ writeln ! (
156
141
glue,
157
- "pub const LUA_VERSION_NUM: c_int = {};\n " ,
142
+ "pub const LUA_VERSION_NUM: c_int = {};" ,
158
143
( version. 0 * 100 ) + version. 1
159
144
) ?;
160
- write ! (
161
- glue,
162
- "pub const LUA_VERSION: &str = \" Lua {}.{}\" ;\n " ,
163
- version. 0 , version. 1
164
- ) ?;
165
- write ! (
166
- glue,
167
- "pub const LUA_RELEASE: &str = \" Lua {}.{}.{}\" ;\n " ,
168
- version. 0 , version. 1 , version. 2
169
- ) ?;
170
145
171
146
let max_stack = if pointer_bit_width >= 32 {
172
147
1_000_000
173
148
} else {
174
149
15_000
175
150
} ;
176
- write ! (
151
+ writeln ! (
177
152
glue,
178
- "pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;\n " ,
153
+ "pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;" ,
179
154
max_stack
180
155
) ?;
181
156
182
157
// These two are only defined in lua 5.1
183
- write ! ( glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;\n " ) ?;
184
- write ! ( glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;\n " ) ?;
158
+ writeln ! ( glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;" ) ?;
159
+ writeln ! ( glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;" ) ?;
185
160
161
+ writeln ! ( glue, "/* lauxlib.h */" ) ?;
186
162
// This is only defined in lua 5.3 and up, but we can always generate its value here,
187
163
// even if we don't use it.
188
164
// This matches the default definition in lauxlib.h
189
- 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 " ) ?;
165
+ 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;" ) ?;
190
166
167
+ writeln ! ( glue, "/* lualib.h */" ) ?;
191
168
write ! (
192
169
glue,
193
170
r#"
0 commit comments