Go: Difference between revisions
imported>Zarelit Add workaround about delve not running in vscode |
imported>Mitar Add musl static building. |
||
| Line 71: | Line 71: | ||
CFLAGS="-I${pkgs.glibc.dev}/include"; | CFLAGS="-I${pkgs.glibc.dev}/include"; | ||
LDFLAGS="-L${pkgs.glibc}/lib"; | LDFLAGS="-L${pkgs.glibc}/lib"; | ||
}; | |||
} | |||
</syntaxHighlight> | |||
== Compile go program with static compile flag (take 2) == | |||
Linking against glibc.static does not really work because glibc does not really like static linking. You get a warning like <code>warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking</code>. To really create a static build, use musl. Example based on buildGoModule example from documentation: | |||
<syntaxHighlight lang=nix> | |||
pet = buildGoModule rec { | |||
pname = "pet"; | |||
version = "0.3.4"; | |||
src = fetchFromGitHub { | |||
owner = "knqyf263"; | |||
repo = "pet"; | |||
rev = "v${version}"; | |||
sha256 = "0m2fzpqxk7hrbxsgqplkg7h2p7gv6s1miymv3gvw0cz039skag0s"; | |||
}; | |||
vendorSha256 = "1879j77k96684wi554rkjxydrj8g3hpp0kvxz03sd8dmwr3lh83j"; | |||
nativeBuildInputs = [musl]; | |||
CGO_ENABLED = 0; | |||
ldflags = [ | |||
"-linkmode external" | |||
"-extldflags '-static -L${musl}/lib'" | |||
]; | |||
meta = with lib; { | |||
description = "Simple command-line snippet manager, written in Go"; | |||
homepage = "https://github.com/knqyf263/pet"; | |||
license = licenses.mit; | |||
maintainers = with maintainers; [ kalbasit ]; | |||
}; | }; | ||
} | } | ||