Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-libsass does not build GOOS=linux #67

Open
weienwong opened this issue Nov 2, 2018 · 3 comments
Open

go-libsass does not build GOOS=linux #67

weienwong opened this issue Nov 2, 2018 · 3 comments

Comments

@weienwong
Copy link

weienwong commented Nov 2, 2018

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
Copy link
Member

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
Copy link

ganglio commented May 3, 2019

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

@ganglio
Copy link

ganglio commented May 9, 2019

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants