Go wrapper for libsass, the only Sass 3.5 compiler for Go

libsass

Circle CI Build status

The only Sass compliant Go library! go-libsass is a wrapper to the sass/libsass project.

To build, setup Go

go build

To test

go test

Basic example more examples found in examples

buf := bytes.NewBufferString("div { p { color: red; } }")
if err != nil {
	log.Fatal(err)
}
comp, err := libsass.New(os.Stdout, buf)
if err != nil {
	log.Fatal(err)
}

if err := comp.Run(); err != nil {
	log.Fatal(err)
}

Output

div p {
  color: red; }

Updating libsass

cd libsass-src; git fetch; git checkout vX.X.X
git commit -m "updated libsass to vX.X.X"
make update-libsass
# iterate on includes and code changes until tests pass

FAQ

  • Compiling go-libsass is very slow, what can be done?

    Go-libsass compiles C/C++ libsass on every build. You can install the package and speed up building go install github.com/wellington/go-libsass. Alternatively, it's possible to link against system libsass and forego C compiling with go build -tags dev.

  • How do I cross compile?

    Since this package uses C bindings, you will need gcc for the target platform. For windows see, https://github.com/wellington/go-libsass/issues/37

Comments
  • "out_of_memory" redefined

    From a clean go-get:

    $ go get github.com/wellington/go-libsass/
    # github.com/wellington/go-libsass/libs
    In file included from unity.cpp:22:0:
    ../libsass-build/json.cpp:49:0: warning: "out_of_memory" redefined
     #define out_of_memory() do {                    \
     
    In file included from ../libsass-build/ast.hpp:52:0,
                     from ../libsass-build/ast.cpp:2,
                     from unity.cpp:4:
    ../libsass-build/util.hpp:15:0: note: this is the location of the previous definition
       #define out_of_memory() do {            \
    
  • Concurrent task cancels out

    Concurrent task cancels out

    Hi,

    I was trying to set concurrency with this package and a simple copy task. It seems like go-libsass "cancels" other concurrencies.

    Here are my routines and here is the code calling go-libsass.

  • Using imports

    Using imports

    I'm trying to provide Imports to my compiler and have not been able to see a way to do this through the API.

    Is this possible through the high level API?

  • Use of unexported `option` type makes it hard to wrap

    Use of unexported `option` type makes it hard to wrap

    The type option is unexported and yes necessary to use when calling libsass.New. I'm looking for a way around this - so far reflection seems like the only choice, but if I want to dynamically choose which set of options I am using, I don't seem to have any other choice than to explicitly make a big switch statement with all of my possible libsass.New() call variations, since I cannot make for example a slice of option.

    I realize this was probably done following the pattern of some other library and in order to not export unnecessary types. But I do think this is not a great design choice. It makes it really hard to compose a custom set of options based on whatever logic (I'm trying to write a command line wrapper around this - here: https://github.com/vugu/vgsassc) and I don't think that was the intention.

    Would you consider making option into Option ?

  • c compiling failes with `invalid flag in #cgo CPPFLAGS: -w`

    c compiling failes with `invalid flag in #cgo CPPFLAGS: -w`

    I get this with Go v1.9.4 and gcc v7.3.0.

    Happens on go install github.com/wellington/go-libsass and on compilation when used in my project: go build github.com/wellington/go-libsass/libs: invalid flag in #cgo CPPFLAGS: -w

    Linking against system libsass with the dev tag works fine.

  • Issue with IncludePaths

    Issue with IncludePaths

    Hey!

    I'm rewriting my Webpack/Gulp compiler in Go and I've run into an issue, when using the IncludePaths functionality of go-libsass.

    What

    My tree looks like this:

    .
    ├── css
    │   └── style.css
    ├── node_modules
    │   └── bourbon
    │   │   └── *
    │   └── susy
    │   │   └── sass
    │   │   │   └── *.scss
    ├── scss
    │   └── style.scss
    │   └── _variables.scss
    └── main.go
    

    The main.go file, has the following code implemented:

    		fi, err := os.Open("scss/style.scss")
    		if err != nil {
    			return err
    		}
    		defer fi.Close()
    
    		fo, err := os.Create("css/style.css")
    		if err != nil {
    			return err
    		}
    		defer fo.Close()
    
    		p := libsass.IncludePaths([]string{"scss", "node_modules/bourbon/app/assets/stylesheets", "node_modules/susy/sass"})
    		s := libsass.OutputStyle(libsass.COMPRESSED_STYLE)
    
    		comp, err := libsass.New(fo, fi, p, s)
    		if err != nil {
    			return err
    		}
    
    		if err := comp.Run(); err != nil { # This line fails on me.
    			return err
    		}
    

    The style.scss file, is simple.

    @import "variables";
    @import "bourbon";
    @import "susy";
    

    And then, when I execute go run main.go, I get the following:

    panic: Error > stdin:5
    File to import not found or unreadable: variables
    Parent style sheet: stdin
    @import "variables";
    @import "bourbon";
    @import "susy";
    
    
    goroutine 1 [running]:
    main.main()
            main.go:85 +0xdb
    exit status 2
    

    Possibility

    I suspect, that the go-libsass may have a problem, when (for example), susy will contain it's own variables file.

    I'm probably configuring something wrong, in which case it would be nice to see some documentation on this :)

    Any feedback on this would be great.

    Thanks!

  • Custom import resolution

    Custom import resolution

    First, thanks for this library, it works great.

    I'm the lead maintainer of Hugo (https://github.com/gohugoio/hugo) and I'm about to add SASS support to Hugo via go-libsass/libsass. I hope we can switch out that with a native Go library eventually, but after thinking hard, I concluded that I/we really need this now.

    I have a very convincing demo of this working in Hugo (https://twitter.com/GoHugoIO/status/1007361748201037824) -- but I have one problem that I would really like to solve to get this where I want it.

    In Hugo we have a layered and virtual filesystem with a well defined order (project, themes). Setting IncludePaths with a list of these directories works mostly as I want, but LibSass seems to always prefer the local relative import if present.

    I know which import should be picked, so if I could hook in a "import resolver" func given the file path and import path, I could provide the correct import filename.

    Looking at the LibSass API, it looks like this should be possible, but I would appreciate any help/hint in this area.

  • No sass support...?

    No sass support...?

    Am I wrong in assuming this library does not support sass? And instead only supports scss? All of the tests are scss only, so perhaps it's broken, but only scss will compile.

    Reproducing the problem: a sass file with this, for example:

    html
      font-family: 'MonoSocial'
    

    Will produce the following error:

    [ERROR]: Error > stdin:3
    Invalid CSS after "html": expected 1 selector or at-rule, was "font-family: 'MonoS"
    @import "settings"
    
    html
      font-family: 'MonoSocial'
    
  • Errors executing tests on Go 1.5

    Errors executing tests on Go 1.5

    Go tests are failing on Windows like here: https://ci.appveyor.com/project/drewwells/go-libsass/build/157. It is likely related to https://github.com/golang/go/issues/11710.

    Related: https://github.com/wellington/go-libsass/pull/16

  • [error] could not determine kind of name for C.sass_context_get_included_files_size

    [error] could not determine kind of name for C.sass_context_get_included_files_size

    go get github.com/wellington/go-libsass fails with the following error:

    golang ❱ go get -u github.com/wellington/go-libsass
    # github.com/wellington/go-libsass
    could not determine kind of name for C.sass_context_get_included_files_size
    

    Any idea what's going on?

    golang ❱ go version
    go version go1.4.2 darwin/amd64
    
    golang ❱ brew install autoconf automake libtool mercurial pkg-config
    Warning: autoconf-2.69 already installed
    Warning: automake-1.15 already installed
    Warning: pkg-config-0.28 already installed
    Error: libtool-2.4.5 already installed
    To install this version, first `brew unlink libtool'
    Error: mercurial-3.3 already installed
    To install this version, first `brew unlink mercurial'
    
  • Error marshalling fails on 32-bit systems

    Error marshalling fails on 32-bit systems

    I'm running a test build across all arches using 0.9.2, and it fails 3 tests on 32-bit systems (i686 and armv7hl):

    --- FAIL: TestUnmarshalError (0.00s)
        encoding_test.go:78: got:  wanted: error message
    --- FAIL: TestMarshalError (0.00s)
        encoding_test.go:265: got:
            
            wanted:
            error has been thrown
    --- FAIL: TestError_simple (0.00s)
        export_test.go:28: got:  wanted: help me
    

    These are all tests that attempt to marshal and unmarshal an error. It does not appear to matter whether I build with the bundled libsass or a system one.

  • Update libsass to avoid warnings

    Update libsass to avoid warnings

    Warning:

    ../../gocode/pkg/mod/github.com/wellington/[email protected]/libs/../libsass-build/cencode.c:50:5: warning: declaration does not declare anything [-Wmissing-declarations]

    Related to: libsass issue 2690

  • Possible memory leak?

    Possible memory leak?

    I've been using go-libsass to compile sass content for static sites in a long-running process, and believe I'm seeing a memory leak in the library.

    I put together a small program to exercise this:

    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"log"
    	"runtime"
    	"strings"
    	"time"
    
    	humanize "github.com/dustin/go-humanize"
    	libsass "github.com/wellington/go-libsass"
    )
    
    func main() {
    	var (
    		sample = `
    $font-stack:    Helvetica, sans-serif;
    $primary-color: #333;
    body {
    	font: 100% $font-stack;
    	color: $primary-color;
    }
    		`
    		maxAlloc uint64
    		start    = time.Now()
    	)
    	for i := 0; true; i++ {
    		comp, err := libsass.New(ioutil.Discard, strings.NewReader(sample))
    		if err != nil {
    			log.Fatal(err)
    		}
    
    		if err := comp.Run(); err != nil {
    			log.Fatal(err)
    		}
    		var m runtime.MemStats
    		runtime.ReadMemStats(&m)
    		if m.Alloc > maxAlloc*2 {
    			maxAlloc = m.Alloc
    			fmt.Printf(
    				"%v (%d): Alloc = %v MiB, NumGC = %v\n",
    				time.Since(start),
    				i,
    				humanize.Bytes(maxAlloc),
    				m.NumGC,
    			)
    		}
    	}
    }
    

    Running using go-libsass v0.9.2 I see the following output after running for 10 minutes:

    1.839078ms (0): Alloc = 106 kB MiB, NumGC = 0
    21.184192ms (26): Alloc = 215 kB MiB, NumGC = 0
    55.547495ms (79): Alloc = 432 kB MiB, NumGC = 0
    109.932748ms (186): Alloc = 868 kB MiB, NumGC = 0
    206.257662ms (400): Alloc = 1.7 MB MiB, NumGC = 0
    713.857603ms (1563): Alloc = 3.5 MB MiB, NumGC = 1
    4.377593582s (9946): Alloc = 7.0 MB MiB, NumGC = 16
    8.849047488s (19345): Alloc = 14 MB MiB, NumGC = 24
    22.658077622s (40564): Alloc = 28 MB MiB, NumGC = 33
    46.552797916s (78313): Alloc = 56 MB MiB, NumGC = 41
    1m38.739205546s (165444): Alloc = 111 MB MiB, NumGC = 50
    2m59.728412134s (318347): Alloc = 223 MB MiB, NumGC = 58
    6m5.303138905s (660328): Alloc = 446 MB MiB, NumGC = 67
    

    Is there a step I'm missing to release resources? Or is there something that needs adding to the Run() function?

  • Tag a new release?

    Tag a new release?

    I wonder if it would be possible to tag a new release sometime soon?

    Mostly because https://github.com/bep/go-tocss is pinning a random version of master, and uses API that is not released.

  • go-libsass does not build GOOS=linux

    go-libsass does not build GOOS=linux

    I am running this on go version go1.11.1 darwin/amd64 on Mac OS High Sierra v.10.13.6

    This is the code I am trying to run through go build

    package main
    
    import (
    	"bytes"
    	"log"
    	"os"
    
    	libsass "github.com/wellington/go-libsass"
    )
    
    func main() {
    	buf := bytes.NewBufferString("div { p { color: red; } }")
    
    	comp, err := libsass.New(os.Stdout, buf)
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	if err := comp.Run(); err != nil {
    		log.Fatal(err)
    	}
    
    }
    
    

    When I compile the above file using go build -tags dev, I'm able to run the outputted binary. However when I run GOOS=linux go build

    I receive the following error. We need the GOOS flag set to linux because the app is being deployed to a Linux Docker Image. There should not be any correlation between the struct SassNumber and the output OS.

    # github.com/wellington/go-libsass/libs
    ../../wellington/go-libsass/libs/sass_number.go:8:9: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:151:10: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:153:9: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:157:10: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:159:9: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:164:10: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:166:9: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:170:10: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:175:28: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:186:24: undefined: SassNumber
    ../../wellington/go-libsass/libs/sass_number.go:166:9: too many errors
    
  • Silent crashes

    Silent crashes

    I'm running this in my go1.10 project in docker (alpine linux) and it started crashing with the latest master so I moved it back to fd1a2294913da5d31ccc8eea2556ccd07f89a4c8 which is working fine. Still not sure where the problem lies, but likely between commmits fdbf3052799586f07de4ffee8ca11b4f7e8bcfb4 and da42dc7f85c0d4b772af5e0a8decf6ab4e409ccb.

    I was able to mitigate in one scenario without rolling back and that was by removing nested imports and just importing from the top level file.

Golang CS:GO external base. Development currently halted due to compiler/runtime Golang bugs.

gogo Golang CS:GO External cheat/base. Also, my first Golang project. Wait! Development momentarily halted due to compiler/runtime bugs. Disclaimer Th

Jun 25, 2022
golang script for bypass AV and work only in windows platform
golang script for bypass AV and work only in windows platform

antivirus bypass protection requirements golang installed usage 1 - create your payload go run create.go <ip> <port> <secret> <any url>

Nov 9, 2022
A simple wrapper to daemonize Go applications.

daemonigo A simple library to daemonize Go programming language applications. Installing $ go get github.com/tyranron/daemonigo After this command da

Jul 15, 2022
Some helper types for go1: priority queue, slice wrapper.

go-villa Package villa contains some helper types for Go: priority queue, slice wrapper, binary-search, merge-sort. GoDoc Link: http://godoc.org/githu

Apr 24, 2021
A wrapper for the Wandbox API, written in Golang!

GoWandBox A simple wrapper for the WandBox API, written in Golang! Documentation can be found at classpythonaddike.github.io/gowandbox/ Note: This wra

Sep 19, 2021
singleflight wrapper supporting contexts

contextflight contextflight is a thin wrapper around singleflight that adds context handling. It works like singleflight, with the addition that the p

Nov 9, 2022
rsync wrapper (or output parser) that pushes metrics to prometheus

rsync-prom An rsync wrapper (or output parser) that pushes metrics to prometheus. This allows you to then build dashboards and alerting for your rsync

Dec 11, 2022
GoSetProcessAffinity as a wrapper with GUI
GoSetProcessAffinity as a wrapper with GUI

GoSetProcessAffinity as a wrapper with GUI basically this is a configuration tool for the IFEO settings. Settings that go beyond the IFEO are done via

Sep 24, 2022
Testing the use of a golang wrapper around UserMode Linux for making stdin

This code is for testing the use of a golang wrapper around UserMode Linux for making stdin, stdout and stderr available to attach, detach and reattach to from the host using Unix sockets.

Dec 24, 2021
Rusprofile wrapper with golang

Rusprofile Wrapper Запуск docker-compose up Описание Swagger http://localhost:8080/swagger/ Можно было бы брать данные здесь: https://www.rusprofile.r

Nov 24, 2021
Interkassa api wrapper in golang.

Golang https://interkassa.com/ api wrapper (WIP) Как использовать Создаём кассу package main import ( "net/http" "time" "github.com/qystishere/in

Jun 30, 2022
A dead simple Go wrapper around the hidden moonarch.app API.

moonarch A dead simple Go wrapper around the hidden moonarch.app API. How-To First, get the repository: go get github.com/lazdotdigital/moonarch. moon

Nov 27, 2021
Tiny 10MinuteMail wrapper for Go.

tmm Tiny package that uses 10MinuteMail to generate temporary email addresses. Zero dependancies. Supports receiving, forwarding and replying to messa

Nov 29, 2021
A simple Via CEP Wrapper to demonstrate GoLang tests usage

via-cep-wrapper A simple Via CEP Wrapper to demonstrate GoLang tests usage Purpose Demonstrate how struct services could make easy to build and test a

May 18, 2022
Go API wrapper for Greenhouse.io API

Greenhouse IO A Go interface to Greenhouse.io's API Useage Creating the Client NewClient accepts: A context; used for any HTTP requests made using the

Jan 14, 2022
Executor - Wrapper for exec.Command for simple using and multi commands executing

executor Examples package main import ( "fmt" "github.com/solar-jsoc/execut

Feb 12, 2022
Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.

Babygo, a go compiler made from scratch Babygo is a small and simple go compiler. (Smallest and simplest in the world, I believe.) It is made from scr

Jan 8, 2023
Compiler as a Service is a compiler that is available over http/https and gRPC

BlakBoks(CaaS) Elasticsearch but for compiling untrusted code Compiler as a Service is a compiler that is available over http/2 and gRPC. Setup First

Nov 24, 2021
ReCT-Go-Compiler - A compiler for the ReCT programming language written in Golang

ReCT-Go-Compiler A compiler for the ReCT programming language written in Golang

Nov 30, 2022
ReCT-Go-Compiler - A compiler for the ReCT programming language written in Golang

ReCT-Go-Compiler A compiler for the ReCT programming language written in Golang

Nov 30, 2022