wellington / go-libsass

Go wrapper for libsass, the only Sass 3.5 compiler for Go
http://godoc.org/github.com/wellington/go-libsass
Apache License 2.0
205 stars 28 forks source link

go-libsass does not build GOOS=linux #67

Open weienwong opened 5 years ago

weienwong commented 5 years ago

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
drewwells commented 5 years ago

go-libsass uses cgo. It's awful but the underlying compiler has been very challenging to rebuild in go. If you want to look at a pure Go compiler check out: https://github.com/wellington/sass

Anyways, your issue is that you need to compile the c code against linux libraries.

ganglio commented 5 years ago

@weienwong I'm having the same issue. Did you find any workaround?

ganglio commented 5 years ago

Quick update. I managed to build it using the following dockerfile:

FROM golang:1.12-alpine as builder
RUN apk add git gcc g++ libsass-dev
RUN mkdir -p /app
COPY . /app
WORKDIR /app
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags "-linkmode external -extldflags -static"