Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ldflags in GOFLAGS not being respected. #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

williambrode
Copy link

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
Copy link
Member

Jacalz commented Jan 17, 2025

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
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
Copy link

kpauljoseph commented Jan 18, 2025

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
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.

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