Sunday, February 23, 2014

Dart on Cloud 9 IDE

Although I haven't talked much about it, I've been doing quite a bit of JavaScript & HTML development in my free-time for the past year.  I had done web development for several years before that, but it was very basic and involved simply editing files via Notepad and uploading them to my server.  This workflow was very inefficient for me and made me hesitant to continue development since it was so cumbersome.  I sought out a solution for being able to develop directly in a web browser using a browser-based IDE.

I discovered that there were several solutions, each at various levels of features, stability, and ease of use.  I tried KodingOrion, and Cloud 9.  Cloud 9 stood out as the best of the bunch with a very friendly layout, tons of supported languages, a variety of software pre-installed (Java, Python, Git, etc), and a full Linux terminal to use.

While I was able to write a powerful HTML5 music player and lay down a nice foundation for a WebGL engine all using JavaScript & HTML, it was rather painful for me.  JavaScript is not a very fun or easy language to use.  I found I was constantly fighting against the language to build even the simplest of structures.

I had briefly looked at Dart a year ago and decided that I would rather write "pure" JavaScript instead of writing in a higher level language that simply compiled down to JavaScript.  However, after looking at various benchmarks that compared Dart compiled JavaScript with native JavaScript, it made me reconsider my decision.  Another big push was from one of my co-workers who was writing a simple WebGL game using Dart.  We were able to sit down and compare Dart and JavaScript code side by side to see similarities and differences.  That convinced me to install the Dart IDE and give it a whirl.  There are some odd quirks to it since it does get compiled down to JavaScript, but for the most part it felt like C# or Java, which is great for me (10 years of C# development experience).

However, switching to Dart means that I have to resort to the old style of editing code on a specific machine and then uploading it to my server over and over.  I would prefer to use a web IDE like Cloud 9.  While Cloud 9 supports syntax highlighting for Dart, it doesn't provide the Dart VM or any way to compile the Dart code to JavaScript.

Since Cloud 9 is simply running Red Hat Enterprise Linux (RHEL), I decided to import the Dart SDK for Linux directly into a new workspace.  Unfortunately, I immediately ran into a problem.  I couldn't run the Dart VM because the binary had been compiled using GNU C Library (glibc) version 2.15.  In fact, Google uses Ubuntu 12.04 "Precise Pangolin" to compile Dart which uses glibc 2.15.  It turns out that the version of Red Hat on Cloud 9 (RHEL 6.5) only has glibc version 2.12.

I tried three different options to try and get Dart working on Cloud 9.

1) Compile Dart in a virtual machine
I downloaded Virtual Box and the latest 64-bit version of Ubuntu (13.10).  Unfortunately, Virtual Box doesn't support 64-bit OSs on my machine because it apparently doesn't have some visualization enhancements. Not only that, but I also found out that Ubuntu 13.10 uses an even higher version of glibc (2.17).

2) Compile Dart directly in Cloud 9
I figured since Cloud 9 supports Java, C, Python, Git, Subversion, etc I would just try to pull in the source directly into a Cloud 9 workspace and compile it there, using this as a guide.  I spent massive amounts of time trying to get this to work, but alas I was not successful.  I could list all of the things I tried, but in the end it simply did not work.  Whenever I would try to compile, the compiler would crash trying to compile SQLite.  I believe it has something to do with the version of the compiler (Cloud 9 has GCC v4.4.7 and Dart apparently needs 4.6.0).

3) Use a patched Dart SDK
Some people were having very similar issues to me when trying to use Dart on CentOS.  One guy built a patch that would pull in the dependencies directly from the Ubuntu repo and put them alongside the Dart SDK.  This caused all sorts of bad things to happen such as random files getting locked by Cloud 9 itself and random seg faults.

So ... I decided to go back to step 1

1 - Again) Compile Dart in a virtual machine
I downloaded the 32-bit Ubuntu 10.04, which uses glibc 2.11, and installed it in Virtual Box.  I followed this guide in order to get the latest Dart source code and build the SDK.  I then zipped up the built Dart SDK, uploaded it via FTP to my server, and then pulled it back down onto my Windows machine.  I extracted the SDK, and then uploaded it to Cloud 9.  I did have to force all of the binaries to have executable permissions, since Cloud 9 doesn't give them it by default.

I then uploaded the default "Hello World" text reversal Dart project, and wrote simple Node.js wrappers around dart2js and pub to make them easier to access.  I now have Dart compiling and running on Cloud 9!

Let me know if you have any questions or want examples/details of anything.