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

How to build using CGO_ENABLED=0 flag #12

Open
kidambisrinivas opened this issue Jan 23, 2019 · 4 comments
Open

How to build using CGO_ENABLED=0 flag #12

kidambisrinivas opened this issue Jan 23, 2019 · 4 comments

Comments

@kidambisrinivas
Copy link

How do we build a service using this library with CGO_ENABLED=0

Typically I build using this command:
CGO_ENABLED=0 GOOS=linux go build ./cmd/test_scripts

I got this error: go build github.com/myuser/myservice/vendor/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre: build constraints exclude all Go files in /home/myuser/gocode/src/github.com/myuser/myservice/vendor/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre

I tried this, but still get the same error
CGO_ENABLED=0 CGO_LDFLAGS="-lpcre" CGO_CFLAGS="-I/usr/lib/x86_64-linux-gnu" GOOS=linux go build -ldflags="-lpcre" -gcflags="-I/usr/lib/x86_64-linux-gnu" ./cmd/test_scripts

@dikki0
Copy link

dikki0 commented Feb 20, 2019

@kidambisrinivas I am struggling with the same problem. Did you maybe find another solution?

I'm trying to build this for aws Lambda, in a Serverless environment, so it cannot use any outside c functions.

@kidambisrinivas
Copy link
Author

kidambisrinivas commented Feb 20, 2019

@dikki0 I was mostly interested in support for negative look ahead regex support in Go. In the end, I used this library import github.com/h2so5/goback/regexp (source) which doesnt require libpcre++ package as a dependency. So building a static binary of my service became straightforward and worked with the same command above.

CGO_ENABLED=0 GOOS=linux go build ./cmd/test_scripts

The h2so5/goback does not guarantee linear processing time. So I switch between using native golang regex, (which supports most of PCRE) when my I dont need lookahead based regexes and h2so5/goback package when I need lookahead based regexes

@dikki0
Copy link

dikki0 commented Feb 20, 2019

Thanks for your answer.
So you found an alternative for your use case. I will check it out, see if I can use it in mine.

@Elara6331
Copy link

For anyone who comes across this later, I've made a CGo-free port of pcre2 at go.arsenm.dev/pcre. It does not build on Windows, but works on Linux and macOS (both Intel and M1).

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