11import 'dart:io' ;
22
3- Future <void > main () async {
3+ const _mwebdVersion = "v0.1.8" ;
4+ const _defaultFetchBaseUrl =
5+ "https://github.com/cypherstack/stack_wallet/releases/download" ;
6+
7+ Future <void > main (List <String > args) async {
48 final projectToolDir = File (Platform .script.toFilePath ()).parent;
59
10+ if (args.contains ("--fetch" )) {
11+ await _fetchPrebuilt (projectToolDir);
12+ } else {
13+ await _buildFromSource (projectToolDir);
14+ }
15+ }
16+
17+ Future <void > _fetchPrebuilt (Directory projectToolDir) async {
18+ final baseUrl =
19+ Platform .environment["MWEBD_FETCH_BASE_URL" ] ?? _defaultFetchBaseUrl;
20+ final tag = "mwebd-$_mwebdVersion " ;
21+
22+ final winAssetsDir = Directory (
23+ "${projectToolDir .parent .path }"
24+ "${Platform .pathSeparator }assets"
25+ "${Platform .pathSeparator }windows" ,
26+ );
27+ if (! (await winAssetsDir.exists ())) {
28+ await winAssetsDir.create (recursive: true );
29+ }
30+ final exePath = "${winAssetsDir .path }${Platform .pathSeparator }mwebd.exe" ;
31+ final shaPath = "$exePath .sha256" ;
32+
33+ await _waitForProcess (
34+ await Process .start (
35+ "curl" ,
36+ ["-fL" , "-o" , exePath, "$baseUrl /$tag /mwebd.exe" ],
37+ runInShell: true ,
38+ mode: ProcessStartMode .inheritStdio,
39+ ),
40+ );
41+ await _waitForProcess (
42+ await Process .start (
43+ "curl" ,
44+ ["-fL" , "-o" , shaPath, "$baseUrl /$tag /mwebd.exe.sha256" ],
45+ runInShell: true ,
46+ mode: ProcessStartMode .inheritStdio,
47+ ),
48+ );
49+
50+ final expected = (await File (
51+ shaPath,
52+ ).readAsString ()).trim ().split (RegExp (r"\s+" )).first;
53+ final actual = (await Process .run ("sha256sum" , [
54+ exePath,
55+ ], runInShell: true )).stdout.toString ().trim ().split (RegExp (r"\s+" )).first;
56+ if (expected.toLowerCase () != actual.toLowerCase ()) {
57+ stderr.writeln (
58+ "mwebd.exe sha256 mismatch: expected $expected , got $actual " ,
59+ );
60+ exit (1 );
61+ }
62+ await File (shaPath).delete ();
63+ }
64+
65+ Future <void > _buildFromSource (Directory projectToolDir) async {
666 // setup temp build dir
767 final tempBuildDir = Directory (
868 "${projectToolDir .path }"
@@ -15,12 +75,17 @@ Future<void> main() async {
1575
1676 // change working dir and clone mwebd
1777 Directory .current = tempBuildDir;
18- final clone = await Process .start ("git" , [
19- "clone" ,
20- "https://www.github.com/ltcmweb/mwebd.git" ,
21- "--branch" ,
22- "v0.1.8" ,
23- ], runInShell: true , mode: ProcessStartMode .inheritStdio);
78+ final clone = await Process .start (
79+ "git" ,
80+ [
81+ "clone" ,
82+ "https://www.github.com/ltcmweb/mwebd.git" ,
83+ "--branch" ,
84+ _mwebdVersion,
85+ ],
86+ runInShell: true ,
87+ mode: ProcessStartMode .inheritStdio,
88+ );
2489 await _waitForProcess (clone);
2590
2691 // change working dir and build mwebd.exe
@@ -33,23 +98,40 @@ Future<void> main() async {
3398 if (Platform .isWindows && isCI) {
3499 build = await Process .start (
35100 "go" ,
36- ["build" , "-v" , "-o" , "../mwebd.exe" , "github.com/ltcmweb/mwebd/cmd/mwebd" ],
101+ [
102+ "build" ,
103+ "-v" ,
104+ "-o" ,
105+ "../mwebd.exe" ,
106+ "github.com/ltcmweb/mwebd/cmd/mwebd" ,
107+ ],
37108 environment: {"CGO_ENABLED" : "1" },
38109 runInShell: true ,
39110 mode: ProcessStartMode .inheritStdio,
40111 );
41112 } else if (Platform .isWindows) {
42- build = await Process .start ("wsl" , [
43- "bash" ,
44- "-l" ,
45- "-c" ,
46- "GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc "
47- "go build -v -o ../mwebd.exe github.com/ltcmweb/mwebd/cmd/mwebd" ,
48- ], runInShell: true , mode: ProcessStartMode .inheritStdio);
113+ build = await Process .start (
114+ "wsl" ,
115+ [
116+ "bash" ,
117+ "-l" ,
118+ "-c" ,
119+ "GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc "
120+ "go build -v -o ../mwebd.exe github.com/ltcmweb/mwebd/cmd/mwebd" ,
121+ ],
122+ runInShell: true ,
123+ mode: ProcessStartMode .inheritStdio,
124+ );
49125 } else {
50126 build = await Process .start (
51127 "go" ,
52- ["build" , "-v" , "-o" , "../mwebd.exe" , "github.com/ltcmweb/mwebd/cmd/mwebd" ],
128+ [
129+ "build" ,
130+ "-v" ,
131+ "-o" ,
132+ "../mwebd.exe" ,
133+ "github.com/ltcmweb/mwebd/cmd/mwebd" ,
134+ ],
53135 environment: {
54136 "GOOS" : "windows" ,
55137 "GOARCH" : "amd64" ,
0 commit comments