Skip to content

Allow compiling from source on windows:#3690

Merged
kddnewton merged 1 commit into
ruby:mainfrom
Edouard-chin:ec-shebang
Oct 22, 2025
Merged

Allow compiling from source on windows:#3690
kddnewton merged 1 commit into
ruby:mainfrom
Edouard-chin:ec-shebang

Conversation

@Edouard-chin

Copy link
Copy Markdown
Member

👋

I'm trying to compile Prism from source on a Windows machine but it unforutnately fails when trying to render the template due to the shebang that doesn't exist on Windows

#!/usr/bin/env ruby

I modified the system call to call ruby with its full path directly instead.

Comment thread ext/prism/extconf.rb Outdated
Dir.chdir(File.expand_path("../..", __dir__)) do
if !File.exist?("include/prism/ast.h") && Dir.exist?(".git")
system("templates/template.rb", exception: true)
system(Gem.ruby, "templates/template.rb", exception: true)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is okay, but I just want to make sure there's not an environment when Gem isn't available. @tenderlove do you know if that could possibly be the case?

Since we know we already have RbConfig because of the explicit require, maybe safer to just implement it ourselves:

Suggested change
system(Gem.ruby, "templates/template.rb", exception: true)
ruby = File.join(RbConfig::CONFIG["bindir"], "#{RbConfig::CONFIG["ruby_install_name"]}#{RbConfig::CONFIG["EXEEXT"]}")
system(ruby, "templates/template.rb", exception: true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using Gem should be fine. The only time it won't be available is if someone does --disable-gems, but since we're using RubyGems to install the gem, then I think it's OK.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is RbConfig.ruby, that seems safer to use and is just as expressive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The user could have RUBYOPT=--disable-gems in env, then Gem.ruby here would likely break (probably many other things too, but that's out of scope), hence RbConfig.ruby is better.

@Edouard-chin

Copy link
Copy Markdown
Member Author

Thanks for the review folks. Let me know if you'd like to go with the custom suggested solution or just Gem.ruby which is simpler

@eregon

eregon commented Oct 22, 2025

Copy link
Copy Markdown
Member

@Edouard-chin Can you change to RbConfig.ruby? Then I think it's good to go.

- I'm trying to compile Prism from source on a Windows machine but
  it unforunately fails when trying to render the template due to the
  shebang that doesn't exist on Windows.

  I modified the `system` call to call ruby with its full path
  directly instead.
@kddnewton
kddnewton merged commit 5e67d13 into ruby:main Oct 22, 2025
63 checks passed
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.

5 participants