build-on-windows.md 4.7 KB

We support builds via MingGW and via Visual Studio Community 2013. Both should be considered experimental (MinGW was better tested)!

Building via MingGW (makefiles)

First grab the latest MinGW for windows installer. Once it is installed, you can click on continue or open the Installation Manager via bin\mingw-get.exe.

You need to have the following components installed:

Visualization of components installed in the interface

Next we need to install git for windows. You probably want to check the option to add it to the global path, but you do not need to install the unix tools.

If you want to run the spec test-suite you also need ruby and a few gems available. Grab the latest installer and make sure to add it the global path. Then install the missing gems:

gem install minitest

Mount the mingw root directory

As mentioned in the MinGW Getting Started guide, you should edit C:\MinGW\msys\1.0\etc\fstab to contain the following line:

C:\MinGW   /mingw

Starting a "MingGW" console

Create a batch file with this content:

@echo off
set PATH=C:\MinGW\bin;%PATH%
REM only needed if not already available
set PATH=%PROGRAMFILES%\git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd

Execute it and make sure these commands can be called: git, mingw32-make, rm and gcc! Once this is all set, you should be ready to compile libsass!

Get the sources

# using git is preferred
git clone https://github.com/sass/libsass.git
# only needed for sassc and/or testsuite
git clone https://github.com/sass/sassc.git libsass/sassc
git clone https://github.com/sass/sass-spec.git libsass/sass-spec

Decide for static or shared library

libsass can be built and linked as a static or as a shared library. The default is static. To change it you can set the BUILD environment variable:

set BUILD="shared"

Compile the library

mingw32-make -C libsass

Results can be found in

$ ls libsass/lib
libsass.a  libsass.dll  libsass.so

Run the spec test-suite

mingw32-make -C libsass test_build

Building via MingGW 64bit (makefiles)

Building libass to dll on window 64bit.

@echo off
set PATH=C:\mingw64\bin;%PATH%
set CC=gcc
REM only needed if not already available
set PATH=%PROGRAMFILES%\Git\bin;%PATH%
REM C:\MinGW\msys\1.0\msys.bat
cmd
  • By default , mingw64 dll will depends on "​m​i​n​g​w​m​1​0​.​d​l​l​、​ ​l​i​b​g​c​c​​s​​d​w​2​-​1​.​d​l​l​" , we can modify Makefile to fix this:(add "-static")
lib/libsass.dll: $(COBJECTS) $(OBJECTS) $(RCOBJECTS)
    $(MKDIR) lib
    $(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(RCOBJECTS) $(LDLIBS) -s -static -Wl,--subsystem,windows,--out-implib,lib/libsass.a
  • Compile the library
mingw32-make -C libsass

By the way , if you are using java jna , JNAerator is a good tool.

Building via Visual Studio Community 2013

Open a Visual Studio 2013 command prompt:

  • VS2013 x86 Native Tools Command Prompt

Note: When I installed the community edition, I only got the 2012 command prompts. I copied them from the Startmenu to the Desktop and adjusted the paths from Visual Studio 11.0 to Visual Studio 12.0. Since libsass uses some C++11 features, you need at least a MSVC 2013 compiler (v120).

Get the source

# using git is preferred
git clone https://github.com/sass/libsass.git
git clone https://github.com/sass/sassc.git libsass/sassc
# only needed if you want to run the testsuite
git clone https://github.com/sass/sass-spec.git libsass/sass-spec

Compile sassc

Sometimes msbuild seems not available from the command prompt. Just search for it and add it to the global path. It seems to be included in the .net folders too.

cd libsass
REM set PATH=%PATH%;%PROGRAMFILES%\MSBuild\12.0\Bin
msbuild /m:4 /p:Configuration=Release win\libsass.sln
REM running the spec test-suite manually (needs ruby and minitest gem)
ruby sass-spec\sass-spec.rb -V 3.5 -c win\bin\sassc.exe -s --impl libsass sass-spec/spec
cd ..