Skip to content

ruby: re-enable yjit, and fix, on cross#461684

Merged
kirillrdy merged 2 commits intoNixOS:masterfrom
samueldr:fix/ruby-cross-ynojit-lets-yjit
Nov 18, 2025
Merged

ruby: re-enable yjit, and fix, on cross#461684
kirillrdy merged 2 commits intoNixOS:masterfrom
samueldr:fix/ruby-cross-ynojit-lets-yjit

Conversation

@samueldr
Copy link
Member

@samueldr samueldr commented Nov 14, 2025

This PR fixes yjit support, after re-enabling it (see: #449938).

This was authored sometimes last year when working on fixing Mobile NixOS cross-compilation issues with Ruby. I never got around to sending the fix.

Currently verified with:

 $ nix-build --attr pkgsCross.aarch64-multiplatform.ruby_3_3 --attr pkgsCross.aarch64-multiplatform.ruby_3_4

~/tmp/nixpkgs/nixos-unstable $ nix-shell -p qemu-user

[nix-shell:~/tmp/nixpkgs/nixos-unstable]$ qemu-aarch64 ./result/bin/ruby --yjit-stats -e 'pp RUBY_VERSION'
"3.3.10"
***YJIT: Printing YJIT statistics on exit***
[...]

For the record, before this change:

[nix-shell:~/tmp/nixpkgs/nixos-unstable]$ qemu-aarch64 ./result/bin/ruby --yjit-stats -e 'pp RUBY_VERSION'
./result/bin/ruby: warning: Ruby was built without YJIT support. You may need to install rustc to build Ruby with YJIT.
"3.3.10"

Ruby 3.5 has an unrelated failure, same as on nixos-unstable:

error: output '/nix/store/0f1s4lmddng92rwi28l1ibajiyq3ky22-ruby-aarch64-unknown-linux-> gnu-3.5.0-preview1' is not allowed to refer to the following paths:
         /nix/store/41virlkphdik7jnvagaas5lxaqbii1hn-ruby-3.3.10

Note that the build otherwise fully succeeds.


  • cc @nim65s, who turned the feature off.
  • cc @kirillrdy, who reviewed the previous change (and is getting deeper into Ruby maintenance?)

Things done

  • Built on platform:
    • x86_64-linux [yes, cross]
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@samueldr
Copy link
Member Author

I can fold back the Revert commit into the other commits, but I feel this is better showing what was done, rather than making the other commits include the revert.

@nixpkgs-ci nixpkgs-ci bot requested a review from manveru November 14, 2025 20:01
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. labels Nov 14, 2025
@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Nov 14, 2025
Copy link
Contributor

@nim65s nim65s left a comment

Choose a reason for hiding this comment

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

Great, thanks !

Diff LGTM, and I can confirm this fix the issue that got me to deactivate this, so I'm happy for the revert

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 14, 2025
@@ -181,6 +174,13 @@ let
];
propagatedBuildInputs = op jemallocSupport jemalloc;

env = lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && yjitSupport) {
Copy link
Member

Choose a reason for hiding this comment

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

i think this is cause of mass rebuild, can it be split ? if not, this should go to staging

Copy link
Member Author

Choose a reason for hiding this comment

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

Not in this case, it's the removal of cargo from the inputs that changes the ruby derivation.

The env input attribute in mkDerivation is special-cased and when it's an empty set, it has no effect.

nix-repl> stdenv.mkDerivation { name = "foo"; }                                             
«derivation /nix/store/w0ps5bzjcc5x3xcv8b327jfzmd5k5nsp-foo.drv»

nix-repl> stdenv.mkDerivation { name = "foo"; env = lib.optionalAttrs false { x = "x"; }; }
«derivation /nix/store/w0ps5bzjcc5x3xcv8b327jfzmd5k5nsp-foo.drv»

nix-repl> stdenv.mkDerivation { name = "foo"; env = lib.optionalAttrs true { x = "x"; }; }  
«derivation /nix/store/216b6l77hb1n2s6n6n7asfdj4b49qcg4-foo.drv»

I'll split that (cargo) change out if ruby cross-compiles fine without that change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Follow-up: #462631

@samueldr samueldr force-pushed the fix/ruby-cross-ynojit-lets-yjit branch from 2db1dcf to 26ddea6 Compare November 17, 2025 16:51
Otherwise it will produce `yjit.a` with the default target for the
`rustc` compiler, which in turn turns out to be the build platform?

It could be configured using the `RUST` environment variable, and
since it's used without quoting it would expand the arguments added
to it.

Using `RUST = "rust --target ..."` I think would be  undesirable for
cross-compiling (and native), since it will save those arguments in
`lib/ruby/*/*/rbconfig.rb`. Though that might be fine too. I guess.

Note that 3.2 breaks differently. I haven't investigated it, since it's
not the default anymore, and will eventually be dropped.

Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
(cherry picked from commit 75d6216)
@samueldr
Copy link
Member Author

(Previous force-push is a simple rebase on top of current nixos-unstable)

@samueldr
Copy link
Member Author

samueldr commented Nov 17, 2025

With the following force-push'd changes:

 $ git checkout -B nixos-unstable NixOS/nixos-unstable

 $ nix-instantiate --attr ruby_3_3
/nix/store/maym3jairjj8mybhf06vfks8ak2mchh3-ruby-3.3.10.drv

 $ git checkout fix/ruby-cross-ynojit-lets-yjit 

~/tmp/nixpkgs/nixos-unstable $ nix-instantiate --attr ruby_3_3
/nix/store/maym3jairjj8mybhf06vfks8ak2mchh3-ruby-3.3.10.drv

And it still cross-compiles.

~/tmp/nixpkgs/nixos-unstable $ nix-build --attr pkgsCross.aarch64-multiplatform.ruby_3_3
/nix/store/57v2sv3lx61y3rd59bnyl5g99rdff9n3-ruby-aarch64-unknown-linux-gnu-3.3.10

@samueldr samueldr force-pushed the fix/ruby-cross-ynojit-lets-yjit branch from 26ddea6 to c286dcb Compare November 17, 2025 17:31
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. and removed 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Nov 17, 2025
@kirillrdy kirillrdy added this pull request to the merge queue Nov 18, 2025
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Nov 18, 2025
Merged via the queue into NixOS:master with commit cce25db Nov 18, 2025
31 of 34 checks passed
@samueldr samueldr deleted the fix/ruby-cross-ynojit-lets-yjit branch November 18, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants