Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ libsass/*

*.o
*.lo
*.so
*.dll
*.a
a.out
libsass.js

bin/*
.deps/
.libs/
win/bin

# Final results

Expand Down
89 changes: 68 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
CC ?= cc
CC ?= gcc
CXX ?= g++
RM ?= rm -f
CP ?= cp -a
MKDIR ?= mkdir -p
CFLAGS ?= -Wall -fPIC -O2
CXXFLAGS ?= -Wall -fPIC -O2
LDFLAGS ?= -Wall -fPIC -O2
WINDRES ?= windres
CFLAGS ?= -Wall -O2
CXXFLAGS ?= -Wall -O2
LDFLAGS ?= -Wall -O2

ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
else
ifneq (,$(findstring WINDOWS,$(PATH)))
UNAME := Windows
else
ifneq (,$(findstring mingw32,$(MAKE)))
UNAME := MinGW
else
UNAME := $(shell uname -s)
endif
endif
endif

ifeq "$(LIBSASS_VERSION)" ""
ifneq "$(wildcard ./.git/ )" ""
Expand All @@ -18,8 +34,13 @@ ifneq "$(LIBSASS_VERSION)" ""
endif

# enable mandatory flag
CXXFLAGS += -std=c++0x
LDFLAGS += -std=c++0x
ifeq (MinGW,$(UNAME))
CXXFLAGS += -std=gnu++0x
LDFLAGS += -std=gnu++0x
else
CXXFLAGS += -std=c++0x
LDFLAGS += -std=c++0x
endif

ifneq "$(SASS_LIBSASS_PATH)" ""
CFLAGS += -I $(SASS_LIBSASS_PATH)
Expand All @@ -36,23 +57,14 @@ ifneq "$(EXTRA_LDFLAGS)" ""
LDFLAGS += $(EXTRA_LDFLAGS)
endif

ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
else
ifneq (,$(findstring WINDOWS,$(PATH)))
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
endif

LDLIBS = -lstdc++ -lm
ifeq ($(UNAME),Darwin)
CFLAGS += -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif

ifneq ($(BUILD), shared)
ifneq ($(BUILD),shared)
BUILD = static
endif

Expand All @@ -70,6 +82,13 @@ SASS_SPEC_SPEC_DIR ?= spec
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc
RUBY_BIN = ruby

ifeq (MinGW,$(UNAME))
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc.exe
endif
ifeq (Windows,$(UNAME))
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc.exe
endif

SOURCES = \
ast.cpp \
base64vlq.cpp \
Expand Down Expand Up @@ -108,8 +127,26 @@ SOURCES = \

CSOURCES = cencode.c

RESOURCES =

LIBRARIES = lib/libsass.so

ifeq (MinGW,$(UNAME))
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIBRARIES += lib/libsass.dll
RESOURCES += res/resource.rc
endif
else
CFLAGS += -fPIC
CXXFLAGS += -fPIC
LDFLAGS += -fPIC
endif

OBJECTS = $(SOURCES:.cpp=.o)
COBJECTS = $(CSOURCES:.c=.o)
RCOBJECTS = $(RESOURCES:.rc=.o)

DEBUG_LVL ?= NONE

Expand All @@ -128,19 +165,26 @@ debug-shared: CXXFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2
debug-shared: shared

static: lib/libsass.a
shared: lib/libsass.so
shared: $(LIBRARIES)

lib/libsass.a: $(COBJECTS) $(OBJECTS)
$(MKDIR) lib
$(AR) rvs $@ $(COBJECTS) $(OBJECTS)
$(AR) rcvs $@ $(COBJECTS) $(OBJECTS)

lib/libsass.so: $(COBJECTS) $(OBJECTS)
$(MKDIR) lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(LDLIBS)

lib/libsass.dll: $(COBJECTS) $(OBJECTS) $(RCOBJECTS)
$(MKDIR) lib
$(CXX) -shared $(LDFLAGS) -o $@ $(COBJECTS) $(OBJECTS) $(RCOBJECTS) $(LDLIBS) -s -Wl,--subsystem,windows,--out-implib,lib/libsass.a

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

%.o: %.rc
$(WINDRES) -i $< -o $@

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

Expand All @@ -160,6 +204,9 @@ install-shared: lib/libsass.so
$(SASSC_BIN): $(BUILD)
cd $(SASS_SASSC_PATH) && $(MAKE)

sassc: $(SASSC_BIN)
$(SASSC_BIN) -v

test: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) -s $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)

Expand All @@ -170,7 +217,7 @@ test_issues: $(SASSC_BIN)
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -c $(SASSC_BIN) $(LOG_FLAGS) $(SASS_SPEC_PATH)/spec/issues

clean:
$(RM) $(COBJECTS) $(OBJECTS) lib/*.a lib/*.la lib/*.so
$(RM) $(RCOBJECTS) $(COBJECTS) $(OBJECTS) $(LIBRARIES) lib/*.a lib/*.so lib/*.dll lib/*.la


.PHONY: all debug debug-static debug-shared static shared install install-static install-shared clean
.PHONY: all debug debug-static debug-shared static shared install install-static install-shared sassc clean
69 changes: 69 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
environment:
CTEST_OUTPUT_ON_FAILURE: 1
matrix:
- Compiler: mingw
Build: static
ruby_version: "21-x64"
- Compiler: mingw
Build: shared
ruby_version: "21-x64"
- Compiler: msvc
Config: Release
ruby_version: "21-x64"
- Compiler: msvc
Config: Debug
ruby_version: "21-x64"

install:
- git clone https://github.com/mgreter/sassc.git --branch feature/build-dll-win-mingw
- git clone https://github.com/sass/sass-spec.git
- set PATH=C:\Ruby%ruby_version%\bin;%PATH%
- set SASS_LIBSASS_PATH=..
- gem install minitest
- ps: |
if ($env:Compiler -eq "mingw") {
# Install MinGW.
$url = "http://sourceforge.net/projects/mingw-w64/files/"
$url += "Toolchains%20targetting%20Win64/Personal%20Builds/"
$url += "mingw-builds/4.9.2/threads-win32/seh/"
$url += "x86_64-4.9.2-release-win32-seh-rt_v3-rev0.7z/download"
Invoke-WebRequest -UserAgent wget -Uri $url -OutFile mingw.7z
&7z x -oC:\ mingw.7z > $null
}
- set PATH=C:\mingw64\bin;%PATH%
- set CC=gcc

build_script:
- ps: |
if ($env:Compiler -eq "mingw") {
mingw32-make -j4 sassc
} else {
msbuild /m:4 /p:Configuration=$env:Config win\libsass.sln
}
- ps: |
if ($env:Compiler -eq "mingw") {
sassc\bin\sassc.exe -v
ruby -v
} else {
if ($env:Config -eq "Debug") {
win\bin\Debug\sassc.exe -v
ruby -v
} else {
win\bin\sassc.exe -v
ruby -v
}
}

test_script:
- ps: |
if ($env:Compiler -eq "mingw") {
ruby sass-spec\sass-spec.rb -c sassc\bin\sassc.exe -s --ignore-todo sass-spec/spec
} else {
if ($env:Config -eq "Debug") {
echo test runner in debug mode build via msvc will throw debug assertions
echo ruby sass-spec\sass-spec.rb -c win\bin\Debug\sassc.exe -s --ignore-todo sass-spec/spec
} else {
ruby sass-spec\sass-spec.rb -c win\bin\sassc.exe -s --ignore-todo sass-spec/spec
}
}

29 changes: 27 additions & 2 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <random>
#include <set>

#ifdef __MINGW32__
#include "windows.h"
#endif

#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, path, position, backtrace)
#define ARGR(argname, argtype, lo, hi) get_arg_r(argname, env, sig, path, position, lo, hi, backtrace)
#define ARGM(argname, argtype, ctx) get_arg_m(argname, env, sig, path, position, backtrace, ctx)
Expand Down Expand Up @@ -112,12 +116,33 @@ namespace Sass {
return val;
}

#ifdef __MINGW32__
uint64_t GetSeed()
{
HCRYPTPROV hp = 0;
BYTE rb[8];
CryptAcquireContext(&hp, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptGenRandom(hp, sizeof(rb), rb);
CryptReleaseContext(hp, 0);

uint64_t seed;
memcpy(&seed, &rb[0], sizeof(seed));

return seed;
}
#else
static random_device rd;
uint64_t GetSeed()
{
return rd();
}
#endif

// note: the performance of many implementations of
// random_device degrades sharply once the entropy pool
// is exhausted. For practical use, random_device is
// generally only used to seed a PRNG such as mt19937.
static random_device rd;
static mt19937 rand(rd());
static mt19937 rand(GetSeed());

// features
static set<string> features;
Expand Down
Loading