Add luajit
This commit is contained in:
parent
1ebeaa9e95
commit
8f6fc64f7a
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "luajit"]
|
||||
path = crates/luajit/src
|
||||
url = https://github.com/LuaJIT/LuaJIT.git
|
393
Cargo.lock
generated
393
Cargo.lock
generated
@ -2,6 +2,41 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.71.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools",
|
||||
"log",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.12.0"
|
||||
@ -13,6 +48,106 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "env_home"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.174"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.53.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "luaffi"
|
||||
version = "0.1.0"
|
||||
@ -43,9 +178,25 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "luajit"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"bitflags",
|
||||
"bstr",
|
||||
"cc",
|
||||
"luaffi",
|
||||
"thiserror",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "luby"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"luajit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@ -53,6 +204,32 @@ version = "2.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6837b9e10d61f45f987d50808f83d1ee3d206c66acf650c3e4ae2e1f6ddedf55"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
@ -71,11 +248,34 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
@ -83,6 +283,19 @@ version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
@ -103,6 +316,12 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "simdutf8"
|
||||
version = "0.1.5"
|
||||
@ -126,8 +345,182 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "8.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3fabb953106c3c8eea8306e4393700d7657561cb43122571b172bbfb7c7ba1d"
|
||||
dependencies = [
|
||||
"env_home",
|
||||
"rustix",
|
||||
"winsafe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.6",
|
||||
"windows_aarch64_msvc 0.52.6",
|
||||
"windows_i686_gnu 0.52.6",
|
||||
"windows_i686_gnullvm 0.52.6",
|
||||
"windows_i686_msvc 0.52.6",
|
||||
"windows_x86_64_gnu 0.52.6",
|
||||
"windows_x86_64_gnullvm 0.52.6",
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.53.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.53.0",
|
||||
"windows_aarch64_msvc 0.53.0",
|
||||
"windows_i686_gnu 0.53.0",
|
||||
"windows_i686_gnullvm 0.53.0",
|
||||
"windows_i686_msvc 0.53.0",
|
||||
"windows_x86_64_gnu 0.53.0",
|
||||
"windows_x86_64_gnullvm 0.53.0",
|
||||
"windows_x86_64_msvc 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
||||
|
||||
[[package]]
|
||||
name = "winsafe"
|
||||
version = "0.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
|
||||
|
@ -1,5 +1,10 @@
|
||||
[workspace]
|
||||
members = ["crates/luaffi", "crates/luaffi_impl", "crates/luaify"]
|
||||
members = [
|
||||
"crates/luaffi",
|
||||
"crates/luaffi_impl",
|
||||
"crates/luaify",
|
||||
"crates/luajit",
|
||||
]
|
||||
|
||||
[package]
|
||||
name = "luby"
|
||||
@ -7,3 +12,4 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
luajit = { version = "0.1.0", path = "crates/luajit" }
|
||||
|
24
crates/luajit/Cargo.toml
Normal file
24
crates/luajit/Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "luajit"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[features]
|
||||
default = ["enable-jit", "enable-ffi"]
|
||||
runtime = []
|
||||
enable-jit = []
|
||||
enable-ffi = []
|
||||
|
||||
[dependencies]
|
||||
bitflags = { version = "2.9.1", features = ["std"] }
|
||||
bstr = "1.12.0"
|
||||
luaffi = { version = "0.1.0", path = "../luaffi" }
|
||||
thiserror = "2.0.12"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.71.1"
|
||||
cc = "1.2.26"
|
||||
which = "8.0.0"
|
217
crates/luajit/build.rs
Normal file
217
crates/luajit/build.rs
Normal file
@ -0,0 +1,217 @@
|
||||
use std::{
|
||||
env,
|
||||
fs::{copy, create_dir_all, read_dir, write},
|
||||
io, mem,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
use which::which;
|
||||
|
||||
macro_rules! panic_err {
|
||||
($value:expr) => { $value.unwrap_or_else(|err| panic!("{err}")) };
|
||||
($value:expr, $($arg:expr)+) => { $value.unwrap_or_else(|err| panic!("{}: {err}", format_args!($($arg),+))) };
|
||||
}
|
||||
|
||||
macro_rules! env_name {
|
||||
($($arg:expr),+) => { format!($($arg),+).replace("-", "_").to_uppercase() };
|
||||
}
|
||||
|
||||
macro_rules! env {
|
||||
($($arg:expr),+) => { panic_err!(env::var(env_name!($($arg),+))) };
|
||||
}
|
||||
|
||||
macro_rules! cfg {
|
||||
($($arg:expr),+) => { env!("CARGO_CFG_{}", format_args!($($arg),+)) };
|
||||
}
|
||||
|
||||
macro_rules! feature {
|
||||
($($arg:expr),+) => { env::var_os(env_name!("CARGO_FEATURE_{}", format_args!($($arg),+))).is_some() };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let src_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
let out_path = PathBuf::from(env!("OUT_DIR"));
|
||||
|
||||
panic_err!(
|
||||
copy_recursive(&src_path, &out_path),
|
||||
"failed to copy luajit source (is the Git submodule initialised?)"
|
||||
);
|
||||
|
||||
panic_err!(write(out_path.join(".relver"), get_relver()));
|
||||
println!("cargo::rerun-if-changed={}", src_path.display());
|
||||
|
||||
build_runtime(&out_path.join("src"));
|
||||
build_bindings(&out_path.join("src"));
|
||||
}
|
||||
|
||||
fn get_relver() -> String {
|
||||
let out = panic_err!(
|
||||
Command::new("git")
|
||||
.args(["show", "-s", "--format=%ct"])
|
||||
.output(),
|
||||
"failed to obtain release version (is the Git command available?)"
|
||||
);
|
||||
|
||||
String::from_utf8_lossy(&out.stdout).into()
|
||||
}
|
||||
|
||||
fn copy_recursive(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
|
||||
create_dir_all(dst.as_ref())?;
|
||||
|
||||
for entry in read_dir(src)? {
|
||||
let entry = entry?;
|
||||
if entry.file_name().to_str() == Some(".git") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let path = dst.as_ref().join(entry.file_name());
|
||||
if entry.file_type()?.is_dir() {
|
||||
copy_recursive(entry.path(), path)?;
|
||||
} else {
|
||||
copy(entry.path(), path)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn find_make() -> Command {
|
||||
let name = match parse_target(&env!("HOST")) {
|
||||
(_, _, "freebsd" | "openbsd" | "netbsd" | "dragonfly", _) => "gmake",
|
||||
_ => "make",
|
||||
};
|
||||
|
||||
Command::new(panic_err!(which(name), "failed to find make"))
|
||||
}
|
||||
|
||||
fn find_cc(target: impl AsRef<str>) -> PathBuf {
|
||||
let cc = cc::Build::new().target(target.as_ref()).get_compiler();
|
||||
let path = panic_err!(which(cc.path()), "failed to find cc");
|
||||
path.to_str().unwrap().into()
|
||||
}
|
||||
|
||||
fn parse_target(target: &str) -> (&str, &str, &str, Option<&str>) {
|
||||
let mut i = target.splitn(4, "-");
|
||||
let arch = i.next().unwrap();
|
||||
let vendor = i.next().unwrap();
|
||||
let os = i.next().unwrap();
|
||||
let env = i.next();
|
||||
(arch, vendor, os, env)
|
||||
}
|
||||
|
||||
fn build_runtime(src_path: &Path) {
|
||||
let mut make = find_make();
|
||||
let opt_level = env!("OPT_LEVEL");
|
||||
let debug = opt_level == "0";
|
||||
|
||||
let host = env!("HOST");
|
||||
let host_cc = find_cc(&host).to_str().unwrap().to_owned();
|
||||
let host_ptr_width = 8 * mem::size_of::<usize>();
|
||||
|
||||
let target = env!("TARGET");
|
||||
let target_cc = find_cc(&target).to_str().unwrap().to_owned();
|
||||
// let target_features: HashSet<&str> = HashSet::from_iter(cfg!("target_feature").split(","));
|
||||
let target_ptr_width: usize = cfg!("target_pointer_width").parse().unwrap();
|
||||
|
||||
if target == host {
|
||||
println!("--- begin compile for {target}:");
|
||||
} else {
|
||||
println!("--- begin cross-compile on {host} for {target}:");
|
||||
}
|
||||
|
||||
make.current_dir(&src_path)
|
||||
.env_clear()
|
||||
.arg("-e")
|
||||
.env("PATH", env!("PATH"))
|
||||
.env("MAKEFLAGS", env!("CARGO_MAKEFLAGS"))
|
||||
.env("BUILDMODE", "static");
|
||||
|
||||
let ccopt = vec![format!("-O{opt_level} -fomit-frame-pointer")];
|
||||
|
||||
let mut xcflags = vec![
|
||||
"-DLUAJIT_ENABLE_LUA52COMPAT", // lua 5.2 compatibility
|
||||
"-DLUAJIT_USE_SYSMALLOC", // disable bundled allocator
|
||||
"-DLUAJIT_UNWIND_EXTERNAL -funwind-tables", // use external frame unwinding
|
||||
];
|
||||
|
||||
if debug {
|
||||
make.env("CCDEBUG", "-g"); // generate debug information
|
||||
xcflags.push("-DLUAJIT_USE_GDBJIT"); // gdb support
|
||||
xcflags.push("-DLUA_USE_APICHECK -DLUA_USE_ASSERT"); // enable assertions
|
||||
}
|
||||
|
||||
if !feature!("enable-jit") {
|
||||
xcflags.push("-DLUAJIT_DISABLE_JIT");
|
||||
}
|
||||
|
||||
if !feature!("enable-ffi") {
|
||||
xcflags.push("-DLUAJIT_DISABLE_FFI");
|
||||
}
|
||||
|
||||
match (host_ptr_width, target_ptr_width) {
|
||||
(64, 64) | (32, 32) => make.env("HOST_CC", &host_cc),
|
||||
(64, 32) => make.env("HOST_CC", format!("{} -m32", host_cc)),
|
||||
(n, m) if n != m => panic!("cannot cross-compile on {n}-bit host for {m}-bit target"),
|
||||
(n, _) => panic!("unsupported {n}-bit architecture"),
|
||||
};
|
||||
|
||||
match cfg!("target_os").as_str() {
|
||||
"linux" | "android" => make.env("TARGET_SYS", "Linux"),
|
||||
"windows" => make.env("TARGET_SYS", "Windows"),
|
||||
"macos" => make.env("TARGET_SYS", "Darwin").env(
|
||||
"MACOSX_DEPLOYMENT_TARGET",
|
||||
env::var("MACOSX_DEPLOYMENT_TARGET").as_deref().unwrap_or(
|
||||
match cfg!("target_arch").as_str() {
|
||||
"x86_64" | "x86_64h" => "10.12",
|
||||
"aarch64" | "arm64" | "arm64e" => "11.0",
|
||||
arch => panic!("unsupported MacOS target architecture '{arch}'"),
|
||||
},
|
||||
),
|
||||
),
|
||||
"ios" => make.env("TARGET_SYS", "iOS"),
|
||||
"solaris" => make.env("TARGET_SYS", "SunOS"),
|
||||
_ => make.env("TARGET_SYS", "Other"),
|
||||
};
|
||||
|
||||
if let Some(cross) = target_cc.strip_suffix("gcc") {
|
||||
make.env("CC", "gcc").env("CROSS", cross);
|
||||
} else if let Some(cross) = target_cc.strip_suffix("clang") {
|
||||
make.env("CC", "clang").env("CROSS", cross);
|
||||
} else {
|
||||
let path = Path::new(&target_cc);
|
||||
make.env("CC", path.file_name().unwrap())
|
||||
.env("CROSS", format!("{}/", path.parent().unwrap().display()));
|
||||
}
|
||||
|
||||
if let Some(path) = env::var("RUSTC_LINKER").ok() {
|
||||
make.env("TARGET_LD", panic_err!(which(path), "failed to find ld"));
|
||||
}
|
||||
|
||||
make.env("CCOPT", ccopt.join(" "))
|
||||
.env("XCFLAGS", xcflags.join(" "));
|
||||
|
||||
let status = panic_err!(make.status(), "failed to execute make");
|
||||
(!status.success()).then(|| panic!("failed to compile luajit: {status}: {make:?}"));
|
||||
|
||||
if feature!("runtime") {
|
||||
println!("cargo::rustc-link-search=native={}", src_path.display());
|
||||
println!("cargo::rustc-link-lib=static=luajit");
|
||||
}
|
||||
}
|
||||
|
||||
fn build_bindings(src_path: &Path) {
|
||||
let mut bindgen = bindgen::builder()
|
||||
.clang_arg(format!("--target={}", env!("TARGET")))
|
||||
.allowlist_item(r"^(lua|LUA).*_.+$")
|
||||
.formatter(bindgen::Formatter::None)
|
||||
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
|
||||
.generate_cstr(true);
|
||||
|
||||
for header in ["lua.h", "lualib.h", "lauxlib.h", "luaconf.h", "luajit.h"] {
|
||||
bindgen = bindgen.header(src_path.join(header).to_str().unwrap());
|
||||
}
|
||||
|
||||
let path = src_path.join("bindgen.rs");
|
||||
panic_err!(panic_err!(bindgen.generate(), "failed to generate bindings").write_to_file(&path));
|
||||
println!("cargo::rustc-env=LJ_BINDINGS={}", path.display());
|
||||
}
|
1138
crates/luajit/lib.rs
Normal file
1138
crates/luajit/lib.rs
Normal file
File diff suppressed because it is too large
Load Diff
1
crates/luajit/src
Submodule
1
crates/luajit/src
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit f9140a622a0c44a99efb391cc1c2358bc8098ab7
|
Loading…
x
Reference in New Issue
Block a user