Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ jobs:
run: |
cargo test --manifest-path testcrate/Cargo.toml --release
cargo test --manifest-path testcrate/Cargo.toml --release --features lua52compat
cargo test --manifest-path testcrate/Cargo.toml --release --features openresty
cargo test --manifest-path testcrate/Cargo.toml --release --features openresty,lua52compat
shell: bash

rustfmt:
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = luajit2
url = https://github.com/LuaJIT/LuaJIT.git
branch = v2.1
[submodule "luajit2-openresty"]
path = luajit2-openresty
url = https://github.com/openresty/luajit2.git
branch = v2.1-agentzh
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ license = "MIT"
description = """
Sources of LuaJIT 2.1 and logic to build it.
"""
exclude = ["/luajit2/doc", "/luajit2/etc"]
exclude = ["/luajit2/doc", "/luajit2/etc", "/luajit2-openresty/doc", "/luajit2-openresty/etc", "/luajit2-openresty/t"]

[workspace]
members = ["testcrate"]

[features]
openresty = []

[dependencies]
cc = "1.2"
which = "8.0"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
This crate contains the sources of [LuaJIT] 2.1 (from Mike Pall) and logic to build it.
Intended to be consumed by the [mlua-sys] crate.

By default, this crate builds vanilla LuaJIT from the official repository. An optional `openresty` feature is available that builds [OpenResty's LuaJIT fork](https://github.com/openresty/luajit2) instead, which includes additional patches and support for architectures not available in vanilla LuaJIT, such as s390x (interpreter-only mode, no JIT compilation).

[LuaJIT]: https://github.com/LuaJIT/LuaJIT
[mlua-sys]: https://crates.io/crates/mlua-sys

Expand Down
1 change: 1 addition & 0 deletions luajit2-openresty
Submodule luajit2-openresty added at f75bf4
1 change: 1 addition & 0 deletions luajit_relver_openresty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1789605824
36 changes: 30 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ pub struct Artifacts {
libs: Vec<String>,
}

#[cfg(feature = "openresty")]
fn source_dir(manifest_dir: &Path) -> PathBuf {
manifest_dir.join("luajit2-openresty")
}

#[cfg(not(feature = "openresty"))]
fn source_dir(manifest_dir: &Path) -> PathBuf {
manifest_dir.join("luajit2")
}

#[cfg(feature = "openresty")]
fn relver_file(manifest_dir: &Path) -> PathBuf {
manifest_dir.join("luajit_relver_openresty.txt")
}

#[cfg(not(feature = "openresty"))]
fn relver_file(manifest_dir: &Path) -> PathBuf {
manifest_dir.join("luajit_relver.txt")
}

impl Default for Build {
fn default() -> Self {
Build {
Expand Down Expand Up @@ -111,7 +131,7 @@ impl Build {
let host = &self.host.as_ref().expect("HOST is not set")[..];
let out_dir = self.out_dir.as_ref().expect("OUT_DIR is not set");
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let source_dir = manifest_dir.join("luajit2");
let source_dir = source_dir(manifest_dir);
let build_dir = out_dir.join("luajit-build");
let lib_dir = out_dir.join("lib");
let include_dir = out_dir.join("include");
Expand All @@ -127,8 +147,8 @@ impl Build {

// Copy release version file
let relver = build_dir.join(".relver");
fs::copy(manifest_dir.join("luajit_relver.txt"), &relver)
.context(|| "Cannot copy 'luajit_relver.txt'")?;
fs::copy(relver_file(manifest_dir), &relver)
.context(|| "Cannot copy release version file")?;
Comment thread
Chandrababunagilli-ibm marked this conversation as resolved.
Resolved

// Fix permissions for certain build situations
let mut perms = (fs::metadata(&relver).map(|md| md.permissions()))
Expand Down Expand Up @@ -237,6 +257,10 @@ impl Build {
make.env("CCDEBUG", "-g");
xcflags.push("-DLUA_USE_ASSERT");
xcflags.push("-DLUA_USE_APICHECK");
} else if cfg!(feature = "openresty") {
// Override OpenResty's default CCDEBUG=-g to ensure release builds
// don't include debug symbols, matching vanilla LuaJIT behavior
make.env("CCDEBUG", "");
}

make.env("BUILDMODE", "static");
Expand All @@ -251,7 +275,7 @@ impl Build {
let target = &self.target.as_ref().expect("TARGET is not set")[..];
let out_dir = self.out_dir.as_ref().expect("OUT_DIR is not set");
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let source_dir = manifest_dir.join("luajit2");
let source_dir = source_dir(manifest_dir);
let build_dir = out_dir.join("luajit-build");
let lib_dir = out_dir.join("lib");
let include_dir = out_dir.join("include");
Expand All @@ -267,8 +291,8 @@ impl Build {

// Copy release version file
let relver = build_dir.join(".relver");
fs::copy(manifest_dir.join("luajit_relver.txt"), &relver)
.context(|| "Cannot copy 'luajit_relver.txt'")?;
fs::copy(relver_file(manifest_dir), &relver)
.context(|| "Cannot copy release version file")?;
Comment thread
Chandrababunagilli-ibm marked this conversation as resolved.
Resolved

let mut msvcbuild = Command::new(build_dir.join("src").join("msvcbuild.bat"));
msvcbuild.current_dir(build_dir.join("src"));
Expand Down
1 change: 1 addition & 0 deletions testcrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish = false

[features]
lua52compat = []
openresty = ["luajit-src/openresty"]

[build-dependencies]
luajit-src = { path = ".." }
4 changes: 4 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ set -eux
cd luajit2
git pull
git show -s --format=%ct > ../luajit_relver.txt

cd ../luajit2-openresty
git pull
git show -s --format=%ct > ../luajit_relver_openresty.txt