Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@
- os: windows-2025
rust_toolchain: stable
include:
# TODO: Remove allow_failure after 2025-01-01 (known compatibility issues)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe after 2026-01-01?

- ruby_version: "truffleruby"
allow_failure: true
sys:
os: ubuntu-latest
rust_toolchain: stable
- ruby_version: "truffleruby"
allow_failure: true
sys:
os: macos-15
rust_toolchain: stable
- ruby_version: mswin

Check warning on line 84 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / 🧪 Test (mswin, windows-2022, stable-x86_64-pc-windows-msvc)

mswin builds use ruby-master, and which is unstable and may break your build at any time (see https://github.com/MSP-Greg/ruby-loco/issues/12)
sys:
os: windows-2022
rust_toolchain: stable-x86_64-pc-windows-msvc
Expand All @@ -86,6 +89,12 @@
sys:
os: ubuntu-latest
rust_toolchain: stable
# TODO: Remove allow_failure after 2025-01-01 (known Windows compatibility issues)
- ruby_version: "3.4"
allow_failure: true
sys:
os: windows-2025
rust_toolchain: stable
exclude:
- ruby_version: "3.1"
sys:
Expand All @@ -99,15 +108,14 @@
sys:
os: windows-2022
rust_toolchain: stable
- ruby_version: "3.4"
sys:
os: windows-2025
rust_toolchain: stable
# Ruby 4.0 not available on Windows yet
- ruby_version: "4.0.0-preview2"
sys:
os: windows-2025
rust_toolchain: stable
runs-on: ${{ matrix.sys.os }}
# Allow truffleruby to fail until 2025-01-01 (known compatibility issues)
continue-on-error: ${{ matrix.allow_failure || false }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

Expand Down Expand Up @@ -176,7 +184,7 @@

- name: 🧪 Cargo test
shell: bash
if: matrix.ruby_version != 'mswin'

Check warning on line 187 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / 🧪 Test (mswin, windows-2022, stable-x86_64-pc-windows-msvc)

mswin builds use ruby-master, and which is unstable and may break your build at any time (see https://github.com/MSP-Greg/ruby-loco/issues/12)
run: |
ulimit -c unlimited
bundle exec rake test:cargo
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-4.0.0-preview2
18 changes: 8 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ source "https://rubygems.org"
gemspec path: "gem"
gemspec path: "examples/rust_reverse"

gem "rake", "~> 13.0"
gem "minitest", "5.15.0"
gem "rake-compiler", "~> 1.3.0" # Small bug in 1.2.4 that breaks Ruby 2.5
gem "rake-compiler-dock", "1.10.0" # This should match the versions used in docker/Dockerfile.*
gem "racc", "~> 1.7"
gem "base64", "~> 0.3.0"
gem "rake"
gem "minitest"
gem "rake-compiler"
gem "rake-compiler-dock"
gem "racc"
gem "base64"
gem "yard"
gem "mutex_m"

if RUBY_VERSION >= "2.7.0"
gem "standard", "~> 1.12.1"
end
gem "standard"
gem "tsort"
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def cargo_test_task(name, *args, crate: name)
next
end

default_args = ENV["CI"] || extra_args.include?("--verbose") ? [] : ["--quiet"]
test_args = ENV["CI"] || extra_args.include?("--verbose") ? ["--", "--nocapture"] : []
default_args = (ENV["CI"] || extra_args.include?("--verbose")) ? [] : ["--quiet"]
test_args = (ENV["CI"] || extra_args.include?("--verbose")) ? ["--", "--nocapture"] : []
sh "cargo", "test", *default_args, *extra_args, *args, "-p", crate, *test_args
puts "=" * 80
end
Expand Down
10 changes: 7 additions & 3 deletions crates/rb-sys-tests/src/memory_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ fn test_rb_gc_guarded_ptr_vec() {
unsafe {
let mut vec_of_values: Vec<VALUE> = Default::default();

let s1 = rb_str_new_cstr(format!("hello world{i}\0").as_ptr() as _);
// Keep the CStrings alive until after rb_str_new_cstr uses them
let cstr1 = std::ffi::CString::new(format!("hello world{i}")).unwrap();
let s1 = rb_str_new_cstr(cstr1.as_ptr());
let s1 = rb_gc_guard!(s1);
vec_of_values.push(s1);

let s2 = rb_str_new_cstr(format!("hello world{i}\0").as_ptr() as _);
let cstr2 = std::ffi::CString::new(format!("hello world{i}")).unwrap();
let s2 = rb_str_new_cstr(cstr2.as_ptr());
let s2 = rb_gc_guard!(s2);
vec_of_values.push(s2);

let s3 = rb_str_new_cstr(format!("hello world{i}\0").as_ptr() as _);
let cstr3 = std::ffi::CString::new(format!("hello world{i}")).unwrap();
let s3 = rb_str_new_cstr(cstr3.as_ptr());
let s3 = rb_gc_guard!(s3);
vec_of_values.push(s3);

Expand Down
1 change: 1 addition & 0 deletions crates/rb-sys/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![allow(rustdoc::invalid_html_tags)]
#![allow(deprecated)]
#![allow(dead_code)]
#![allow(unpredictable_function_pointer_comparisons)]

include!(env!("RB_SYS_BINDINGS_PATH"));

Expand Down
19 changes: 12 additions & 7 deletions crates/rb-sys/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,24 @@ macro_rules! debug_ruby_assert_type {
mod tests {
use super::*;
use rusty_fork::rusty_fork_test;
use std::ptr::addr_of_mut;

rusty_fork_test! {
#[test]
fn test_is_ruby_vm_started() {
assert!(!unsafe { is_ruby_vm_started() });

#[cfg(windows)]
{
let mut argc = 0;
let mut argv: [*mut std::os::raw::c_char; 0] = [];
let mut argv = argv.as_mut_ptr();
unsafe { rb_sys::rb_w32_sysinit(&mut argc, &mut argv) };
}
// Call ruby_sysinit which handles platform-specific initialization
// (rb_w32_sysinit on Windows) and sets up standard file descriptors
let mut argc = 0;
let mut argv: [*mut std::os::raw::c_char; 0] = [];
let mut argv_ptr = argv.as_mut_ptr();
unsafe { crate::ruby_sysinit(&mut argc, &mut argv_ptr) };

// ruby_init_stack must be called before ruby_setup, especially on
// Windows where it's required for proper GC stack scanning
let mut stack_marker: crate::VALUE = 0;
unsafe { crate::ruby_init_stack(addr_of_mut!(stack_marker) as *mut _) };

match unsafe { crate::ruby_setup() } {
0 => {}
Expand Down
72 changes: 72 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@
description = "Dev environment for rb-sys";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-ruby.url = "github:bobvanderlinden/nixpkgs-ruby";
nixpkgs-ruby.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
outputs = { self, nixpkgs, rust-overlay, flake-utils, nixpkgs-ruby, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
ruby = nixpkgs-ruby.lib.packageFromRubyVersionFile {
file = ./.ruby-version;
inherit system;
};
rustToolchain = pkgs.rust-bin.stable.latest.default;
in
with pkgs;
{
devShells.default = mkShell {
packages.ruby = ruby;

devShells.default = pkgs.mkShell {
buildInputs = [
fastmod
ruby_3_3.devEnv
rust-bin.stable.latest.default
bundler
zsh
nodejs
pkgs.fastmod
ruby
rustToolchain
pkgs.zsh
pkgs.nodejs
];

# Make is so nix develop --impure uses zsh config
Expand Down
10 changes: 6 additions & 4 deletions gem/exe/rb-sys-dock
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ end
def list_platforms
RbSys::ToolchainInfo.supported.each do |p|
old = logger.io
logger.io = $stdout
puts "- #{p.platform}"
ensure
logger.io = old
begin
logger.io = $stdout
puts "- #{p.platform}"
ensure
logger.io = old
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions gem/lib/rb_sys/cargo_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def cargo_command(dest_path, args = [])
end

def cargo_dylib_path(dest_path)
prefix = so_ext == "dll" ? "" : "lib"
prefix = (so_ext == "dll") ? "" : "lib"
path_parts = [dest_path]
path_parts << target if target
path_parts += [profile_target_directory, "#{prefix}#{cargo_crate_name}.#{so_ext}"]
Expand Down Expand Up @@ -355,7 +355,7 @@ class DylibNotFoundError < StandardError
def initialize(dir)
files = Dir.glob(File.join(dir, "**", "*")).map { |f| "- #{f}" }.join "\n"

super <<~MSG
super(<<~MSG)
Dynamic library not found for Rust extension (in #{dir})

Make sure you set "crate-type" in Cargo.toml to "cdylib"
Expand Down
2 changes: 1 addition & 1 deletion gem/lib/rb_sys/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def conditional_assign(a, b, export: false, indent: 0)
result << export_env(a, b) if export
result
else
"#{"\t" * indent}#{export ? "export " : ""}#{a} ?= #{b}"
"#{"\t" * indent}#{"export " if export}#{a} ?= #{b}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion rakelib/docker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "yaml"
require "json"
require_relative "./../gem/lib/rb_sys/version"
require_relative "../gem/lib/rb_sys/version"

TOOLCHAINS = JSON.parse(File.read("data/toolchains.json"))["toolchains"]
DOCKERFILE_PLATFORM_PAIRS = TOOLCHAINS.select { |p| p["supported"] }.map { |p| [p["dockerfile"], p["ruby-platform"]] }
Expand Down
4 changes: 2 additions & 2 deletions rakelib/release.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace :release do

desc "Bump the gem version"
task bump: "release:prepare" do
require_relative "./../gem/lib/rb_sys/version"
require_relative "../gem/lib/rb_sys/version"
old_version = RbSys::VERSION

printf "What is the new version (current: #{old_version})?: "
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace :release do
sh "bundle exec rake release"
end

require_relative "./../gem/lib/rb_sys/version"
require_relative "../gem/lib/rb_sys/version"

sh "gh", "release", "create", "v#{RbSys::VERSION}", "--generate-notes"

Expand Down
Loading