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..422aff7 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 (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..b16df2b 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,9 @@ 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'")?; + 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())) @@ -237,6 +258,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"); @@ -251,7 +276,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 +292,9 @@ 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'")?; + 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")); 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