6
6
"fmt"
7
7
"os"
8
8
"path/filepath"
9
+ "runtime"
9
10
"strings"
10
11
"sync"
11
12
@@ -72,7 +73,18 @@ func generateAppImage(options *GenerateAppImageOptions) error {
72
73
// Get the last path of the binary and normalise the name
73
74
name := normaliseName (filepath .Base (options .Binary ))
74
75
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 ))
76
88
s .RMDIR (appDir )
77
89
78
90
log (p , "Preparing AppImage Directory: " + appDir )
@@ -92,27 +104,38 @@ func generateAppImage(options *GenerateAppImageOptions) error {
92
104
// Download linuxdeploy and make it executable
93
105
s .CD (options .BuildDir )
94
106
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
96
114
log (p , "Downloading AppImage tooling" )
97
115
var wg sync.WaitGroup
98
116
wg .Add (2 )
117
+
99
118
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 )
102
122
}
103
- s .CHMOD (filepath . Join ( options . BuildDir , "linuxdeploy-x86_64.AppImage" ) , 0755 )
123
+ s .CHMOD (linuxdeployPath , 0755 )
104
124
wg .Done ()
105
125
}()
126
+
106
127
go func () {
107
128
target := filepath .Join (appDir , "AppRun" )
108
129
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 )
110
131
}
111
132
s .CHMOD (target , 0755 )
112
133
wg .Done ()
113
134
}()
135
+
114
136
wg .Wait ()
115
137
138
+ // Processing GTK files
116
139
log (p , "Processing GTK files." )
117
140
filesNeeded := []string {"WebKitWebProcess" , "WebKitNetworkProcess" , "libwebkit2gtkinjectedbundle.so" }
118
141
files , err := findGTKFiles (filesNeeded )
@@ -122,48 +145,48 @@ func generateAppImage(options *GenerateAppImageOptions) error {
122
145
s .CD (appDir )
123
146
for _ , file := range files {
124
147
targetDir := filepath .Dir (file )
125
- // Strip leading forward slash
126
148
if targetDir [0 ] == '/' {
127
149
targetDir = targetDir [1 :]
128
150
}
129
- var err error
130
151
targetDir , err = filepath .Abs (targetDir )
131
152
if err != nil {
132
153
return err
133
154
}
134
155
s .MKDIR (targetDir )
135
156
s .COPY (file , targetDir )
136
157
}
158
+
137
159
// Copy GTK Plugin
138
160
err = os .WriteFile (filepath .Join (options .BuildDir , "linuxdeploy-plugin-gtk.sh" ), gtkPlugin , 0755 )
139
161
if err != nil {
140
162
return err
141
163
}
142
164
143
165
// Determine GTK Version
144
- // Run ldd on the binary and capture the output
145
166
targetBinary := filepath .Join (appDir , "usr" , "bin" , options .Binary )
146
167
lddOutput , err := s .EXEC (fmt .Sprintf ("ldd %s" , targetBinary ))
147
168
if err != nil {
148
169
println (string (lddOutput ))
149
170
return err
150
171
}
151
172
lddString := string (lddOutput )
152
- // Check if GTK3 is present
153
173
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" ):
155
176
DeployGtkVersion = "2"
156
- } else if s .CONTAINS (lddString , "libgtk-3.so" ) {
177
+ case s .CONTAINS (lddString , "libgtk-3.so" ):
157
178
DeployGtkVersion = "3"
158
- } else if s .CONTAINS (lddString , "libgtk-4.so" ) {
179
+ case s .CONTAINS (lddString , "libgtk-4.so" ):
159
180
DeployGtkVersion = "4"
160
- } else {
181
+ default :
161
182
return fmt .Errorf ("unable to determine GTK version" )
162
183
}
184
+
163
185
// Run linuxdeploy to bundle the application
164
186
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 )
167
190
s .SETENV ("DEPLOY_GTK_VERSION" , DeployGtkVersion )
168
191
output , err := s .EXEC (cmd )
169
192
if err != nil {
@@ -172,7 +195,7 @@ func generateAppImage(options *GenerateAppImageOptions) error {
172
195
}
173
196
174
197
// 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 ) )
176
199
s .MOVE (targetFile , options .OutputDir )
177
200
178
201
log (p , "AppImage created: " + targetFile )
0 commit comments