cli icon indicating copy to clipboard operation
cli copied to clipboard

Windows support running `hanami dev`

Open kyleplump opened this issue 1 year ago • 4 comments

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?

kyleplump avatar Jul 28 '24 13:07 kyleplump

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 avatar Jul 29 '24 12:07 timriley

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?

timriley avatar Jul 29 '24 12:07 timriley

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!

kyleplump avatar Jul 29 '24 21:07 kyleplump

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

pcopissa avatar Nov 05 '24 00:11 pcopissa