Windows support running `hanami dev`
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:
- Running
hanami serverdirectly seems to start everything up - but probably don't want to circumvent the procfile - Converting
dev.shtodev.bathalf 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?
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?
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?
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:
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!
I took some time to investigate what's going on. TL;DR https://github.com/hanami/hanami/issues/1463#issuecomment-2455155518 longer version: https://github.com/hanami/hanami/issues/1463#issuecomment-2454538102