summaryrefslogtreecommitdiff
path: root/zjit/bindgen
diff options
context:
space:
mode:
Diffstat (limited to 'zjit/bindgen')
-rw-r--r--zjit/bindgen/Cargo.lock392
-rw-r--r--zjit/bindgen/Cargo.toml12
-rw-r--r--zjit/bindgen/src/main.rs470
3 files changed, 874 insertions, 0 deletions
diff --git a/zjit/bindgen/Cargo.lock b/zjit/bindgen/Cargo.lock
new file mode 100644
index 0000000000..66b9bf5a20
--- /dev/null
+++ b/zjit/bindgen/Cargo.lock
@@ -0,0 +1,392 @@
+# This file is automatically @generated by Cargo.
+# 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 = "anstream"
+version = "0.6.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
+
+[[package]]
+name = "anstyle-parse"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
+dependencies = [
+ "anstyle",
+ "windows-sys",
+]
+
+[[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.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
+
+[[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.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[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 = "colorchoice"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
+
+[[package]]
+name = "either"
+version = "1.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
+
+[[package]]
+name = "env_filter"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
+dependencies = [
+ "log",
+ "regex",
+]
+
+[[package]]
+name = "env_logger"
+version = "0.11.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "env_filter",
+ "humantime",
+ "log",
+]
+
+[[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
+[[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
+[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
+
+[[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.161"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
+
+[[package]]
+name = "libloading"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
+dependencies = [
+ "cfg-if",
+ "windows-targets",
+]
+
+[[package]]
+name = "log"
+version = "0.4.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
+
+[[package]]
+name = "memchr"
+version = "2.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
+
+[[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.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba"
+dependencies = [
+ "proc-macro2",
+ "syn",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.88"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "regex"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3"
+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"
+version = "2.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
+
+[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
+[[package]]
+name = "syn"
+version = "2.0.79"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
+
+[[package]]
+name = "utf8parse"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+
+[[package]]
+name = "windows-sys"
+version = "0.52.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[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_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+
+[[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_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+
+[[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_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+
+[[package]]
+name = "zjit-bindgen"
+version = "0.1.0"
+dependencies = [
+ "bindgen",
+ "env_logger",
+]
diff --git a/zjit/bindgen/Cargo.toml b/zjit/bindgen/Cargo.toml
new file mode 100644
index 0000000000..2f20f18016
--- /dev/null
+++ b/zjit/bindgen/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "zjit-bindgen"
+version = "0.1.0"
+edition = "2024"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+bindgen = "0.71.1"
+env_logger = "0.11.5"
+
+[workspace]
diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs
new file mode 100644
index 0000000000..d015f975de
--- /dev/null
+++ b/zjit/bindgen/src/main.rs
@@ -0,0 +1,470 @@
+//! See https://docs.rs/bindgen/0.59.2/bindgen/struct.Builder.html
+//! This is the binding generation tool that the ZJIT cruby module talks about.
+//! More docs later once we have more experience with this, for now, check
+//! the output to make sure it looks reasonable and allowlist things you want
+//! to use in Rust.
+
+use std::env;
+use std::path::PathBuf;
+
+const SRC_ROOT_ENV: &str = "ZJIT_SRC_ROOT_PATH";
+const JIT_NAME: &str = "BINDGEN_JIT_NAME";
+
+fn main() {
+ // Path to repo is a required input for supporting running `configure`
+ // in a directory away from the code.
+ let src_root = env::var(SRC_ROOT_ENV).expect(
+ format!(
+ r#"The "{}" env var must be a path to the root of the Ruby repo"#,
+ SRC_ROOT_ENV
+ )
+ .as_ref(),
+ );
+ let src_root = PathBuf::from(src_root);
+
+ let jit_name = env::var(JIT_NAME).expect(JIT_NAME);
+ let c_file = format!("{}.c", jit_name);
+
+ assert!(
+ src_root.is_dir(),
+ "{} must be set to a path to a directory",
+ SRC_ROOT_ENV
+ );
+
+ // We want Bindgen warnings printed to console
+ env_logger::init();
+
+ // Remove this flag so rust-bindgen generates bindings
+ // that are internal functions not public in libruby
+ let filtered_clang_args = env::args().filter(|arg| arg != "-fvisibility=hidden");
+
+ let bindings = bindgen::builder()
+ .clang_args(filtered_clang_args)
+ .header("encindex.h")
+ .header("internal.h")
+ .header("internal/object.h")
+ .header("internal/re.h")
+ .header("include/ruby/ruby.h")
+ .header("shape.h")
+ .header("vm_core.h")
+ .header("vm_callinfo.h")
+
+ // Our C file for glue code
+ .header(src_root.join(c_file).to_str().unwrap())
+ .header(src_root.join("jit.c").to_str().unwrap())
+
+ // Don't want to copy over C comment
+ .generate_comments(false)
+
+ // Makes the output more compact
+ .merge_extern_blocks(true)
+
+ // Don't want layout tests as they are platform dependent
+ .layout_tests(false)
+
+ // Block for stability since output is different on Darwin and Linux
+ .blocklist_type("size_t")
+ .blocklist_type("fpos_t")
+
+ // Import YARV bytecode instruction constants
+ .allowlist_type("ruby_vminsn_type")
+
+ // JITFrame struct defined in zjit.h, imported into Rust via bindgen
+ .allowlist_type("zjit_jit_frame")
+
+ .allowlist_type("ruby_special_consts")
+ .allowlist_function("rb_utf8_str_new")
+ .allowlist_function("rb_str_buf_append")
+ .allowlist_function("rb_str_dup")
+ .allowlist_function("rb_str_getbyte")
+ .allowlist_type("ruby_preserved_encindex")
+ .allowlist_function("rb_class2name")
+
+ // This struct is public to Ruby C extensions
+ .allowlist_type("RBasic")
+
+ .allowlist_type("ruby_rstring_flags")
+ .allowlist_type("rbimpl_typeddata_flags")
+
+ // This function prints info about a value and is useful for debugging
+ .allowlist_function("rb_raw_obj_info")
+
+ .allowlist_function("ruby_init")
+ .allowlist_function("ruby_init_stack")
+ .allowlist_function("ruby_options")
+ .allowlist_function("ruby_executable_node")
+ .allowlist_function("rb_funcallv")
+ .allowlist_function("rb_protect")
+ .allowlist_function("rb_zjit_profile_disable")
+
+ // For crashing
+ .allowlist_function("rb_bug")
+
+ .allowlist_function("rb_obj_shape_id")
+ .allowlist_function("rb_shape_id_offset")
+ .allowlist_function("rb_shape_get_iv_index")
+ .allowlist_function("rb_shape_transition_add_ivar_no_warnings")
+ .allowlist_function("rb_jit_shape_capacity")
+ .allowlist_var("rb_invalid_shape_id")
+ .allowlist_type("shape_id_fl_type")
+ .allowlist_var("VM_KW_SPECIFIED_BITS_MAX")
+ .allowlist_var("SHAPE_ID_NUM_BITS")
+ .allowlist_function("rb_obj_is_kind_of")
+ .allowlist_function("rb_obj_frozen_p")
+ .allowlist_function("rb_class_inherited_p")
+ .allowlist_function("rb_class_real")
+ .allowlist_type("ruby_encoding_consts")
+ .allowlist_function("rb_hash_new")
+ .allowlist_function("rb_hash_new_with_size")
+ .allowlist_function("rb_hash_resurrect")
+ .allowlist_function("rb_hash_stlike_foreach")
+ .allowlist_function("rb_to_hash_type")
+ .allowlist_type("st_retval")
+ .allowlist_function("rb_hash_aset")
+ .allowlist_function("rb_hash_aref")
+ .allowlist_function("rb_hash_bulk_insert")
+ .allowlist_function("rb_hash_new_with_bulk_insert")
+ .allowlist_function("rb_hash_stlike_lookup")
+ .allowlist_function("rb_ary_new_capa")
+ .allowlist_function("rb_ary_store")
+ .allowlist_function("rb_ary_resurrect")
+ .allowlist_function("rb_ary_cat")
+ .allowlist_function("rb_ary_concat")
+ .allowlist_function("rb_ary_clear")
+ .allowlist_function("rb_ary_dup")
+ .allowlist_function("rb_ary_push")
+ .allowlist_function("rb_ary_pop")
+ .allowlist_function("rb_ary_unshift_m")
+ .allowlist_function("rb_ec_ary_new_from_values")
+ .allowlist_function("rb_ary_tmp_new_from_values")
+ .allowlist_function("rb_ary_entry")
+ .allowlist_function("rb_class_attached_object")
+ .allowlist_function("rb_singleton_class")
+ .allowlist_function("rb_define_class")
+ .allowlist_function("rb_class_get_superclass")
+ .allowlist_function("rb_gc_disable")
+ .allowlist_function("rb_gc_enable")
+ .allowlist_function("rb_gc_mark")
+ .allowlist_function("rb_gc_mark_movable")
+ .allowlist_function("rb_gc_location")
+ .allowlist_function("rb_gc_writebarrier")
+ .allowlist_function("rb_gc_writebarrier_remember")
+ .allowlist_function("rb_gc_register_mark_object")
+
+ // VALUE variables for Ruby class objects
+ .allowlist_var("rb_cBasicObject")
+ .allowlist_var("rb_cObject")
+ .allowlist_var("rb_cModule")
+ .allowlist_var("rb_cNilClass")
+ .allowlist_var("rb_cTrueClass")
+ .allowlist_var("rb_cFalseClass")
+ .allowlist_var("rb_cInteger")
+ .allowlist_var("rb_cIO")
+ .allowlist_var("rb_cSymbol")
+ .allowlist_var("rb_cFloat")
+ .allowlist_var("rb_cNumeric")
+ .allowlist_var("rb_cRange")
+ .allowlist_var("rb_cString")
+ .allowlist_var("rb_cThread")
+ .allowlist_var("rb_cArray")
+ .allowlist_var("rb_cHash")
+ .allowlist_var("rb_cSet")
+ .allowlist_var("rb_cClass")
+ .allowlist_var("rb_cRegexp")
+ .allowlist_var("rb_cISeq")
+ .allowlist_var("rb_cRubyVM")
+ .allowlist_function("rb_const_get")
+
+ .allowlist_type("ruby_fl_type")
+ .allowlist_type("ruby_fl_ushift")
+ .allowlist_type("ruby_robject_flags")
+ .allowlist_type("ruby_rarray_flags")
+ .allowlist_type("ruby_rarray_consts")
+ .allowlist_type("ruby_rmodule_flags")
+ .allowlist_var("rb_mKernel")
+ .allowlist_type("vm_call_flag_bits")
+ .allowlist_type("rb_call_data")
+ .blocklist_type("rb_callcache.*") // Not used yet - opaque to make it easy to import rb_call_data
+ .opaque_type("rb_callcache.*")
+ .allowlist_type("rb_callinfo")
+ .allowlist_var("VM_ENV_DATA_INDEX_ME_CREF")
+ .allowlist_var("rb_block_param_proxy")
+ .allowlist_function("rb_range_new")
+ .allowlist_function("rb_intern")
+ .allowlist_function("rb_intern2")
+ .allowlist_function("rb_id2sym")
+ .allowlist_function("rb_sym2id")
+ .allowlist_function("rb_str_intern")
+ .allowlist_function("rb_id2str")
+ .allowlist_function("rb_sym2str")
+ .allowlist_function("rb_fix_aref")
+ .allowlist_function("rb_float_plus")
+ .allowlist_function("rb_float_minus")
+ .allowlist_function("rb_float_mul")
+ .allowlist_function("rb_float_div")
+ .allowlist_function("rb_flo_to_i")
+ .allowlist_type("ruby_rstring_private_flags")
+ .allowlist_function("rb_ec_str_resurrect")
+ .allowlist_function("rb_str_concat_literals")
+ .allowlist_function("rb_obj_as_string_result")
+ .allowlist_function("rb_str_byte_substr")
+ .allowlist_function("rb_str_substr_two_fixnums")
+ .allowlist_function("rb_backref_get")
+ .allowlist_function("rb_reg_last_match")
+ .allowlist_function("rb_reg_match_pre")
+ .allowlist_function("rb_reg_match_post")
+ .allowlist_function("rb_reg_match_last")
+ .allowlist_function("rb_reg_nth_match")
+ .allowlist_function("rb_reg_new_from_values")
+ .allowlist_var("ARG_ENCODING_FIXED")
+ .allowlist_var("ARG_ENCODING_NONE")
+ .allowlist_var("ONIG_OPTION_IGNORECASE")
+ .allowlist_var("ONIG_OPTION_EXTEND")
+ .allowlist_var("ONIG_OPTION_MULTILINE")
+
+ // `ruby_value_type` is a C enum and this stops it from
+ // prefixing all the members with the name of the type
+ .prepend_enum_name(false)
+ .translate_enum_integer_types(true) // so we get fixed width Rust types for members
+ .allowlist_type("ruby_value_type") // really old C extension API
+
+ .allowlist_type("ruby_rhash_flags") // really old C extension API
+ .allowlist_type("rb_method_visibility_t")
+ .allowlist_type("rb_method_type_t")
+ .allowlist_type("method_optimized_type")
+ .allowlist_type("rb_callable_method_entry_t")
+ .allowlist_type("rb_callable_method_entry_struct")
+ .allowlist_function("rb_method_entry_at")
+ .allowlist_type("rb_method_entry_t")
+ .blocklist_type("rb_method_cfunc_t")
+ .blocklist_type("rb_method_definition_.*") // Large struct with a bitfield and union of many types - don't import (yet?)
+ .opaque_type("rb_method_definition_.*")
+ .allowlist_function("rb_float_new")
+ .allowlist_var("rb_mRubyVMFrozenCore")
+ .allowlist_var("VM_BLOCK_HANDLER_NONE")
+ .allowlist_type("vm_frame_env_flags")
+ .allowlist_type("rb_seq_param_keyword_struct")
+ .allowlist_type("rb_callinfo_kwarg")
+ .allowlist_type("ruby_basic_operators")
+ .allowlist_var(".*_REDEFINED_OP_FLAG")
+ .allowlist_type("rb_num_t")
+ .allowlist_function("rb_callable_method_entry")
+ .allowlist_function("rb_callable_method_entry_or_negative")
+ .allowlist_function("rb_vm_frame_method_entry")
+ .allowlist_type("IVC") // pointer to iseq_inline_iv_cache_entry
+ .allowlist_type("IC") // pointer to iseq_inline_constant_cache
+ .allowlist_type("iseq_inline_constant_cache_entry")
+ .blocklist_type("rb_cref_t") // don't need this directly, opaqued to allow IC import
+ .opaque_type("rb_cref_t")
+ .allowlist_type("iseq_inline_iv_cache_entry")
+ .allowlist_type("ICVARC") // pointer to iseq_inline_cvar_cache_entry
+ .allowlist_type("iseq_inline_cvar_cache_entry")
+ .blocklist_type("rb_execution_context_.*") // Large struct with various-type fields and an ifdef, so we don't import
+ .opaque_type("rb_execution_context_.*")
+ .allowlist_type("rb_control_frame_struct")
+ .allowlist_function("rb_vm_bh_to_procval")
+ .allowlist_function("rb_vm_env_write")
+ .allowlist_function("rb_vm_ep_local_ep")
+ .allowlist_type("vm_special_object_type")
+ .allowlist_var("VM_ENV_DATA_INDEX_SPECVAL")
+ .allowlist_var("VM_ENV_DATA_INDEX_FLAGS")
+ .allowlist_var("VM_ENV_DATA_SIZE")
+ .allowlist_function("rb_iseq_path")
+ .allowlist_type("rb_builtin_attr")
+ .allowlist_type("ruby_tag_type")
+ .allowlist_type("ruby_vm_throw_flags")
+ .allowlist_type("vm_check_match_type")
+ .allowlist_type("vm_opt_newarray_send_type")
+ .allowlist_type("rb_iseq_type")
+ .allowlist_type("rb_event_flag_t")
+ .allowlist_function("rb_object_shape_count")
+ .allowlist_function("rb_iseq_(get|set)_zjit_payload")
+ .allowlist_function("rb_iseq_pc_at_idx")
+ .allowlist_function("rb_iseq_opcode_at_pc")
+ .allowlist_function("rb_iseq_bare_opcode_at_pc")
+ .allowlist_function("rb_jit_reserve_addr_space")
+ .allowlist_function("rb_jit_mark_writable")
+ .allowlist_function("rb_jit_mark_executable")
+ .allowlist_function("rb_jit_mark_unused")
+ .allowlist_function("rb_jit_get_page_size")
+ .allowlist_function("rb_jit_array_len")
+ .allowlist_function("rb_jit_fix_div_fix")
+ .allowlist_function("rb_jit_iseq_builtin_attrs")
+ .allowlist_function("rb_jit_str_concat_codepoint")
+ .allowlist_function("rb_zjit_iseq_inspect")
+ .allowlist_function("rb_zjit_iseq_insn_set")
+ .allowlist_function("rb_zjit_local_id")
+ .allowlist_function("rb_set_cfp_(pc|sp)")
+ .allowlist_function("rb_c_method_tracing_currently_enabled")
+ .allowlist_function("rb_zjit_method_tracing_currently_enabled")
+ .allowlist_function("rb_zjit_iseq_tracing_currently_enabled")
+ .allowlist_function("rb_full_cfunc_return")
+ .allowlist_function("rb_assert_(iseq|cme)_handle")
+ .allowlist_function("rb_IMEMO_TYPE_P")
+ .allowlist_function("rb_RSTRING_PTR")
+ .allowlist_function("rb_RSTRING_LEN")
+ .allowlist_function("rb_ENCODING_GET")
+ .allowlist_function("rb_profile_frame_full_label")
+ .allowlist_function("rb_profile_frame_absolute_path")
+ .allowlist_function("rb_profile_frame_path")
+ .allowlist_function("rb_optimized_call")
+ .allowlist_function("rb_jit_icache_invalidate")
+ .allowlist_function("rb_zjit_print_exception")
+ .allowlist_function("rb_zjit_singleton_class_p")
+ .allowlist_function("rb_zjit_defined_ivar")
+ .allowlist_function("rb_zjit_insn_leaf")
+ .allowlist_type("jit_bindgen_constants")
+ .allowlist_type("zjit_struct_offsets")
+ .allowlist_var("ZJIT_JIT_RETURN_C_FRAME")
+ .allowlist_function("rb_assert_holding_vm_lock")
+ .allowlist_function("rb_jit_shape_complex_p")
+ .allowlist_function("rb_jit_multi_ractor_p")
+ .allowlist_function("rb_jit_class_fields_embedded_p")
+ .allowlist_function("rb_jit_data_fields_embedded_p")
+ .allowlist_function("rb_jit_vm_lock_then_barrier")
+ .allowlist_function("rb_jit_vm_unlock")
+ .allowlist_function("rb_jit_for_each_iseq")
+ .allowlist_function("rb_iseq_reset_jit_func")
+ .allowlist_function("rb_vm_barrier")
+
+ // Not sure why it's picking these up, but don't.
+ .blocklist_type("FILE")
+ .blocklist_type("_IO_.*")
+
+ .allowlist_function("rb_vm_insn_decode")
+ .allowlist_function("rb_jit_cont_each_iseq")
+ .allowlist_function("rb_vm_insn_addr2opcode")
+ .allowlist_function("rb_iseqw_to_iseq")
+ .allowlist_function("rb_iseq_label")
+ .allowlist_function("rb_iseq_line_no")
+ .allowlist_function("rb_iseq_defined_string")
+ .allowlist_type("defined_type")
+ .allowlist_type("rb_builtin_function.*")
+ .allowlist_function("rb_gvar_(get|set)")
+ .allowlist_function("rb_ensure_iv_list_size")
+ .allowlist_function("rb_attr_get")
+ .allowlist_function("rb_ivar_defined")
+ .allowlist_function("rb_ivar_get")
+ .allowlist_function("rb_ivar_get_at_no_ractor_check")
+ .allowlist_function("rb_ivar_set")
+ .allowlist_function("rb_mod_name")
+ .allowlist_var("rb_vm_insn_count")
+ .allowlist_function("rb_get_alloc_func")
+ .allowlist_function("rb_class_allocate_instance")
+ .allowlist_function("rb_obj_equal")
+ .allowlist_function("rb_class_new_instance_pass_kw")
+ .allowlist_function("rb_obj_alloc")
+ .allowlist_function("rb_obj_info")
+ .allowlist_function("rb_obj_frozen_p")
+ // From include/ruby/debug.h
+ .allowlist_function("rb_profile_frames")
+ .allowlist_function("ruby_xfree")
+ .allowlist_function("rb_profile_frames")
+
+ // Functions used for code generation
+ .allowlist_function("rb_insn_name")
+ .allowlist_function("rb_insn_len")
+ .allowlist_function("rb_yarv_class_of")
+ .allowlist_function("rb_zjit_class_initialized_p")
+ .allowlist_function("rb_zjit_class_has_default_allocator")
+ .allowlist_function("rb_zjit_class_get_alloc_func")
+ .allowlist_function("rb_get_ec_cfp")
+ .allowlist_function("rb_get_cfp_iseq")
+ .allowlist_function("rb_get_cfp_pc")
+ .allowlist_function("rb_get_cfp_sp")
+ .allowlist_function("rb_get_cfp_self")
+ .allowlist_function("rb_get_cfp_ep")
+ .allowlist_function("rb_get_cfp_ep_level")
+ .allowlist_function("rb_get_cme_def_type")
+ .allowlist_function("rb_zjit_constcache_shareable")
+ .allowlist_function("rb_zjit_vm_search_method")
+ .allowlist_function("rb_zjit_cme_is_cfunc")
+ .allowlist_function("rb_get_cme_def_body_attr_id")
+ .allowlist_function("rb_get_symbol_id")
+ .allowlist_function("rb_get_cme_def_body_optimized_type")
+ .allowlist_function("rb_get_cme_def_body_optimized_index")
+ .allowlist_function("rb_get_cme_def_body_cfunc")
+ .allowlist_function("rb_get_def_method_serial")
+ .allowlist_function("rb_get_def_original_id")
+ .allowlist_function("rb_get_mct_argc")
+ .allowlist_function("rb_get_mct_func")
+ .allowlist_function("rb_get_def_iseq_ptr")
+ .allowlist_function("rb_get_def_bmethod_proc")
+ .allowlist_function("rb_jit_get_proc_ptr")
+ .allowlist_function("rb_iseq_encoded_size")
+ .allowlist_function("rb_get_iseq_body_total_calls")
+ .allowlist_function("rb_get_iseq_body_local_iseq")
+ .allowlist_function("rb_get_iseq_body_parent_iseq")
+ .allowlist_function("rb_get_iseq_body_iseq_encoded")
+ .allowlist_function("rb_get_iseq_body_stack_max")
+ .allowlist_function("rb_get_iseq_body_type")
+ .allowlist_function("rb_get_iseq_flags_has_lead")
+ .allowlist_function("rb_get_iseq_flags_has_opt")
+ .allowlist_function("rb_get_iseq_flags_has_kw")
+ .allowlist_function("rb_get_iseq_flags_has_rest")
+ .allowlist_function("rb_get_iseq_flags_has_post")
+ .allowlist_function("rb_get_iseq_flags_has_kwrest")
+ .allowlist_function("rb_get_iseq_flags_anon_kwrest")
+ .allowlist_function("rb_get_iseq_flags_has_block")
+ .allowlist_function("rb_get_iseq_flags_ambiguous_param0")
+ .allowlist_function("rb_get_iseq_flags_accepts_no_kwarg")
+ .allowlist_function("rb_get_iseq_flags_ruby2_keywords")
+ .allowlist_function("rb_get_iseq_flags_forwardable")
+ .allowlist_function("rb_get_iseq_body_local_table_size")
+ .allowlist_function("rb_get_iseq_body_param_keyword")
+ .allowlist_function("rb_get_iseq_body_param_size")
+ .allowlist_function("rb_get_iseq_body_param_lead_num")
+ .allowlist_function("rb_get_iseq_body_param_opt_num")
+ .allowlist_function("rb_get_iseq_body_param_opt_table")
+ .allowlist_function("rb_get_cikw_keyword_len")
+ .allowlist_function("rb_get_cikw_keywords_idx")
+ .allowlist_function("rb_get_call_data_ci")
+ .allowlist_function("rb_yarv_str_eql_internal")
+ .allowlist_function("rb_str_neq_internal")
+ .allowlist_function("rb_yarv_ary_entry_internal")
+ .allowlist_function("rb_vm_get_untagged_block_handler")
+ .allowlist_function("rb_vm_untag_block_handler")
+ .allowlist_function("rb_FL_TEST")
+ .allowlist_function("rb_FL_TEST_RAW")
+ .allowlist_function("rb_RB_TYPE_P")
+ .allowlist_function("rb_BASIC_OP_UNREDEFINED_P")
+ .allowlist_function("rb_vm_ci_argc")
+ .allowlist_function("rb_vm_ci_mid")
+ .allowlist_function("rb_vm_ci_flag")
+ .allowlist_function("rb_vm_ci_kwarg")
+ .allowlist_function("rb_METHOD_ENTRY_VISI")
+ .allowlist_function("rb_RCLASS_ORIGIN")
+ .allowlist_function("rb_method_basic_definition_p")
+ .allowlist_function("rb_obj_class")
+ .allowlist_function("rb_obj_is_proc")
+ .allowlist_function("rb_vm_base_ptr")
+ .allowlist_function("rb_ec_stack_check")
+ .allowlist_function("rb_vm_top_self")
+ .allowlist_function("rb_const_lookup")
+
+ // We define these manually, don't import them
+ .blocklist_type("VALUE")
+ .blocklist_type("ID")
+ .blocklist_type("rb_iseq_constant_body")
+
+ // Avoid binding to stuff we don't use
+ .blocklist_item("rb_thread_struct.*")
+ .opaque_type("rb_thread_struct.*")
+ .blocklist_item("iseq_inline_storage_entry_.*")
+ .opaque_type("iseq_inline_storage_entry")
+ .opaque_type("iseq_compile_data")
+
+ // Finish the builder and generate the bindings.
+ .generate()
+ // Unwrap the Result and panic on failure.
+ .expect("Unable to generate bindings");
+
+ let mut out_path: PathBuf = src_root;
+ out_path.push(jit_name);
+ out_path.push("src");
+ out_path.push("cruby_bindings.inc.rs");
+
+ bindings
+ .write_to_file(out_path)
+ .expect("Couldn't write bindings!");
+}