title: How to have Assetic + sass work with Symfony2 in Windows?
body: <p>I'm trying to get Assetic to run within Symfony 2.0.11 in order to use sass for css files.</p>
  
  <p>I've been fiddling around that issue for hours, and from what I gather the current assetic version (1.0.2) is screwed up and just can't work in windows.</p>
  
  <p>I tried updating assetic and asseticBundle to the latest Master version from github, but those require Symfony 2.1 which brings in a lot of changes and is not backward compatible (not to mention it's not officially released either), so that's not an option.</p>
  
  <p>This post <a href="https://stackoverflow.com/questions/8195114/symfony2-assetics-yui-compressor-on-windows-path-syntax">symfony2 assetics yui compressor on windows (path syntax)</a> gives some good insight on the matter, but unfortunately the changes on the assetic lib it recommends aren't enough to make it work properly in my environment.</p>
  
  <p>I found some interesting bits also in <a href="https://github.com/kriswallsmith/assetic/commit/5621cd449b0d85316e5872d672e7e900edc2246c" rel="nofollow noreferrer">https://github.com/kriswallsmith/assetic/commit/5621cd449b0d85316e5872d672e7e900edc2246c</a> and <a href="https://github.com/kriswallsmith/assetic/issues/25" rel="nofollow noreferrer">https://github.com/kriswallsmith/assetic/issues/25</a></p>
  
  <p>In the end, what I know is that I need to alter vendor/assetic/src/Assetic/Util/ProcessBuilder.php, maybe some other files in the package, and perhaps add some informations in my config.yml file (it seems adding the path to java or sass might help).</p>
  
  <p>What I need is for someone who was able to get a working configuration to give me pointers onto what I'm missing, or ideally the steps required to have that damn thing work.</p>
  
  <p>Anyone up to the task ?</p>
  
  <p>_____Update:
  Still digging, it's only been 3 days now :/</p>
  
  <p>New elements : </p>
  
  <p>1/ php5.3.8 may have an issue with proc_open and data > 2048 bytes as per <a href="https://bugs.php.net/bug.php?id=60120" rel="nofollow noreferrer">https://bugs.php.net/bug.php?id=60120</a>
  This issue can have implications when getting symfony from the git repository ( <a href="https://github.com/symfony/symfony/issues/3216" rel="nofollow noreferrer">https://github.com/symfony/symfony/issues/3216</a> ).
  issuing "git config --global core.autocrlf input" and re-fetching everything from git allowed me to use php5.3.10 without crash.</p>
  
  <p>2/ <a href="https://github.com/kriswallsmith/assetic/commit/5621cd449b0d85316e5872d672e7e900edc2246c" rel="nofollow noreferrer">https://github.com/kriswallsmith/assetic/commit/5621cd449b0d85316e5872d672e7e900edc2246c</a> looks like a decent basis. 
  I've maded some minor modifications on the paths in Process.php (cf <a href="https://github.com/kriswallsmith/assetic/issues/92" rel="nofollow noreferrer">https://github.com/kriswallsmith/assetic/issues/92</a> ) but I'm not really sure that is relevant.
  Anyhow, the command line I get from Assetic at this point works in a shell and outputs the expected css.</p>
  
  <p>3/ sass.bat (located in Ruby193\bin) needs to have absolute path to ruby.exe in order to go a bit further (I learnt that the hard way, you only see the error message if you var_dump and kill the script at the right place!)</p>
  
  <p>Now, things seem a bit better, but still not working with sass (I think it'd work fine with some other filters)
  I managed to isolate the issue in Process.php (around line 172) at "$data = fread($pipe, 8192);" : The second time the script passes at this place, with $pipe pointing to the second resource, it never returns... and php gets stuck and has really hard times coming out (I need to kill/restart wamp at least two times to be able to make another test)</p>
  
  <p>I'm really not familiar with proc_open and streams, and I have difficulties understanding what the code is trying to do in there...</p>
  
  <p>I hope this can help the next one trying to have things work, and eventually help my case too.
  Still looking for some support on the matter!</p>
  
  <p>_____Update:</p>
  
  <p>Further testing made me realize that I could have "php app/console assetic:dump" work when the sass file was small enough. It seems to me that the actual css rules (excluding variable definitions and mixins) need to me smaller than 4096 bytes with php5.3.10, even less with php 5.3.8. 
  That is pointing to the proc_open bug described in <a href="https://bugs.php.net/bug.php?id=60120" rel="nofollow noreferrer">https://bugs.php.net/bug.php?id=60120</a> and <a href="https://bugs.php.net/bug.php?id=51800" rel="nofollow noreferrer">https://bugs.php.net/bug.php?id=51800</a></p>
  
  <p>_____Update:</p>
  
  <p>I tried to install php5.4 to check if it was fixing the issue.
  It took me some time to realize the reason this version was not working on my computer is because there is no x64 build yet.
  I then installed the 32bits version of wamp, and got php5.4 working with it easily.
  End result : proc_open still hangs :(
  I'm beginning to be out of ideas here...</p>
  
  <hr>
  
  <h2>Walkthrough:</h2>
  
  <p>So, eventually I got this to work, and thought I'd try to sum the most important steps up for later viewers :</p>
  
  <h3>1. Have Ruby 1.9.3 and compass 0.12 installed</h3>
  
  <p>check <a href="http://rubyinstaller.org/downloads/" rel="nofollow noreferrer">http://rubyinstaller.org/downloads/</a></p>
  
  <p>Update compass to 0.12 with </p>
  
  <pre><code>"gem update --system"
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>"gem install compass"
  </code></pre>
  
  <h3>2. Alter compiler.rb in compass</h3>
  
  <p>Go to Ruby193\lib\ruby\gems\1.9.1\gems\compass-0.12.0\lib\compass 
  in line 10, replace </p>
  
  <pre><code>self.from, self.to = File.expand_path(from), to
  </code></pre>
  
  <p>with</p>
  
  <pre><code>self.from, self.to = from.gsub('./', ''), to
  </code></pre>
  
  <p>/!\ with some setup, it may be the other way around, but with the setup I'm trying to describe, it goes this way.</p>
  
  <h3>3. point Assetic to the latest version that works with symfony 2.0.11</h3>
  
  <p>edit the deps file like such :</p>
  
  <pre><code>[assetic]
      git=http://github.com/kriswallsmith/assetic.git
      ;version=v1.0.2
      version=ac71449e46bed22c276da26bf54ab2f733b3801d
  [AsseticBundle]
      git=http://github.com/symfony/AsseticBundle.git
      target=/bundles/Symfony/Bundle/AsseticBundle
      ;version=v1.0.1
      version=da4a46ce37557dcf3068b8493b12bdbbe47455e2
  </code></pre>
  
  <p>/!\ you'll need to remove the references to a specific version in the deps.lock file too !</p>
  
  <p>and issue a "php bin/vendors install". </p>
  
  <h3>4. Change your config.yml</h3>
  
  <p>here's what mine looks like now :</p>
  
  <pre><code># Assetic Configuration
  assetic:
      debug:          %kernel.debug%
      use_controller: false
      # java: /usr/bin/java
      filters:
          compass:
              bin: e:\outils\Ruby193\bin\compass.bat
  </code></pre>
  
  <h3>5. Use absolute path in compass.bat/sass.bat</h3>
  
  <p>Go to your Ruby193\bin directory and edit compass.bat to set an absolute path to ruby.exe (do the same with sass.bat while you're at it)</p>
  
  <h3>6. Change the call in template</h3>
  
  <p>Here's what mine looks like now :</p>
  
  <pre><code>{% stylesheets filter='compass' output='css/*.css'
          '@LndBimBundle/Resources/public/css/main.scss'
      %}
          &lt;link href="{{ asset_url }}" type="text/css" rel="stylesheet" /&gt;
      {% endstylesheets %}
  </code></pre>
  
  <h3>Testing :</h3>
  
  <p>For testing, you can use</p>
  
  <pre><code>php app/console assetic:dump --verbose --no-debug
  </code></pre>
  
  <p>That way if you get into an endless loop as I did, you can just ctrl+C, which makes testing way more efficient than in a browser</p>
  
  <p>/!\ You absolutely need to use --no-debug, or you'll end up with a bunch of unwanted lines in your css that look like :</p>
  
  <pre><code>@media -sass-debug-info{filename{font-family:file\:\/\/C\:\/Users\/Mattso\/AppData\/Local\/Temp\/ass9DBF\.tmp\.scss}line{font-family:\0000359}}
  </code></pre>
  
  <p>You can use </p>
  
  <pre><code>die($this-&gt;commandline);
  </code></pre>
  
  <p>in the run method of</p>
  
  <pre><code>vendor\assetic\src\Assetic\Util\Process.php
  </code></pre>
  
  <p>to show you the current command line, and test it.</p>
  
  <p>Mine currently looks like this :</p>
  
  <pre><code>cmd /V:ON /E:ON /C ""e:\outils\Ruby193\bin\compass.bat" "compile" "C:\Users\Mattso\AppData\Local\Temp" "--config" "C:\Users\Mattso\AppData\Local\Temp\ass59BB.tmp" "--sass-dir" "" "--css-dir" "" "C:\Users\Mattso\AppData\Local\Temp\ass59BC.tmp.scss""
  </code></pre>
  
  <p>Then you just need to type "php app/console assetic:dump --no-debug" in your cli to create the css files in web\css and refresh your site's page. Et... voila! (hopefully!)</p>
  
  <p>Note: As you may have noticed, I'm using the CompassFilter instead of the SassFilter. That is because it does the same thing (and more) and can actually be made to do what we expect of it. If anyone can find out how to fix the SassFilter, that would be swell. Meanwhile I already spent way too much time on this.</p>
  
  <p>I've been pulling my hair for days on that crazyness, I hope this post will be helpful to some other people's mental health ;)</p>