This commit is contained in:
Jaroslaw Konik 2025-05-20 22:20:05 +02:00
parent 5d104a1d01
commit 07331f8d48
3 changed files with 16 additions and 5 deletions

6
.cargo/config.toml Normal file
View file

@ -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"]

View file

@ -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]]

View file

@ -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::<Box<dyn FnOnce(Ruby) + Send>>();
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::<Vec<_>>();
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");