Skip to content

Commit 3b7c870

Browse files
kodflowleaanthony
andauthored
[V3 Linux] aarch64 compilation (#3854)
* [V3 Linux] Add multi arch package for imageapp base quick refacto * update changelog * update changelog --------- Co-authored-by: Lea Anthony <[email protected]>
1 parent 331097f commit 3b7c870

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

mkdocs-website/docs/en/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
### Fixed
4040
- Fixed `AlwaysOnTop` not working on Mac by [leaanthony](https://github.com/leaanthony) in [#3841](https://github.com/wailsapp/wails/pull/3841)
4141
- [darwin] Fixed `application.NewEditMenu` including a duplicate `PasteAndMatchStyle` role in the edit menu on Darwin by [johnmccabe](https://github.com/johnmccabe) in [#3839](https://github.com/wailsapp/wails/pull/3839)
42+
- [linux] Fixed aarch64 compilation [#3840](https://github.com/wailsapp/wails/issues/3840) in [#3854](https://github.com/wailsapp/wails/pull/3854) by [kodflow](https://github.com/kodflow)
4243

4344
## v3.0.0-alpha.7 - 2024-09-18
4445

v3/internal/commands/appimage.go

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011
"sync"
1112

@@ -72,7 +73,18 @@ func generateAppImage(options *GenerateAppImageOptions) error {
7273
// Get the last path of the binary and normalise the name
7374
name := normaliseName(filepath.Base(options.Binary))
7475

75-
appDir := filepath.Join(options.BuildDir, name+"-x86_64.AppDir")
76+
// Architecture-specific variables using a map
77+
archDetails := map[string]string{
78+
"arm64": "aarch64",
79+
"x86_64": "x86_64",
80+
}
81+
82+
arch, exists := archDetails[runtime.GOARCH]
83+
if !exists {
84+
return fmt.Errorf("unsupported architecture: %s", runtime.GOARCH)
85+
}
86+
87+
appDir := filepath.Join(options.BuildDir, fmt.Sprintf("%s-%s.AppDir", name, arch))
7688
s.RMDIR(appDir)
7789

7890
log(p, "Preparing AppImage Directory: "+appDir)
@@ -92,27 +104,38 @@ func generateAppImage(options *GenerateAppImageOptions) error {
92104
// Download linuxdeploy and make it executable
93105
s.CD(options.BuildDir)
94106

95-
// Download necessary files
107+
// Download URLs using a map based on architecture
108+
urls := map[string]string{
109+
"linuxdeploy": fmt.Sprintf("https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-%s.AppImage", arch),
110+
"AppRun": fmt.Sprintf("https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-%s", arch),
111+
}
112+
113+
// Download necessary files concurrently
96114
log(p, "Downloading AppImage tooling")
97115
var wg sync.WaitGroup
98116
wg.Add(2)
117+
99118
go func() {
100-
if !s.EXISTS(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage")) {
101-
s.DOWNLOAD("https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage", filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"))
119+
linuxdeployPath := filepath.Join(options.BuildDir, filepath.Base(urls["linuxdeploy"]))
120+
if !s.EXISTS(linuxdeployPath) {
121+
s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath)
102122
}
103-
s.CHMOD(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"), 0755)
123+
s.CHMOD(linuxdeployPath, 0755)
104124
wg.Done()
105125
}()
126+
106127
go func() {
107128
target := filepath.Join(appDir, "AppRun")
108129
if !s.EXISTS(target) {
109-
s.DOWNLOAD("https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-x86_64", target)
130+
s.DOWNLOAD(urls["AppRun"], target)
110131
}
111132
s.CHMOD(target, 0755)
112133
wg.Done()
113134
}()
135+
114136
wg.Wait()
115137

138+
// Processing GTK files
116139
log(p, "Processing GTK files.")
117140
filesNeeded := []string{"WebKitWebProcess", "WebKitNetworkProcess", "libwebkit2gtkinjectedbundle.so"}
118141
files, err := findGTKFiles(filesNeeded)
@@ -122,48 +145,48 @@ func generateAppImage(options *GenerateAppImageOptions) error {
122145
s.CD(appDir)
123146
for _, file := range files {
124147
targetDir := filepath.Dir(file)
125-
// Strip leading forward slash
126148
if targetDir[0] == '/' {
127149
targetDir = targetDir[1:]
128150
}
129-
var err error
130151
targetDir, err = filepath.Abs(targetDir)
131152
if err != nil {
132153
return err
133154
}
134155
s.MKDIR(targetDir)
135156
s.COPY(file, targetDir)
136157
}
158+
137159
// Copy GTK Plugin
138160
err = os.WriteFile(filepath.Join(options.BuildDir, "linuxdeploy-plugin-gtk.sh"), gtkPlugin, 0755)
139161
if err != nil {
140162
return err
141163
}
142164

143165
// Determine GTK Version
144-
// Run ldd on the binary and capture the output
145166
targetBinary := filepath.Join(appDir, "usr", "bin", options.Binary)
146167
lddOutput, err := s.EXEC(fmt.Sprintf("ldd %s", targetBinary))
147168
if err != nil {
148169
println(string(lddOutput))
149170
return err
150171
}
151172
lddString := string(lddOutput)
152-
// Check if GTK3 is present
153173
var DeployGtkVersion string
154-
if s.CONTAINS(lddString, "libgtk-x11-2.0.so") {
174+
switch {
175+
case s.CONTAINS(lddString, "libgtk-x11-2.0.so"):
155176
DeployGtkVersion = "2"
156-
} else if s.CONTAINS(lddString, "libgtk-3.so") {
177+
case s.CONTAINS(lddString, "libgtk-3.so"):
157178
DeployGtkVersion = "3"
158-
} else if s.CONTAINS(lddString, "libgtk-4.so") {
179+
case s.CONTAINS(lddString, "libgtk-4.so"):
159180
DeployGtkVersion = "4"
160-
} else {
181+
default:
161182
return fmt.Errorf("unable to determine GTK version")
162183
}
184+
163185
// Run linuxdeploy to bundle the application
164186
s.CD(options.BuildDir)
165-
//log(p, "Generating AppImage (This may take a while...)")
166-
cmd := fmt.Sprintf("./linuxdeploy-x86_64.AppImage --appimage-extract-and-run --appdir %s --output appimage --plugin gtk", appDir)
187+
linuxdeployAppImage := filepath.Join(options.BuildDir, fmt.Sprintf("linuxdeploy-%s.AppImage", arch))
188+
189+
cmd := fmt.Sprintf("%s --appimage-extract-and-run --appdir %s --output appimage --plugin gtk", linuxdeployAppImage, appDir)
167190
s.SETENV("DEPLOY_GTK_VERSION", DeployGtkVersion)
168191
output, err := s.EXEC(cmd)
169192
if err != nil {
@@ -172,7 +195,7 @@ func generateAppImage(options *GenerateAppImageOptions) error {
172195
}
173196

174197
// Move file to output directory
175-
targetFile := filepath.Join(options.BuildDir, name+"-x86_64.AppImage")
198+
targetFile := filepath.Join(options.BuildDir, fmt.Sprintf("%s-%s.AppImage", name, arch))
176199
s.MOVE(targetFile, options.OutputDir)
177200

178201
log(p, "AppImage created: "+targetFile)

0 commit comments

Comments
 (0)