Skip to content

Fix ldflags in GOFLAGS not being respected.#17

Closed
williambrode wants to merge 1 commit into
fyne-io:mainfrom
williambrode:fix/ldflags
Closed

Fix ldflags in GOFLAGS not being respected.#17
williambrode wants to merge 1 commit into
fyne-io:mainfrom
williambrode:fix/ldflags

Conversation

@williambrode

Copy link
Copy Markdown

extractLdflagsFromGoFlags() was not reentrant, but we were calling it a second time when building on windows. PackageWindows does another build and the second one saw an environment with the ldflags stripped out.

This doesn't work before the change (version was not set) but it work after this change.

$Env:GOFLAGS="-ldflags=-X=path/to/pkg/config.Version=v0.0.2"
fyne package -os windows -name myapp.exe -icon ./Icon.png -appBuild 1 -appVersion 1.0.0 -appID com.example.app -tags windows

@Jacalz

Jacalz commented Jan 17, 2025

Copy link
Copy Markdown
Member

Sorry for this not getting a review. I must admit that I don't quite understand what the code is trying to do or what it fixes but I hope Cedric might understand the inner workings of this tool better.

@williambrode

Copy link
Copy Markdown
Author

I'll try to restate the problem in case it helps. The issue is this code:

	if goFlags != "" {
		os.Setenv("GOFLAGS", goFlags)
	} else {
		os.Unsetenv("GOFLAGS")
	}

This CHANGES the environment - which is obviously global. If this code ever runs a second time (which it does) then it doesn't work because the environment was changed by the first run.

@kpauljoseph

kpauljoseph commented Jan 18, 2025

Copy link
Copy Markdown

extractLdflagsFromGoFlags() was not reentrant, but we were calling it a second time when building on windows. PackageWindows does another build and the second one saw an environment with the ldflags stripped out.

This doesn't work before the change (version was not set) but it work after this change.

$Env:GOFLAGS="-ldflags=-X=path/to/pkg/config.Version=v0.0.2"
fyne package -os windows -name myapp.exe -icon ./Icon.png -appBuild 1 -appVersion 1.0.0 -appID com.example.app -tags windows

@williambrode
By it not working, do you mean it is getting compiled but the version doesn't show up?
I have the same issue. After a lot of trial and error, I was able to get it compiled with fyne-cross but the ldflags for windows just wouldn't show up in the final package. I mainly wanted it for versioning, but for now, I've moved onto a generated version file at build time.

If it helps, this is the command that eventually got it compiled successfully, but it the values don't show up in the windows app.

fyne-cross windows \
    -arch=amd64,arm64 \
    -icon ./assets/icons/icon.ico \
    -ldflags=-X=github.com/kpauljoseph/notesankify/pkg/version.Version=test-v0.1.0-dirty,-X=github.com/kpauljoseph/notesankify/pkg/version.CommitSHA=edf25ee,-X=github.com/kpauljoseph/notesankify/pkg/version.BuildTime=2025-01-01-17:56:16 \
    -name "NotesAnkify" \
    -app-id "com.notesankify.app" \
    -output "NotesAnkify" \
    cmd/gui

@andydotxyz

Copy link
Copy Markdown
Member

Like Jacob I think this makes sense, but wonder if @Bluebugs is able to comment as this is an area he has battled before.

@andydotxyz

Copy link
Copy Markdown
Member

It seems like #70 does fix this issue but with a broader solution, let's go with that one.

@andydotxyz andydotxyz closed this May 24, 2026
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

Successfully merging this pull request may close these issues.

4 participants