diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f3e9974 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,6 @@ +[build] +# Without this flag, when linking static libruby, the linker removes symbols +# (such as `_rb_ext_ractor_safe`) which it thinks are dead code... but they are +# not, and they need to be included for the `embed` feature to work with static +# Ruby. +rustflags = ["-C", "link-dead-code=on", "-C", "link-arg=-lz"] diff --git a/Cargo.toml b/Cargo.toml index f4666e6..8c7712c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ mlua = { version = "0.9.8", features = [ ], optional = true } magnus = { version = "0.7.1", optional = true } rb-sys = { version = "*", default-features = false, features = ["link-ruby", "ruby-static"], optional = true } -openssl-sys = { version = "0.9", features = ["vendored"] } crossbeam-channel = "0.5.15" [[example]] diff --git a/src/runtimes/ruby.rs b/src/runtimes/ruby.rs index fa535a6..399d58e 100644 --- a/src/runtimes/ruby.rs +++ b/src/runtimes/ruby.rs @@ -21,16 +21,14 @@ use magnus::{ DataType, DataTypeFunctions, IntoValue, Object, RClass, RModule, Ruby, TryConvert, TypedData, }; use magnus::{method, prelude::*}; -use rb_sys::{ - ruby_exec_node, ruby_finalize, ruby_init_stack, ruby_options, ruby_process_options, VALUE, -}; +use rb_sys::{ruby_finalize, ruby_init_stack, VALUE}; use serde::Deserialize; use crate::{ assets::GetExtensions, callback::{FromRuntimeValueWithEngine, IntoRuntimeValueWithEngine}, promise::Promise, - FuncArgs, Runtime, ScriptingError, ENTITY_VAR_NAME, + FuncArgs, Runtime, ScriptingError, }; #[derive(Resource)] @@ -74,10 +72,18 @@ impl RubyThread { let (sender, receiver) = crossbeam_channel::unbounded::>(); let handle = thread::spawn(move || { + let argc: i32 = 0; + let argv = vec![CString::new("ruby").unwrap(), CString::new("-e").unwrap()]; + let mut argv = argv + .iter() + .map(|cs| cs.as_ptr() as *mut _) + .collect::>(); + unsafe { let mut variable_in_this_stack_frame: VALUE = 0; ruby_init_stack(&mut variable_in_this_stack_frame as *mut VALUE as *mut _); rb_sys::ruby_init(); + rb_sys::ruby_options(argc, argv.as_mut_ptr()); }; while let Ok(f) = receiver.recv() { let ruby = Ruby::get().expect("Failed to get a handle to Ruby API");