Skip to content

Commit cc9438d

Browse files
committed
Add opt-in --fetch path for mwebd.exe Windows build
1 parent 80107e9 commit cc9438d

2 files changed

Lines changed: 103 additions & 17 deletions

File tree

scripts/app_config/configure_stack_wallet.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ dart "${APP_PROJECT_ROOT_DIR}/tool/gen_interfaces.dart" \
5353

5454
MWEBD_EXE_SHA256=""
5555
if [[ "$1" == "windows" ]]; then
56-
dart "${APP_PROJECT_ROOT_DIR}/tool/build_standalone_mwebd_windows.dart"
56+
if [[ "${MWEBD_FETCH:-0}" == "1" ]]; then
57+
dart "${APP_PROJECT_ROOT_DIR}/tool/build_standalone_mwebd_windows.dart" --fetch
58+
else
59+
dart "${APP_PROJECT_ROOT_DIR}/tool/build_standalone_mwebd_windows.dart"
60+
fi
5761
MWEBD_EXE_SHA256="$(sha256sum "${APP_PROJECT_ROOT_DIR}/assets/windows/mwebd.exe" | awk '{print $1}')"
5862
dart "${APP_PROJECT_ROOT_DIR}/tool/process_pubspec_deps.dart" \
5963
"${PUBSPEC_FILE}" MWEBDEXE

tool/build_standalone_mwebd_windows.dart

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,68 @@
11
import '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

Comments
 (0)