Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support running hanami dev #219

Open
kyleplump opened this issue Jul 28, 2024 · 4 comments
Open

Windows support running hanami dev #219

kyleplump opened this issue Jul 28, 2024 · 4 comments

Comments

@kyleplump
Copy link
Contributor

Tried to start developing on a windows machine and running into the following error executing: bundle exec hanami dev:

C:/Ruby33-x64/lib/ruby/3.3.0/open3.rb:534:in spawn': Exec format error - bin/dev (Errno::ENOEXEC)`

It look's like this might have been a bug introduced relatively recently? Or at least reported recently: https://www.reddit.com/r/ruby/comments/1b1c0yp/hanami_21_is_out/

Reproducible Steps

Create a new Hanami app on a windows machine and run the command:
gem install hanami
hanami new win_app
cd win_app
bundle exec hanami dev

It seems like it comes down to windows just not natively supporting bash? Although, even using Git Bash - same issue.

A few things I tried:

  1. Running hanami server directly seems to start everything up - but probably don't want to circumvent the procfile
  2. Converting dev.sh to dev.bat half works - the asset command forks a process, where forking isn't supported on non-POSIX (https://ruby-doc.org/core-2.6.2/Process.html#method-c-fork)

Any thoughts on Windows support?

@timriley
Copy link
Member

Hi @kyleplump, thanks for this report! I was unaware of this forking limitation on Windows, so I appreciate you bringing it up.

Sounds like we need to adjust Hanami::CLI::Commands::App::Assets::Command#fork_child_assets_command so it uses a spawning strategy on Windows.

Would you be able to help with this?

@timriley
Copy link
Member

It also looks like the bin/dev file is possibly being generated on Windows without the executable bit? Are you able to share the permissions of the newly generated file? Can you show whether it's executable or not?

@kyleplump
Copy link
Contributor Author

Hi @timriley, thanks for the response! Happy to help!

I opened a PR to provide a default fallback to the Hanami::CLI::Commands::App::Assets::Command#fork_child_assets_command function that will rely on spawning instead: #221. Lmk if this is an OK approach

Here are the file permissions on the file for a newly generated project:

image

Which looks to be correct. I'd also like to make an update: it does launch using Git Bash (although still gets hung up on the fork thing), that's my mistake.

Maybe we could update the documentation to mention this? The alternative is that we could provide an equivalent .bat file, use RbConfig::CONFIG['host_os'] to detect environment in both Generators::Gem::App#generate_app to determin which file to write, and Commands::App::Dev#executable and load in the appropriate executable name (SUPER quick testing makes it seem like you'd need to include the file extension in the case of the batch file)? That way you can maintain the hanami dev command and just hot swap executable types per environment. I'm not sure how much that change would impact, or even if it's something you'd want to get into from the point of view of 'Hanami philosophy` so I'll defer to you on that! ( again, happy to implement if it's something youre into :) )

Thanks!

@pcopissa
Copy link

pcopissa commented Nov 5, 2024

I took some time to investigate what's going on.
TL;DR hanami/hanami#1463 (comment)
longer version: hanami/hanami#1463 (comment)

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

No branches or pull requests

3 participants