From 47da6e0ab45a6ec17926634a34b4941fb8763b2a Mon Sep 17 00:00:00 2001 From: Chandra Nagilli Date: Fri, 9 Oct 2026 13:37:14 -0700 Subject: [PATCH 1/4] Add opt-in openresty feature for s390x support - Add OpenResty LuaJIT submodule (commit f75bf45e, version 1789605824) - Implement conditional compilation based on openresty feature flag - Extend CI to test openresty feature - Update documentation for s390x support - Add helper functions source_dir() and relver_file() - Update update.sh to handle OpenResty submodule Tested on x86_64 (JIT enabled) and s390x (interpreter-only). All 215 mlua integration tests pass on both architectures. --- .github/workflows/main.yml | 2 ++ .gitmodules | 4 ++++ Cargo.toml | 5 ++++- README.md | 2 ++ luajit2-openresty | 1 + luajit_relver_openresty.txt | 1 + src/lib.rs | 34 ++++++++++++++++++++++++++++------ testcrate/Cargo.toml | 1 + update.sh | 4 ++++ 9 files changed, 47 insertions(+), 7 deletions(-) create mode 160000 luajit2-openresty create mode 100644 luajit_relver_openresty.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42515ba..89a5d7f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: diff --git a/.gitmodules b/.gitmodules index c1ae63b..97cd4ca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 9ad3bfe..fbbcb21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index ab3d93a..72b5127 100644 --- a/README.md +++ b/README.md @@ -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 and ppc64le. Note that on s390x, the OpenResty build runs in interpreter-only mode (no JIT compilation). + [LuaJIT]: https://github.com/LuaJIT/LuaJIT [mlua-sys]: https://crates.io/crates/mlua-sys diff --git a/luajit2-openresty b/luajit2-openresty new file mode 160000 index 0000000..f75bf45 --- /dev/null +++ b/luajit2-openresty @@ -0,0 +1 @@ +Subproject commit f75bf45e8b869a8ee4562ab0183322c3ebf2d9f3 diff --git a/luajit_relver_openresty.txt b/luajit_relver_openresty.txt new file mode 100644 index 0000000..aa95865 --- /dev/null +++ b/luajit_relver_openresty.txt @@ -0,0 +1 @@ +1789605824 diff --git a/src/lib.rs b/src/lib.rs index 7ebaccf..c1f5a52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,26 @@ pub struct Artifacts { libs: Vec, } +#[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 { @@ -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"); @@ -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")?; // Fix permissions for certain build situations let mut perms = (fs::metadata(&relver).map(|md| md.permissions())) @@ -237,6 +257,8 @@ impl Build { make.env("CCDEBUG", "-g"); xcflags.push("-DLUA_USE_ASSERT"); xcflags.push("-DLUA_USE_APICHECK"); + } else if cfg!(feature = "openresty") { + make.env("CCDEBUG", ""); } make.env("BUILDMODE", "static"); @@ -251,7 +273,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"); @@ -267,8 +289,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")?; let mut msvcbuild = Command::new(build_dir.join("src").join("msvcbuild.bat")); msvcbuild.current_dir(build_dir.join("src")); diff --git a/testcrate/Cargo.toml b/testcrate/Cargo.toml index d62d185..3427fee 100644 --- a/testcrate/Cargo.toml +++ b/testcrate/Cargo.toml @@ -7,6 +7,7 @@ publish = false [features] lua52compat = [] +openresty = ["luajit-src/openresty"] [build-dependencies] luajit-src = { path = ".." } diff --git a/update.sh b/update.sh index f1c556f..7dd8448 100755 --- a/update.sh +++ b/update.sh @@ -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 \ No newline at end of file From 6f2888d8a11a22f377fdddb65acdaba13145ea5c Mon Sep 17 00:00:00 2001 From: Chandra Nagilli Date: Sun, 11 Oct 2026 22:22:07 -0700 Subject: [PATCH 2/4] Fix README: Remove unverified ppc64le claim, keep only tested s390x --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72b5127..422aff7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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 and ppc64le. Note that on s390x, the OpenResty build runs in interpreter-only mode (no JIT compilation). +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 From 664e28138c2b60a19c071c98d71b53344d80e8fb Mon Sep 17 00:00:00 2001 From: Chandra Nagilli Date: Tue, 13 Oct 2026 03:53:19 -0700 Subject: [PATCH 3/4] Add explanatory comment for CCDEBUG override in OpenResty builds --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c1f5a52..f85f4c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,8 @@ impl Build { 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", ""); } From 688ef4de0ac243941f61575f1c667226dfb9e5a6 Mon Sep 17 00:00:00 2001 From: Chandra Nagilli Date: Tue, 13 Oct 2026 07:37:09 -0700 Subject: [PATCH 4/4] Improve error messages: include source filename when copying relver file - Add relver_src variable to capture source path - Update error context to show which file failed to copy - Applied to both Unix and MSVC build paths Addresses review feedback from ramgdev --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f85f4c1..b16df2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -147,8 +147,9 @@ impl Build { // Copy release version file let relver = build_dir.join(".relver"); - fs::copy(relver_file(manifest_dir), &relver) - .context(|| "Cannot copy release version file")?; + let relver_src = relver_file(manifest_dir); + fs::copy(&relver_src, &relver) + .context(|| format!("Cannot copy release version file from '{}'", relver_src.display()))?; // Fix permissions for certain build situations let mut perms = (fs::metadata(&relver).map(|md| md.permissions())) @@ -291,8 +292,9 @@ impl Build { // Copy release version file let relver = build_dir.join(".relver"); - fs::copy(relver_file(manifest_dir), &relver) - .context(|| "Cannot copy release version file")?; + let relver_src = relver_file(manifest_dir); + fs::copy(&relver_src, &relver) + .context(|| format!("Cannot copy release version file from '{}'", relver_src.display()))?; let mut msvcbuild = Command::new(build_dir.join("src").join("msvcbuild.bat")); msvcbuild.current_dir(build_dir.join("src"));