[erlang-questions] Rebar & Cowboy on Windows 7

346 views
Skip to first unread message

David Mercer

unread,
Oct 8, 2012, 11:54:15 AM10/8/12
to erlang-q...@erlang.org

Having made the statement a few times over the last few months that Rebar is not compatible with Windows, I was challenged on this.  My statement was based on my one-off experience with Rebar one or two years ago, so it was time I retried it.  I decided to use the discussion about HTTP servers to try out Cowboy, which requires Rebar.

 

1.       Rebar installed just fine on Windows.  I downloaded the zip file from Git Hub and unzipped it into my Erlang lib directory.  I ended up with a directory named “basho-rebar-32e67ef” in my lib, which is kind of nonstandard naming, but I could have renamed it to “rebar-...” if I had bothered to look up the correct version number to put there.  Failing that, I could have just renamed it “rebar”, but it worked as it was, so I was unconcerned.

 

2.       I ran the Rebar bootstrap.bat, which generated a rebar file and a rebar.cmd file to run it.  So far I was quite encouraged, with the provision of a Windows “bat” file and now a “cmd” file.  It would appear that Rebar was built to work on Windows. J

 

3.       I downloaded Cowboy from Git Hub the same way I did Rebar.  The resulting directory was again named “extend-cowboy-1f9d71c” in the nonstandard way of Git Hub, but it still works.

 

4.       Here I ran into some problems, but it turned out they were mine rather than Windows’s.  I tried a “rebar compile” on Cowboy, but got an error about the dependency on Ranch not being available.  It should have been available, since I had previously downloaded it, and even if I hadn’t, the rebar.config told it where it could get it from.  Turns out, however, that I have to explicitly tell it to get dependencies.  Tuncer Ayaz – bless his soul – gave me a hand here and explained that I should use the command “rebar get-deps”, “rebar get-deps compile”, or abbreviated to “rebar g-d com”.  With that, it downloaded Ranch and compiled fine.  Yay!

 

5.       Interestingly enough, Rebar does not download the dependencies into the Erlang lib directory, but rather into a “deps” subdirectory of your application.  This means erl.exe and werl.exe cannot see it, but this can easily be rectified by either copying the downloaded applications up into the lib directory, or using the “-pa” option on the command line.  If anyone has any suggestions as to which is better for their workflow, please let me know.

 

6.       At this point, Cowboy was working, but I figured I should try to get it to do something useful.  I couldn’t find a whole lot of documentation on its API, but I did find that it came with a few examples in the examples subdirectory.  I decided to give the static example a whirl, and Rebarred it and then ran it, and it worked.  Fine.  Out of the box.  Yay!

 

7.       Unfortunately, when it served up the test.txt sample file, Chrome treated it as a download rather than text to be displayed in the browser.  Usually when I encounter an issue where I want to see what’s coming down the wire, I just telnet to the appropriate port and send a “GET /” to see what is returned.  I don’t think Cowboy handles HTTP 1.0, though I couldn’t find any record of that.  At any rate, I just had to do some extra typing in order to send a minimal HTTP 1.1 request, and after some poking around, I discovered my problem was related to the MIME type being sent in the HTTP response.  So I added the “mimetypes” application to the example’s Rebar dependencies, modified the static_app.erl file to use the function mimetypes:path_to_mimes to choose the correct MIME type and then restarted it – or at least tried to.  Try as I may, I could not get it to work for the longest time.  In the end, I determined that mimetypes’s lexer was built for Unix only, not Windows, so it was not recognizing the line endings in the provided mime.types file.  The solution then was to modify mimetypes’s mimetypes_scan.xrl to recognize a CRLF as a newline, too.  I suppose I should figure out how to use Git Hub so I can submit that patch.  At any rate, now it all works like champ.

 

So I can confirm that both Rebar and Cowboy work on Windows 7 system.  Thank-you all for your work on these.

 

David Mercer

Director, Technology & Research

MedWorth

 

Loïc Hoguin

unread,
Oct 8, 2012, 12:07:26 PM10/8/12
to David Mercer, erlang-q...@erlang.org
Hello,

On 10/08/2012 05:54 PM, David Mercer wrote:
> 3.I downloaded Cowboy from Git Hub the same way I did Rebar. The
> resulting directory was again named “extend-cowboy-1f9d71c” in the
> nonstandard way of Git Hub, but it still works.

Note that you typically just include Cowboy as a dependency for your own
application.

> 4.Here I ran into some problems, but it turned out they were mine rather
> than Windows’s. I tried a “rebar compile” on Cowboy, but got an error
> about the dependency on Ranch not being available. It should have been
> available, since I had previously downloaded it, and even if I hadn’t,
> the /rebar.config/ told it where it could get it from. Turns out,
> however, that I have to explicitly tell it to get dependencies. Tuncer
> Ayaz – bless his soul – gave me a hand here and explained that I should
> use the command “rebar get-deps”, “rebar get-deps compile”, or
> abbreviated to “rebar g-d com”. With that, it downloaded Ranch and
> compiled fine. Yay!

It's automated on Linux because of the Makefile, you can just type
"make" there. Not sure the same can be done for Windows without a lot of
manipulations.

> 5.Interestingly enough, Rebar does not download the dependencies into
> the Erlang lib directory, but rather into a “deps” subdirectory of your
> application. This means /erl.exe/ and /werl.exe/ cannot see it, but
> this can easily be rectified by either copying the downloaded
> applications up into the lib directory, or using the “-pa” option on the
> command line. If anyone has any suggestions as to which is better for
> their workflow, please let me know.

Neither, the proper way is building your own releases. Releases will
then include both erl.exe and Cowboy and all the applications required.

The examples use -pa only for demonstration purposes, I recommend
building releases even while developing.

> 6.At this point, Cowboy was working, but I figured I should try to get
> it to do something useful. I couldn’t find a whole lot of documentation
> on its API, but I did find that it came with a few examples in the
> /examples/ subdirectory. I decided to give the static example a whirl,
> and Rebarred it and then ran it, and it worked. Fine. Out of the box.
> Yay!

Can you try "rebar edoc"? It's supposed to generate the API reference.

> 7.Unfortunately, when it served up the /test.txt/ sample file, Chrome
> treated it as a download rather than text to be displayed in the
> browser. Usually when I encounter an issue where I want to see what’s
> coming down the wire, I just telnet to the appropriate port and send a
> “GET /” to see what is returned. I don’t think Cowboy handles HTTP 1.0,
> though I couldn’t find any record of that. At any rate, I just had to
> do some extra typing in order to send a minimal HTTP 1.1 request, and
> after some poking around, I discovered my problem was related to the
> MIME type being sent in the HTTP response. So I added the “mimetypes”
> application to the example’s Rebar dependencies, modified the
> /static_app.erl/ file to use the function /mimetypes:path_to_mimes/ to
> choose the correct MIME type and then restarted it – or at least tried
> to. Try as I may, I could not get it to work for the longest time. In
> the end, I determined that mimetypes’s lexer was built for Unix only,
> not Windows, so it was not recognizing the line endings in the provided
> /mime.types/ file. The solution then was to modify mimetypes’s
> /mimetypes_scan.xrl/ to recognize a CRLF as a newline, too. I suppose I
> should figure out how to use Git Hub so I can submit that patch. At any
> rate, now it all works like champ.

Please do send a patch, that'd be much appreciated!

And yeah the example can probably be improved a little using the
mimetypes application. Feel free to send a patch for that, too.

> So I can confirm that both Rebar and Cowboy work on Windows 7 system.
> Thank-you all for your work on these.

Thanks for testing!

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

David Mercer

unread,
Oct 8, 2012, 1:22:37 PM10/8/12
to Loïc Hoguin, erlang-q...@erlang.org
On Monday, October 08, 2012, Loïc Hoguin wrote:

> It's automated on Linux because of the Makefile, you can just type "make"
> there. Not sure the same can be done for Windows without a lot of
> manipulations.

In my experience, Makefiles in Windows get all screwed up with the directory separator. I'll give it a whirl, though, and see if anyone's version of make on Windows works.

> Neither, the proper way is building your own releases. Releases will then
> include both erl.exe and Cowboy and all the applications required.
>
> The examples use -pa only for demonstration purposes, I recommend building
> releases even while developing.

Good advice, which is probably what I would do if using Rebar in my development. Not previously having Rebar at my disposal, release-making was a bit over-complicated for some of the stuff I did.

> Can you try "rebar edoc"? It's supposed to generate the API reference.

"rebar doc" works fine, and I looked at the documentation on Friday; it just didn’t help me.

For example:

start_http(Ref::any(), NbAcceptors::non_neg_integer(), TransOpts::any(), ProtoOpts::any()) -> {ok, pid()}

I am still none the wiser as to what to pass the start_http function.

> Please do send a patch, that'd be much appreciated!
>
> And yeah the example can probably be improved a little using the mimetypes
> application. Feel free to send a patch for that, too.

Will do, once I figure out the Git Hub process. Is Git Hub now preferred over Bit Bucket?

Cheers,

DBM

Reply all
Reply to author
Forward
0 new messages