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

Build Caddy statically without CGO #17

Closed
qdm12 opened this issue May 22, 2020 · 7 comments
Closed

Build Caddy statically without CGO #17

qdm12 opened this issue May 22, 2020 · 7 comments

Comments

@qdm12
Copy link

qdm12 commented May 22, 2020

Hello,

When trying to build Caddy statically (with CGO_ENABLED=0 and without gcc), using:

docker run -it --rm -w /tmp/caddy golang:1.14-alpine3.11
apk add git
export CGO_ENABLED=0
export GO111MODULE=on
go get github.com/caddyserver/xcaddy/cmd/xcaddy@master
xcaddy build v2.0.0

I obtain the errors:

2020/05/22 13:55:03 [INFO] Temporary folder: /tmp/buildenv_2020-05-22-1355.280615980
2020/05/22 13:55:03 [INFO] Writing main module: /tmp/buildenv_2020-05-22-1355.280615980/main.go
2020/05/22 13:55:03 [INFO] Initializing Go module
2020/05/22 13:55:03 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy
go: creating new go.mod: module caddy
2020/05/22 13:55:03 [INFO] Pinning versions
2020/05/22 13:55:03 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2@v2.0.0 
2020/05/22 13:55:04 [INFO] Build environment ready
2020/05/22 13:55:04 [INFO] Building Caddy
2020/05/22 13:55:04 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /tmp/caddy/caddy -ldflags -w -s -trimpath 
# runtime/cgo
exec: "gcc": executable file not found in $PATH
2020/05/22 13:55:04 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-05-22-1355.280615980
2020/05/22 13:55:04 [FATAL] exit status 2

Any idea how I can solve that? Or is this related to xcaddy? Or one of the dependencies?

Thanks!

@mholt
Copy link
Member

mholt commented May 22, 2020

Looks like it's not actually being disabled, try doing the same thing without Docker. Sorry though, I don't use Docker so I don't know how to help. Try asking on our forums instead. If this is a bug in xcaddy we can reopen this though.

@mholt mholt closed this as completed May 22, 2020
@qdm12
Copy link
Author

qdm12 commented May 22, 2020

This is definitely not related to Docker though.

Can you try on your machine:

CGO_ENABLED=0 xcaddy build v2.0.0
ldd caddy

To see if it's actually built statically? Thanks!

@mholt
Copy link
Member

mholt commented May 22, 2020

@qdm12 What is the output for you? (I don't have ldd on my Mac so I need to find a workaround in the meantime.)

@qdm12
Copy link
Author

qdm12 commented May 22, 2020

Maybe try on osx:

otool -L caddy

I can compile it if I have gcc installed (even with CGO_ENABLED=0). Running ldd caddy on it gives me the corresponding C library (on alpine it's musl).

Note that compiling Go programs (and caddy 1.0.x) statically works apart from that so my guess is it has something to do with xcaddy 🤔

I will try building Caddy 2 statically without xcaddy to make sure it's on xcaddy's side.

@mholt
Copy link
Member

mholt commented May 22, 2020

@qdm12 Thanks for the tip, that made it pretty quick. Try the latest from master if you please?

@qdm12
Copy link
Author

qdm12 commented May 22, 2020

Yep it works! Thanks!! 👍

EDIT: What was the cause in the end, out of curiosity?

@mholt
Copy link
Member

mholt commented May 22, 2020

@qdm12 You can see the fix in a1e17ca - I wasn't converting from true/false to 1/0.

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

2 participants