Make the changes I proposed to PR #79

Allows people (maybe only I care about this?) to build rlua in weird
environments.
This commit is contained in:
kyren 2018-09-16 21:18:24 -04:00
parent c07abdc03e
commit 14090821d3
2 changed files with 19 additions and 4 deletions

View File

@ -23,6 +23,13 @@ default = ["builtin-lua"]
# * LUA_EXTRASPACE is at least pointer sized and has at least pointer alignment. # * LUA_EXTRASPACE is at least pointer sized and has at least pointer alignment.
# * LUAI_MAXSTACK is 1_000_000 # * LUAI_MAXSTACK is 1_000_000
builtin-lua = ["cc"] builtin-lua = ["cc"]
# Uses pkg-config to find an appropriate lua 5.3 library to link with. All of
# the caveats about disabling the default builtin-lua feature apply here as
# well. If neither the builtin-lua nor the system-lua feature is enabled, then
# no lua library will be linked at all and one must be linked with or built into
# the final binary manually. The builtin-lua and system-lua features are
# mutually exclusive and enabling both will cause an error at build time.
system-lua = ["pkg-config"]
[dependencies] [dependencies]
libc = { version = "0.2" } libc = { version = "0.2" }
@ -31,7 +38,7 @@ compiletest_rs = { version = "0.3", optional = true }
[build-dependencies] [build-dependencies]
cc = { version = "1.0", optional = true } cc = { version = "1.0", optional = true }
pkg-config = "0.3.11" pkg-config = { version = "0.3.11", optional = true }
[dev-dependencies] [dev-dependencies]
rustyline = "1.0.0" rustyline = "1.0.0"

View File

@ -1,10 +1,14 @@
#[cfg(feature = "builtin-lua")] #[cfg(feature = "builtin-lua")]
extern crate cc; extern crate cc;
#[cfg(not(feature = "builtin-lua"))] #[cfg(feature = "system-lua")]
extern crate pkg_config; extern crate pkg_config;
fn main() { fn main() {
if cfg!(all(feature = "builtin-lua", feature = "system-lua")) {
panic!("cannot enable both builtin-lua and system-lua features when building rlua");
}
#[cfg(feature = "builtin-lua")] #[cfg(feature = "builtin-lua")]
{ {
use std::env; use std::env;
@ -65,8 +69,12 @@ fn main() {
.file("lua/lzio.c") .file("lua/lzio.c")
.compile("liblua5.3.a"); .compile("liblua5.3.a");
} }
#[cfg(not(feature = "builtin-lua"))]
#[cfg(feature = "system-lua")]
{ {
pkg_config::Config::new().atleast_version("5.3").probe("lua").unwrap(); pkg_config::Config::new()
.atleast_version("5.3")
.probe("lua")
.unwrap();
} }
} }