mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
buildGoModule/buildGoPackage: Introduce ldflags argument
Previously it was not possible to define multiple ldflags, since only the last definition applies, and there's some quoting issues with `buildFlagsArray`. With the new `ldflags` argument it's possible to do this, e.g. ldflags = drv.ldflags or [] ++ [ "-X main.Version=1.0" ] can now properly append a flag without clearing all previous ldflags.
This commit is contained in:
parent
99697d891d
commit
155ae682a5
3 changed files with 19 additions and 10 deletions
|
@ -114,21 +114,24 @@ Both `buildGoModule` and `buildGoPackage` can be tweaked to behave slightly diff
|
|||
|
||||
### `buildFlagsArray` and `buildFlags`: {#ex-goBuildFlags-noarray}
|
||||
|
||||
These attributes set build flags supported by `go build`. We recommend using `buildFlagsArray`. The most common use case of these attributes is to make the resulting executable aware of its own version. For example:
|
||||
These attributes set build flags supported by `go build`. We recommend using `buildFlagsArray`.
|
||||
|
||||
```nix
|
||||
buildFlagsArray = [
|
||||
# Note: single quotes are not needed.
|
||||
"-ldflags=-X main.Version=${version} -X main.Commit=${version}"
|
||||
"-tags=release"
|
||||
];
|
||||
```
|
||||
|
||||
### `ldflags` {#var-go-ldflags}
|
||||
|
||||
Arguments to pass to the Go linker tool via the `-ldflags` argument of `go build`. The most common use case for this argument is to make the resulting executable aware of its own version. For example:
|
||||
|
||||
```nix
|
||||
buildFlagsArray = ''
|
||||
-ldflags=
|
||||
-X main.Version=${version}
|
||||
-X main.Commit=${version}
|
||||
'';
|
||||
ldflags = [
|
||||
"-s" "-w"
|
||||
"-X main.Version=${version}"
|
||||
"-X main.Commit=${version}"
|
||||
];
|
||||
```
|
||||
|
||||
### `deleteVendor` {#var-go-deleteVendor}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue