Skip to content
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
9 changes: 8 additions & 1 deletion mlua-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ module = []
[build-dependencies]
cc = "1.0"
cfg-if = "1.0"
pkg-config = "0.3.17"
system-deps = "7.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distro packager hat on here. How exactly does the system-deps crate go about determining if the appropriate headers and sources are installed on a host system? If this isn't using pkg-config under the hood somewhere (it may be) then this feels like a regression. If it's just an ergonomic wrapper around the same tooling that's probably fine, but it it is some bespoke hand rolled detection system this would be a huge red flag.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two separate changes - adding metadata for parsing by any tool (easier than going through code) and one to use the added metadata for pkg-config's probe() calls:

  1. First commit: Specifying dependencies in Cargo.toml in a way that can be parsed. This is for any bespoke tools - no code change, only metadata added to Cargo.toml. Figured the format from system-deps can be reused (as in the second commit, described below). This commit is enough for ci tools to parse and figure out which pkgs to install.
  2. Second commit: Once we specify in Cargo.toml, we might as well switch to system-deps in mlua-sys itself. Cargo.toml of system-deps crate uses pkg-config.
    It explicitly uses pkg-config under the hood here.

For my use case, the first commit is enough but system-deps can use it to call pkg-config's probe() and we can avoid repeating the same info in the code, hence the second commit.

Please let me know if I missed something.

lua-src = { version = ">= 548.1.0, < 548.2.0", optional = true }
luajit-src = { version = ">= 210.6.0, < 210.7.0", optional = true }
luau0-src = { version = "0.17.0", optional = true }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(raw_dylib)'] }

[package.metadata.system-deps]
lua54 = { name = "lua", fallback-names = ["lua5.4", "lua-5.4", "lua54"], version = ">= 5.4, < 5.5", feature = "lua54" }
lua53 = { name = "lua", fallback-names = ["lua5.3", "lua-5.3", "lua53"], version = ">= 5.3, < 5.4", feature = "lua53" }
lua52 = { name = "lua", fallback-names = ["lua5.2", "lua-5.2", "lua52"], version = ">= 5.2, < 5.3", feature = "lua52" }
lua51 = { name = "lua", fallback-names = ["lua5.1", "lua-5.1", "lua51"], version = ">= 5.1, < 5.2", feature = "lua51" }
luajit = { name = "luajit", version = ">= 2.0.4, < 2.2", feature = "luajit" }
40 changes: 3 additions & 37 deletions mlua-sys/build/find_normal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(dead_code)]

use std::env;
use std::ops::Bound;

pub fn probe_lua() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
Expand Down Expand Up @@ -29,40 +28,7 @@ pub fn probe_lua() {
return;
}

// Find using `pkg-config`

#[cfg(feature = "lua54")]
let (incl_bound, excl_bound, alt_probe, ver) =
("5.4", "5.5", ["lua5.4", "lua-5.4", "lua54"], "5.4");
#[cfg(feature = "lua53")]
let (incl_bound, excl_bound, alt_probe, ver) =
("5.3", "5.4", ["lua5.3", "lua-5.3", "lua53"], "5.3");
#[cfg(feature = "lua52")]
let (incl_bound, excl_bound, alt_probe, ver) =
("5.2", "5.3", ["lua5.2", "lua-5.2", "lua52"], "5.2");
#[cfg(feature = "lua51")]
let (incl_bound, excl_bound, alt_probe, ver) =
("5.1", "5.2", ["lua5.1", "lua-5.1", "lua51"], "5.1");
#[cfg(feature = "luajit")]
let (incl_bound, excl_bound, alt_probe, ver) = ("2.0.4", "2.2", [], "JIT");

#[rustfmt::skip]
let mut lua = pkg_config::Config::new()
.range_version((Bound::Included(incl_bound), Bound::Excluded(excl_bound)))
.cargo_metadata(true)
.probe(if cfg!(feature = "luajit") { "luajit" } else { "lua" });

if lua.is_err() {
for pkg in alt_probe {
lua = pkg_config::Config::new()
.cargo_metadata(true)
.probe(pkg);

if lua.is_ok() {
break;
}
}
}

lua.unwrap_or_else(|err| panic!("cannot find Lua{ver} using `pkg-config`: {err}"));
// This reads [package.metadata.system-deps] from Cargo.toml
system_deps::Config::new().probe().unwrap();
}

Loading