Skip to content

Commit

Permalink
Merge pull request fyne-io#3347 from PucklaMotzer09/darwin_package_flags
Browse files Browse the repository at this point in the history
Append CGO_CFLAGS and CGO_LDFLAGS in build of fyne command for darwin
  • Loading branch information
andydotxyz committed Oct 21, 2022
2 parents 63ddee5 + a615f84 commit ac953b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ func (b *Builder) build() error {
env := os.Environ()

if goos == "darwin" {
env = append(env, "CGO_CFLAGS=-mmacosx-version-min=10.11", "CGO_LDFLAGS=-mmacosx-version-min=10.11")
appendEnv(&env, "CGO_CFLAGS", "-mmacosx-version-min=10.11")
appendEnv(&env, "CGO_LDFLAGS", "-mmacosx-version-min=10.11")
}

if !isWeb(goos) {
Expand Down Expand Up @@ -347,3 +348,16 @@ func targetOS() string {

return runtime.GOOS
}

func appendEnv(env *[]string, varName, value string) {
for i := range *env {
keyValue := strings.SplitN((*env)[i], "=", 2)

if keyValue[0] == varName {
(*env)[i] += " " + value
return
}
}

*env = append(*env, varName+"="+value)
}
19 changes: 19 additions & 0 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,22 @@ func Test_FyneGoMod(t *testing.T) {
assert.Equal(t, j.expected, called)
}
}

func Test_AppendEnv(t *testing.T) {
env := []string{
"foo=bar",
"bar=baz",
"foo1=bar=baz",
}

appendEnv(&env, "foo2", "baz2")
appendEnv(&env, "foo", "baz")
appendEnv(&env, "foo1", "-bar")

if assert.Len(t, env, 4) {
assert.Equal(t, "foo=bar baz", env[0])
assert.Equal(t, "bar=baz", env[1])
assert.Equal(t, "foo1=bar=baz -bar", env[2])
assert.Equal(t, "foo2=baz2", env[3])
}
}

0 comments on commit ac953b0

Please sign in to comment.