Compare commits

..

42 commits

Author SHA1 Message Date
b2a98a39ce
luajit2-sys: Apply clippy lints
Some checks failed
build/msvc Build for the target platform: msvc
build/linux Build for the target platform: linux
lint/clippy Checking for common mistakes and opportunities for code improvement
2025-07-02 13:31:19 +02:00
3bf4b7f0d1
luajit2-sys: Move dependencies to workspace 2025-07-01 16:17:05 +02:00
7500f90105
luajit2-sys: Remove unused files
Stuff that isn't needed anymore after the merge into the workspace.
2025-07-01 16:15:56 +02:00
a922868e64 Add 'lib/luajit2-sys/' from commit '6d94a4dd2c'
git-subtree-dir: lib/luajit2-sys
git-subtree-mainline: b42b4f01d2
git-subtree-split: 6d94a4dd2c
2025-07-01 15:58:35 +02:00
b42b4f01d2
Prepare to absorb luajit2-sys submodule
I had to pin the version of the LuaJIT library to a specific commit,
and have reworked the build scripts heavily to work with the XWin setup,
sacrificing the more flexible approach that existed before.
As such it is heavily customized to the specific usage here. There is no
reason to assume that it will be reconciled with the main project in the
future.
2025-07-01 15:57:15 +02:00
1326222eb0
Improve Renovate config 2025-07-01 15:57:11 +02:00
d61ffdfef2
Apply clippy lints 2025-07-01 15:57:10 +02:00
6d94a4dd2c
Update bindgen 2024-08-21 14:33:15 +02:00
5d1a075742
Merge branch 'feat/bitsquid'
* feat/bitsquid:
  Update bindgen
2024-05-15 21:57:23 +02:00
c7ff0b7a90
Update bindgen 2024-05-15 21:57:04 +02:00
19120166f9
Merge branch 'feat/bitsquid'
* feat/bitsquid:
  fix: Fix LuaJIT on Windows
  fix: Disable 64bit GC
2023-11-09 19:50:59 +01:00
24da35e631
fix: Fix LuaJIT on Windows
It turned out that with disabling GC64, LuaJIT would immediately
overflow the stack when opening a Lua state. For now, this reverts to
a version from 2019 that works, but I highly doubt that LuaJIT woould
have been broken on Windows for years.

I'll have to investigate, or rather trial-and-error further.
2023-04-09 12:21:29 +02:00
7395cf0d53
fix: Disable 64bit GC 2023-04-06 11:16:14 +02:00
11c4eddaa4
chore: Fix lcippy warning 2023-03-28 20:49:15 +02:00
18797c4d2a
fix: Fix linking on Linux 2023-03-23 15:32:00 +01:00
9ab05ce18c
feat: Implement cross compilation for MSVC toolchain 2023-03-23 13:35:56 +01:00
206f7884e3
Move bindgen to build script 2023-03-21 11:55:46 +01:00
089acdbc28
feat: Implement MSVC cross compilation 2023-03-21 11:04:21 +01:00
86757089b4
chore: Update LuaJIT 2023-03-02 15:11:50 +01:00
Aaron Loucks
2aa8038854 Update README 2020-01-19 16:31:41 -05:00
Aaron Loucks
f308e7ba66 Version 0.0.2 2020-01-19 16:24:01 -05:00
Aaron Loucks
972f1022ee Update README 2020-01-19 15:31:07 -05:00
Aaron Loucks
32f67222d7 Add weekly build to CI 2020-01-19 15:29:09 -05:00
Aaron Loucks
56c586ecbf Update README 2020-01-19 15:25:07 -05:00
Aaron Loucks
18c5d88e65 Cleanup build.rs
Set the following environment variables. The luajit lib name
varies by platform (lua51 on msvc and luajit everywhere else).

- DEP_LUAJIT_INCLUDE
- DEP_LUAJIT_LIB_NAME
2020-01-19 15:15:55 -05:00
Aaron Loucks
727831d413 Add description 2020-01-19 01:48:17 -05:00
Aaron Loucks
b00970789a Add license 2020-01-19 01:38:51 -05:00
Aaron Loucks
a705ff7d25 Rename to luajit2-sys 2020-01-19 01:31:24 -05:00
Aaron Loucks
bb75b4a2fd Add README 2020-01-19 01:14:53 -05:00
Aaron Loucks
a2b17d749c The bash task in azure seems to find powershells find 2020-01-19 01:04:51 -05:00
Aaron Loucks
e0baa55c2c Disable i686 and mingw tests 2019-08-18 21:55:33 -04:00
Aaron Loucks
6a3c526cfb Add link args for x86_64-apple-darwin 2019-08-15 22:27:12 -04:00
Aaron Loucks
6e5676b889 Disable MACOSX_DEPLOYMENT_TARGET 2019-08-15 21:46:56 -04:00
Aaron Loucks
2b9a03d961 Set BUILDMODE=static and -fPIC in Makefile 2019-08-15 21:36:23 -04:00
Aaron Loucks
4cd8b358d7 Set BUILDMODE=static in Makefile 2019-08-15 21:04:58 -04:00
Aaron Loucks
7c7cb2b56d Checkout submodules in azure-pipelines 2019-08-15 20:28:27 -04:00
Aaron Loucks
64b97a3b19 Debug pipeline 2019-08-15 20:09:27 -04:00
Aaron Loucks
db8d666c8a Fix path separator 2019-08-15 19:32:01 -04:00
Aaron Loucks
dd2810e855 Add azure-pipelines config 2019-08-15 19:31:31 -04:00
Aaron Loucks
f144a4ff6a Add build script and generated ffi 2019-08-15 19:17:23 -04:00
Aaron Loucks
50f832a25d Adding luajit submodule 2019-08-13 18:11:24 -04:00
Aaron Loucks
cdb0423401 Initial commit 2019-08-13 18:03:48 -04:00
11 changed files with 643 additions and 13 deletions

10
.gitmodules vendored
View file

@ -1,11 +1,11 @@
[submodule "lib/luajit2-sys"]
path = lib/luajit2-sys
url = https://github.com/sclu1034/luajit2-sys.git
[submodule "lib/color-eyre"]
path = lib/color-eyre
url = https://github.com/sclu1034/color-eyre.git
branch = "fork"
branch = "fork"
[submodule "lib/ansi-parser"]
path = lib/ansi-parser
url = https://gitlab.com/lschwiderski/ansi-parser.git
branch = "issue/outdated-nom"
branch = "issue/outdated-nom"
[submodule "lib/luajit2-sys/luajit"]
path = lib/luajit2-sys/luajit
url = https://github.com/LuaJIT/LuaJIT.git

12
Cargo.lock generated
View file

@ -379,9 +379,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.13"
version = "1.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
dependencies = [
"jobserver",
"libc",
@ -2173,9 +2173,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.172"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]]
name = "libloading"
@ -2184,7 +2184,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]
[[package]]
@ -4581,7 +4581,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]
[[package]]

View file

@ -16,8 +16,10 @@ ansi-parser = "0.9.1"
ansi_term = "0.12.1"
async-recursion = "1.0.5"
bincode = "2.0.0"
bindgen = "0.70.1"
bitflags = "2.5.0"
byteorder = "1.4.3"
cc = "1.2.27"
clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "string", "unicode"] }
cli-table = { version = "0.5.0", default-features = false, features = ["derive"] }
color-eyre = { path = "lib/color-eyre" }
@ -28,11 +30,13 @@ druid = { version = "0.8", features = ["im", "serde", "image", "png", "jpeg", "b
druid-widget-nursery = "0.1"
dtmt-shared = { path = "lib/dtmt-shared" }
fastrand = "2.1.0"
fs_extra = "1.1.0"
futures = "0.3.25"
futures-util = "0.3.24"
glob = "0.3.0"
interprocess = "2.1.0"
lazy_static = "1.4.0"
libc = "0.2.174"
luajit2-sys = { path = "lib/luajit2-sys" }
minijinja = { version = "2.0.1", default-features = false, features = ["serde"] }
nanorand = "0.8.0"

View file

@ -1,6 +1,5 @@
#![feature(io_error_more)]
#![feature(let_chains)]
#![feature(result_flattening)]
#![feature(test)]
#![windows_subsystem = "console"]

@ -1 +0,0 @@
Subproject commit 6d94a4dd2c296bf1f044ee4c70fb10dca4c1c241

View file

@ -0,0 +1,20 @@
[package]
name = "luajit2-sys"
version = "0.0.2"
description = "LuaJIT-2.1 FFI Bindings"
authors = ["Aaron Loucks <aloucks@cofront.net>"]
edition = "2021"
keywords = ["lua", "luajit", "script"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/aloucks/luajit2-sys"
documentation = "https://docs.rs/luajit2-sys"
links = "luajit"
[dependencies]
libc = { workspace = true }
[build-dependencies]
bindgen = { workspace = true }
cc = { workspace = true }
fs_extra = { workspace = true }

View file

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/LICENSE-2.0
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

216
lib/luajit2-sys/build.rs Normal file
View file

@ -0,0 +1,216 @@
use cc::Build;
use fs_extra::dir;
use fs_extra::dir::CopyOptions;
use std::env;
use std::path::PathBuf;
use std::process::{Command, Stdio};
const LIB_NAME: &str = "luajit";
const LUAJIT_HEADERS: [&str; 4] = ["lua.h", "lualib.h", "lauxlib.h", "luajit.h"];
const LUAJIT_SRC: [&str; 65] = [
// LJCORE_O
// The MSVC toolchain cannot compile this assembler file,
// as it contains GNU-specific directives
// "lj_vm.S",
"lj_gc.c",
"lj_err.c",
"lj_char.c",
"lj_bc.c",
"lj_obj.c",
"lj_buf.c",
"lj_str.c",
"lj_tab.c",
"lj_func.c",
"lj_udata.c",
"lj_meta.c",
"lj_debug.c",
"lj_state.c",
"lj_dispatch.c",
"lj_vmevent.c",
"lj_vmmath.c",
"lj_strscan.c",
"lj_strfmt.c",
"lj_strfmt_num.c",
"lj_api.c",
"lj_profile.c",
"lj_lex.c",
"lj_parse.c",
"lj_bcread.c",
"lj_bcwrite.c",
"lj_load.c",
"lj_ir.c",
"lj_opt_mem.c",
"lj_opt_fold.c",
"lj_opt_narrow.c",
"lj_opt_dce.c",
"lj_opt_loop.c",
"lj_opt_split.c",
"lj_opt_sink.c",
"lj_mcode.c",
"lj_snap.c",
"lj_record.c",
"lj_crecord.c",
"lj_ffrecord.c",
"lj_asm.c",
"lj_trace.c",
"lj_gdbjit.c",
"lj_ctype.c",
"lj_cdata.c",
"lj_cconv.c",
"lj_ccall.c",
"lj_ccallback.c",
"lj_carith.c",
"lj_clib.c",
"lj_cparse.c",
"lj_lib.c",
"lj_alloc.c",
// LJLIB_O
"lib_aux.c",
"lib_base.c",
"lib_math.c",
"lib_bit.c",
"lib_string.c",
"lib_table.c",
"lib_io.c",
"lib_os.c",
"lib_package.c",
"lib_debug.c",
"lib_jit.c",
"lib_ffi.c",
"lib_init.c",
];
fn build_gcc(src_dir: &str) {
let mut buildcmd = Command::new("make");
buildcmd.current_dir(src_dir);
buildcmd.stderr(Stdio::inherit());
buildcmd.arg("--no-silent");
// We do need to cross-compile even here, so that `lj_vm.o` is created
// for the correct architecture.
if env::var("CARGO_CFG_WINDOWS").is_ok() {
buildcmd.arg("TARGET_SYS=Windows");
buildcmd.arg("CROSS=x86_64-w64-mingw32-");
}
if cfg!(target_pointer_width = "32") {
buildcmd.arg("HOST_CC='gcc -m32'");
buildcmd.arg("-e");
} else {
buildcmd.arg("HOST_CC='gcc'");
}
let mut child = buildcmd.spawn().expect("failed to run make");
if !child
.wait()
.map(|status| status.success())
.map_err(|_| false)
.unwrap_or(false)
{
panic!("Failed to build luajit");
}
}
fn build_msvc(src_dir: &str, out_dir: &str) {
let mut cc = Build::new();
// cc can't handle many of the `clang-dl`-specific flags, so
// we need to port them manually from a `make -n` run.
cc.out_dir(out_dir)
// `llvm-as` (which the clang-based toolchain for MSVC would use to compile `lj_vm.S`
// assembler) doesn't support some of the GNU-specific directives.
// However, the previous host-targeted compilation already created the
// object, so we simply link that.
.object(format!("{src_dir}/lj_vm.o"))
.define("_FILE_OFFSET_BITS", "64")
.define("_LARGEFILE_SOURCE", None)
.define("LUA_MULTILIB", "\"lib\"")
.define("LUAJIT_UNWIND_EXTERNAL", None)
.flag("-fcolor-diagnostics")
// Disable warnings
.flag("/W0")
.flag("/U _FORTIFY_SOURCE")
// Link statically
.flag("/MT")
// Omit frame pointers
.flag("/Oy");
for f in LUAJIT_SRC {
cc.file(format!("{src_dir}/{f}"));
}
cc.compile(LIB_NAME);
}
fn main() {
let luajit_dir = format!("{}/luajit", env!("CARGO_MANIFEST_DIR"));
let out_dir = env::var("OUT_DIR").unwrap();
let src_dir = format!("{out_dir}/luajit/src");
dbg!(&luajit_dir);
dbg!(&out_dir);
dbg!(&src_dir);
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
dir::copy(&luajit_dir, &out_dir, &copy_options).expect("Failed to copy LuaJIT source");
// The first run builds with and for the host architecture.
// This also creates all the tools and generated sources that a compilation needs.
build_gcc(&src_dir);
// Then, for cross-compilation, we can utilize those generated
// sources to re-compile just the library.
if env::var("CARGO_CFG_WINDOWS").is_ok() {
build_msvc(&src_dir, &out_dir);
println!("cargo:rustc-link-search={out_dir}");
} else {
println!("cargo:rustc-link-search=native={src_dir}");
}
println!("cargo:lib-name={LIB_NAME}");
println!("cargo:include={src_dir}");
println!("cargo:rustc-link-lib=static={LIB_NAME}");
let mut bindings = bindgen::Builder::default();
for header in LUAJIT_HEADERS {
println!("cargo:rerun-if-changed={luajit_dir}/src/{header}");
bindings = bindings.header(format!("{luajit_dir}/src/{header}"));
}
let bindings = bindings
.allowlist_var("LUA.*")
.allowlist_var("LUAJIT.*")
.allowlist_type("lua_.*")
.allowlist_type("luaL_.*")
.allowlist_function("lua_.*")
.allowlist_function("luaL_.*")
.allowlist_function("luaJIT.*")
.ctypes_prefix("libc")
.impl_debug(true)
.use_core()
.detect_include_paths(true)
.formatter(bindgen::Formatter::Rustfmt)
.sort_semantically(true)
.merge_extern_blocks(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
let bindings = if env::var("CARGO_CFG_WINDOWS").is_ok() {
bindings
.clang_arg("-I/xwin/sdk/include/ucrt")
.clang_arg("-I/xwin/sdk/include/um")
.clang_arg("-I/xwin/sdk/include/shared")
.clang_arg("-I/xwin/crt/include")
.generate()
.expect("Failed to generate bindings")
} else {
bindings.generate().expect("Failed to generate bindings")
};
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Failed to write bindings");
}

@ -0,0 +1 @@
Subproject commit 70f4b15ee45a6137fe6b48b941faea79d72f7159

167
lib/luajit2-sys/src/lib.rs Normal file
View file

@ -0,0 +1,167 @@
#![no_std]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(clippy::deprecated_semver)]
#![allow(clippy::missing_safety_doc)]
//! # LuaJIT 2.1
//!
//! <http://luajit.org>
//!
//! <http://www.lua.org/manual/5.1/manual.html>
//!
//! ## Performance considerations
//!
//! The _Not Yet Implemented_ guide documents which language features will be JIT compiled
//! into native machine code.
//!
//! <http://wiki.luajit.org/NYI>
mod ffi {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
pub use ffi::*;
use core::ptr;
// These are defined as macros
/// <https://www.lua.org/manual/5.1/manual.html#lua_pop>
#[inline]
pub unsafe fn lua_pop(L: *mut lua_State, idx: libc::c_int) {
lua_settop(L, -(idx) - 1)
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_newtable>
#[inline]
pub unsafe fn lua_newtable(L: *mut lua_State) {
lua_createtable(L, 0, 0)
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_register>
#[inline]
pub unsafe fn lua_register(L: *mut lua_State, name: *const libc::c_char, f: lua_CFunction) {
lua_pushcfunction(L, f);
lua_setglobal(L, name);
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_pushcfunction>
#[inline]
pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) {
lua_pushcclosure(L, f, 0);
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_strlen>
#[inline]
pub unsafe fn lua_strlen(L: *mut lua_State, idx: libc::c_int) -> usize {
lua_objlen(L, idx)
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isfunction>
#[inline]
pub unsafe fn lua_isfunction(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TFUNCTION as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_istable>
#[inline]
pub unsafe fn lua_istable(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TTABLE as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_islightuserdata>
#[inline]
pub unsafe fn lua_islightuserdata(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TLIGHTUSERDATA as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isnil>
#[inline]
pub unsafe fn lua_isnil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TNIL as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isboolean>
#[inline]
pub unsafe fn lua_isboolean(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TBOOLEAN as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isthread>
#[inline]
pub unsafe fn lua_isthread(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TTHREAD as i32) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isnone>
#[inline]
pub unsafe fn lua_isnone(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) == LUA_TNONE) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_isnoneornil>
#[inline]
pub unsafe fn lua_isnoneornil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int {
(lua_type(L, idx) <= 0) as i32
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_pushliteral>
#[inline]
pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &str) {
lua_pushlstring(L, s.as_ptr() as _, s.len() as _);
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_setglobal>
#[inline]
pub unsafe fn lua_setglobal(L: *mut lua_State, k: *const libc::c_char) {
lua_setfield(L, LUA_GLOBALSINDEX, k);
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_getglobal>
#[inline]
pub unsafe fn lua_getglobal(L: *mut lua_State, k: *const libc::c_char) {
lua_getfield(L, LUA_GLOBALSINDEX, k)
}
/// <https://www.lua.org/manual/5.1/manual.html#lua_tostring>
#[inline]
pub unsafe fn lua_tostring(L: *mut lua_State, idx: libc::c_int) -> *const libc::c_char {
lua_tolstring(L, idx, ptr::null_mut())
}
// Additional compatibility items that are defined as macros
/// `luaL_newstate()`
#[inline]
#[deprecated(since = "Lua 5.1", note = "replace with `luaL_newstate()`")]
pub unsafe fn lua_open() -> *mut lua_State {
luaL_newstate()
}
/// `lua_pushvalue(L, LUA_REGISTRYINDEX)`
#[inline]
#[deprecated(
since = "Lua 5.1",
note = "replace with `lua_pushvalue(L, LUA_REGISTRYINDEX)`"
)]
pub unsafe fn lua_getregistry(L: *mut lua_State) {
lua_pushvalue(L, LUA_REGISTRYINDEX)
}
/// `lua_gc(L, LUA_GCCOUNT as _, 0)`
#[inline]
#[deprecated(
since = "Lua 5.1",
note = "replace with `lua_gc(L, LUA_GCCOUNT as _, 0)`"
)]
pub unsafe fn lua_getgccount(L: *mut lua_State) -> libc::c_int {
lua_gc(L, LUA_GCCOUNT as _, 0)
}
/// `lua_Reader`
#[deprecated(since = "Lua 5.1", note = "replace with `lua_Reader`")]
pub type lua_Chunkreader = lua_Reader;
/// `lua_Writer`
#[deprecated(since = "Lua 5.1", note = "replace with `lua_Writer`")]
pub type lua_Chunkwriter = lua_Writer;