Skip to content

Fix stable API rust impl file check#683

Merged
ianks merged 3 commits intomainfrom
stable-rust-impl-ensure
Dec 17, 2025
Merged

Fix stable API rust impl file check#683
ianks merged 3 commits intomainfrom
stable-rust-impl-ensure

Conversation

@ianks
Copy link
Collaborator

@ianks ianks commented Dec 16, 2025

When detecting Ruby versions like 3.5 (ruby-head), the build fails with a
missing file error because is_stable() only checked version ranges.

This fix replaces is_stable() with has_rust_impl() that checks if the actual
ruby_X_Y.rs file exists. Versions without impls (like 3.5, 4.1) now correctly
fall back to compiled C when stable-api-compiled-fallback is enabled, or error
clearly when it's not.

Fixes the issue where ruby-head (3.5.0) couldn't build rb-sys with stable API.

@ianks ianks force-pushed the stable-rust-impl-ensure branch from 1c2ea35 to 41477b7 Compare December 16, 2025 23:19
When detecting Ruby versions like 3.5 (ruby-head), the build would fail
with a missing file error because is_stable() only checked version ranges
rather than verifying a corresponding ruby_X_Y.rs file exists.

Replace is_stable() with has_rust_impl() that checks for actual file
existence. This allows ruby-head or other versions without impls to
correctly fall back to compiled C when stable-api-compiled-fallback is
enabled, or error clearly when it's not.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a build failure when using Ruby versions like 3.5 (ruby-head) by replacing the version range check with an actual file existence check. Previously, is_stable() only checked if a version fell within a predefined range, causing builds to fail when the implementation file didn't actually exist.

Key changes:

  • Replaced is_stable() method with has_rust_impl() that checks for actual Rust implementation file existence
  • Updated error messages to include the specific Ruby version for better debugging
  • Added version constraint to the standard gem in Gemfile

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/rb-sys/build/version.rs Removes the deprecated is_stable() method that only checked version ranges
crates/rb-sys/build/stable_api_config.rs Implements has_rust_impl() function that checks for actual file existence and updates all call sites
script/show-asm Formatting adjustment for command-line argument comments
Gemfile Adds version constraint to standard gem (appears unrelated to main fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +24
/// Check if a Rust implementation file exists for the given Ruby version.
fn has_rust_impl(version: Version) -> bool {
let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let path = crate_dir.join("src").join("stable_api").join(format!(
"ruby_{}_{}.rs",
version.major(),
version.minor()
));

let exists = path.exists();

// Ensure we rebuild if the file is added or removed
println!("cargo:rerun-if-changed={}", path.display());

exists
}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The has_rust_impl() function performs filesystem checks and is called multiple times during the build (lines 62, 96, 108, 122). Consider caching the result to avoid redundant filesystem operations, especially since the version doesn't change during a single build.

Copilot uses AI. Check for mistakes.
ianks and others added 2 commits December 16, 2025 19:43
The `standard` gem version 1.52.0 dropped support for Ruby 2.7. Since we only need linting on newer Rubies, we simply skip installing and running `standard` on Ruby < 3.0.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ianks ianks force-pushed the stable-rust-impl-ensure branch from 675f50e to d1d15c9 Compare December 17, 2025 02:38
@ianks ianks merged commit 794a8da into main Dec 17, 2025
59 of 60 checks passed
@ianks ianks deleted the stable-rust-impl-ensure branch December 17, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants