[v2] ldflags fix

This commit is contained in:
Lea Anthony
2021-06-27 04:18:33 +10:00
parent 9ac4990f89
commit 995d485a43

View File

@@ -228,20 +228,26 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
commands.Add("-tags")
commands.Add(tags.Join(","))
// Strip binary in Production mode
// LDFlags
ldflags := slicer.String()
if options.LDFlags != "" {
ldflags.Add(options.LDFlags)
}
if options.Mode == Production {
// Different linker flags depending on platform
commands.Add("-ldflags")
switch runtime.GOOS {
case "windows":
commands.Add("-w -s -H windowsgui")
default:
commands.Add("-w -s")
ldflags.Add("-w", "-s")
if runtime.GOOS == "windows" {
ldflags.Add("-H windowsgui")
}
}
ldflags.Deduplicate()
if ldflags.Length() > 0 {
commands.Add("-ldflags")
commands.Add(ldflags.Join(" "))
}
// Get application build directory
appDir := options.BuildDirectory
if options.CleanBuildDirectory {
@@ -251,11 +257,6 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
}
}
if options.LDFlags != "" {
commands.Add("-ldflags")
commands.Add(options.LDFlags)
}
// Set up output filename
outputFile := b.OutputFilename(options)
compiledBinary := filepath.Join(appDir, outputFile)