Skip to content

Commit

Permalink
fix: trimpath flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed May 13, 2024
1 parent d42f38a commit 3a09396
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ By default, compile for all architecture types. You can use the flags `--os` and
~$ release ./cmd/release --arch amd64,386
```

During compilation, default ldflags include `-extldflags "-static -fpic" -s -w` as well as `trimpath`. If additional custom ldflags are needed, you can use an additional flag to append them.
During compilation, default ldflags include `-extldflags "-static -fpic" -s -w` as well as `-trimpath`. If additional custom ldflags are needed, you can use an additional flag to append them.

```shell
~$ release ./cmd/release --ldflags='-X main.Version=5.5.5'
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CGO、软浮点、生成压缩文件默认关闭
~$ release ./cmd/release --arch amd64,386
```

编译时默认已带有 `-extldflags "-static -fpic" -s -w` 以及 `trimpath` 的 ldflags,如果需要附加自定义 ldflags,可以用 flag 继续加
编译时默认已带有 `-extldflags "-static -fpic" -s -w` 以及 `-trimpath` 的 ldflags,如果需要附加自定义 ldflags,可以用 flag 继续加

```shell
~$ release ./cmd/release --ldflags='-X main.Version=5.5.5'
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
func NewBuilder(outputDir string) (*Builder, error) {
outputName := LoadBinaryName()

goBuilder := goCMD.NewBuilder(global.Config.Target)
goBuilder := goCMD.NewBuilder(global.Config.Target).TrimPath()
if !global.Config.DisableDefaultLdflags {
goBuilder = goBuilder.ProductionLdflags().TrimPath()
goBuilder = goBuilder.ProductionLdflags()
}
if global.Config.Ldflags != "" {
goBuilder = goBuilder.Ldflags(global.Config.Ldflags)
Expand Down
3 changes: 1 addition & 2 deletions pkg/goCMD/build.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package goCMD

import (
"os"
"os/exec"
"strings"
)
Expand Down Expand Up @@ -31,7 +30,7 @@ func (c BuildCommand) Run() ([]byte, error) {
}

func (c BuildCommand) TrimPath() BuildCommand {
c.args = append(c.args, "-gcflags=-trimpath="+os.Getenv("GOPATH"), "-asmflags=-trimpath="+os.Getenv("GOPATH"))
c.args = append(c.args, "-trimpath")
return c
}

Expand Down

0 comments on commit 3a09396

Please sign in to comment.