Skip to content

Commit b1720e9

Browse files
zephylacPierre Champion
authored and
Pierre Champion
committed
Fixed broken symlink & added icudtl.dat download (#33)
Download the icudtl.dat /w the engine. Everything is now in the same directory.
1 parent eba7878 commit b1720e9

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

example/simpleDemo/engineDownloader.go

+61-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import (
1919
"time"
2020
)
2121

22+
func createSymLink(symlink string, file string) {
23+
24+
os.Remove(symlink)
25+
26+
err := os.Symlink(file, symlink)
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
}
31+
2232
// Unzip will decompress a zip archive, moving all files and folders
2333
// within the zip file (parameter 1) to an output directory (parameter 2).
2434
func unzip(src string, dest string) ([]string, error) {
@@ -128,7 +138,7 @@ func printDownloadPercent(done chan int64, path string, total int64) {
128138
size = 1
129139
}
130140

131-
var percent float64 = float64(size) / float64(total) * 100
141+
var percent = float64(size) / float64(total) * 100
132142

133143
// We use `\033[2K\r` to avoid carriage return, it will print above previous.
134144
fmt.Printf("\033[2K\r %.0f %% / 100 %%", percent)
@@ -154,6 +164,7 @@ func downloadFile(filepath string, url string) error {
154164
os.Exit(0)
155165
}
156166
}
167+
157168
start := time.Now()
158169

159170
// Create the file
@@ -242,45 +253,85 @@ func main() {
242253
}
243254

244255
var platform = "undefined"
245-
var downloadURL = ""
256+
var downloadShareLibraryURL = ""
257+
var endMessage = ""
246258

247259
// Retrieve the OS and set variable to retrieve correct flutter embedder
248260
switch runtime.GOOS {
249261
case "darwin":
250262
platform = "darwin-x64"
251-
downloadURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/FlutterEmbedder.framework.zip", hashResponse.Items[0].Sha, platform)
263+
downloadShareLibraryURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/FlutterEmbedder.framework.zip", hashResponse.Items[0].Sha, platform)
264+
endMessage = "export CGO_LDFLAGS=\"-F${PWD} -Wl,-rpath,@executable_path\""
252265

253266
case "linux":
254267
platform = "linux-x64"
255-
downloadURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/%s-embedder", hashResponse.Items[0].Sha, platform, platform)
268+
downloadShareLibraryURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/%s-embedder", hashResponse.Items[0].Sha, platform, platform)
269+
endMessage = "export CGO_LDFLAGS=\"-L${PWD}\""
256270

257271
case "windows":
258272
platform = "windows-x64"
259-
downloadURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/%s-embedder", hashResponse.Items[0].Sha, platform, platform)
273+
downloadShareLibraryURL = fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/%s-embedder", hashResponse.Items[0].Sha, platform, platform)
274+
endMessage = "set CGO_LDFLAGS=-L%cd%"
260275

261276
default:
262277
log.Fatal("OS not supported")
263278
}
264279

265-
err3 := downloadFile(dir+"/.build/temp.zip", downloadURL)
280+
downloadIcudtlURL := fmt.Sprintf("https://storage.googleapis.com/flutter_infra/flutter/%s/%s/artifacts.zip", hashResponse.Items[0].Sha, platform)
281+
282+
err3 := downloadFile(dir+"/.build/temp.zip", downloadShareLibraryURL)
266283
if err3 != nil {
267284
log.Fatal(err3)
268285
} else {
269286
fmt.Printf("Downloaded embedder for %s platform, matching version : %s\n", platform, hashResponse.Items[0].Sha)
270287
}
271288

289+
err4 := downloadFile(dir+"/.build/artifacts.zip", downloadIcudtlURL)
290+
if err != nil {
291+
log.Fatal(err4)
292+
} else {
293+
fmt.Printf("Downloaded artifact for %s platform.\n", platform)
294+
}
295+
272296
_, err = unzip(".build/temp.zip", dir+"/.build/")
273297
if err != nil {
274298
log.Fatal(err)
275299
}
276300

301+
_, err = unzip(".build/artifacts.zip", dir+"/.build/artifacts/")
302+
if err != nil {
303+
log.Fatal(err)
304+
}
305+
306+
err = os.Rename(".build/artifacts/icudtl.dat", dir+"/icudtl.dat")
307+
if err != nil {
308+
log.Fatal(err)
309+
}
310+
277311
switch platform {
278312
case "darwin-x64":
279-
_, err = unzip(".build/FlutterEmbedder.framework.zip", dir+"/FlutterEmbedder.framework")
313+
_, err = unzip(dir+"/.build/FlutterEmbedder.framework.zip", dir+"/.build/FlutterEmbedder.framework/")
314+
if err != nil {
315+
log.Fatal(err)
316+
}
317+
318+
os.RemoveAll(dir + "/FlutterEmbedder.framework")
319+
320+
err := os.Rename(dir+"/.build/FlutterEmbedder.framework/", dir+"/FlutterEmbedder.framework/")
280321
if err != nil {
281322
log.Fatal(err)
282323
}
283324

325+
createSymLink(dir+"/FlutterEmbedder.framework/Versions/Current", dir+"/FlutterEmbedder.framework/Versions/A")
326+
327+
createSymLink(dir+"/FlutterEmbedder.framework/FlutterEmbedder", dir+"/FlutterEmbedder.framework/Versions/Current/FlutterEmbedder")
328+
329+
createSymLink(dir+"/FlutterEmbedder.framework/Headers", dir+"/FlutterEmbedder.framework/Versions/Current/Headers")
330+
331+
createSymLink(dir+"/FlutterEmbedder.framework/Modules", dir+"/FlutterEmbedder.framework/Versions/Current/Modules")
332+
333+
createSymLink(dir+"/FlutterEmbedder.framework/Resources", dir+"/FlutterEmbedder.framework/Versions/Current/Resources")
334+
284335
case "linux-x64":
285336
err := os.Rename(".build/libflutter_engine.so", dir+"/libflutter_engine.so")
286337
if err != nil {
@@ -296,6 +347,8 @@ func main() {
296347
}
297348
fmt.Printf("Unzipped files and moved them to correct repository.\n")
298349

299-
fmt.Printf("Done.\n")
350+
fmt.Printf("\nTo let know the CGO compiler where to look for the share library, Please run:\n\t")
351+
fmt.Printf("%s\n", endMessage)
300352

353+
fmt.Printf("Done.\n")
301354
}

example/simpleDemo/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func main() {
3434
* Linux : flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat
3535
* Windows : flutter/bin/cache/artifacts/engine/windows-x64/icudtl.dat
3636
*/
37-
gutter.OptionICUDataPath("/opt/flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat"),
37+
gutter.OptionICUDataPath(dir + "/icudtl.dat"),
3838
gutter.OptionWindowInitializer(setIcon),
3939
gutter.OptionWindowDimension(800, 600),
4040
gutter.OptionWindowInitializer(setIcon),

0 commit comments

Comments
 (0)