forked from fzyzcjy/flutter_rust_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
349 lines (282 loc) · 13.4 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# To use this file, install Just: `cargo install just`
pana := if os() == "windows" {
"pana.bat"
} else {
"pana"
}
dir_example_pure_dart := "frb_example/pure_dart"
dir_example_pure_dart_multi := "frb_example/pure_dart_multi"
dir_example_with_flutter := "frb_example/with_flutter"
# ============================ installation ============================
install_ffigen_dependency:
# needed by `ffigen`, see https://github.com/dart-lang/ffigen#installing-llvm
{{ if os() == "linux" { "sudo apt update && sudo apt-get install -y libclang-dev" } else { "" } }}
install_ffigen:
dart pub global activate ffigen
install_valgrind:
sudo apt install -y valgrind
install_prerequisite_for_integration_test_linux:
sudo apt update && sudo apt-get -y install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libglu1-mesa
install_corrosion_linux:
#!/usr/bin/env bash
set -euxo pipefail
cd ..
git clone https://github.com/corrosion-rs/corrosion.git
cmake -Scorrosion -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
sudo cmake --install build --config Release
dart_pub_get mode="default":
cd frb_dart && dart pub get
cd {{dir_example_pure_dart}}/dart && dart pub get
cd {{dir_example_pure_dart_multi}}/dart && dart pub get
cd {{dir_example_with_flutter}} && {{ if mode == "dart_only" { "pwd" } else { "flutter pub get" } }}
# ============================ build & test ============================
rust_build_and_test:
just _rust_build_and_test_single frb_codegen --features uuid --features chrono
just _rust_build_and_test_single frb_rust
just _rust_build_and_test_single frb_macros
just _rust_build_and_test_single {{dir_example_pure_dart}}/rust
just _rust_build_and_test_single {{dir_example_with_flutter}}/rust
just _rust_build_and_test_single {{dir_example_pure_dart_multi}}/rust
just _rust_build_and_test_single {{dir_example_pure_dart_multi}}/rust --features c-output
just _rust_build_and_test_single {{dir_example_pure_dart_multi}}/rust --features c-output,extra-c-output-path
_rust_build_and_test_single directory *args:
cd {{directory}} && cargo build {{args}}
cd {{directory}} && cargo test {{args}}
dart_test_web_unit:
cd frb_dart && dart pub get
cd frb_dart && dart test test/*.dart
cd frb_dart && dart test -p chrome test/*.dart
dart_test_web_integration features:
cd {{dir_example_pure_dart}}/dart && dart run \
../../../frb_dart/bin/serve.dart \
-c ../rust --dart-input lib/main.web.dart --root web/ --run-tests \
--features={{features}}
dart_test_vm_service:
cd frb_example/pure_dart/rust && cargo build --verbose
dart run --enable-vm-service --define=ENABLE_FRB_FFI_TEST_TOOL=true \
frb_example/pure_dart/dart/lib/main_with_vm_service.dart \
target/debug/libflutter_rust_bridge_example_pure_dart.so
dart_test_valgrind $CARGO_TARGET_DIR="/home/runner":
cd {{dir_example_pure_dart}}/dart && \
chmod +x ./run.sh ./valgrind_util.py && \
./run.sh
flutter_example_with_flutter_integration_test:
flutter config --enable-{{ os() }}-desktop
cd {{dir_example_with_flutter}} && flutter pub get
cd {{dir_example_with_flutter}} && flutter test -d {{ os() }} integration_test/main.dart --verbose
# ============================ code generators ============================
generate_all: generate_ffigen generate_bridge generate_book_help
generate_book_help:
cargo run --manifest-path frb_codegen/Cargo.toml -- --help > book/src/help.txt
dart run frb_dart/bin/serve.dart --help > book/src/help.serve.txt
generate_ffigen:
cd frb_dart && dart run ffigen
cargo_run_codegen := if env_var_or_default("FRB_TEST_USE_RELEASE_VERSION", "false") == "true" {
"flutter_rust_bridge_codegen"
} else {
"cargo run --manifest-path frb_codegen/Cargo.toml --package flutter_rust_bridge_codegen --bin flutter_rust_bridge_codegen --features 'chrono,uuid' -- "
}
generate_bridge:
just _generate_bridge_pure_dart
just _generate_bridge_pure_dart_multi
just _generate_bridge_with_flutter
_generate_bridge_pure_dart:
{{cargo_run_codegen}} frb_example/pure_dart/rust/.flutter_rust_bridge.yml
_generate_bridge_pure_dart_multi:
{{cargo_run_codegen}} \
--rust-input frb_example/pure_dart_multi/rust/src/api_1.rs frb_example/pure_dart_multi/rust/src/api_2.rs \
--dart-output frb_example/pure_dart_multi/dart/lib/bridge_generated_api_1.dart frb_example/pure_dart_multi/dart/lib/bridge_generated_api_2.dart \
--dart-format-line-length 120 \
--dart-enums-style \
--rust-output frb_example/pure_dart_multi/rust/src/generated_api_1.rs frb_example/pure_dart_multi/rust/src/generated_api_2.rs \
--class-name ApiClass1 ApiClass2 \
--wasm
_generate_bridge_with_flutter:
{{cargo_run_codegen}} \
--rust-input frb_example/with_flutter/rust/src/api.rs \
--dart-output frb_example/with_flutter/lib/bridge_generated.dart \
--c-output frb_example/with_flutter/ios/Runner/bridge_generated.h \
--dart-decl-output frb_example/with_flutter/lib/bridge_definitions.dart \
--dart-format-line-length 120 \
--dart-enums-style \
--no-use-bridge-in-method \
--wasm
# ============================ linters ============================
rust_linter:
just _rust_linter_main
just _rust_linter_wasm
_rust_linter_main:
cargo fmt
cargo clippy -- -D warnings
_rust_linter_wasm:
rustup target add wasm32-unknown-unknown
cd frb_rust && cargo clippy --target wasm32-unknown-unknown -- -D warnings
default_line_length := "120"
dart_linter mode="default":
just dart_pub_get
just _dart_linter_single {{mode}} frb_dart dart 80
just _dart_linter_single {{mode}} {{dir_example_pure_dart}}/dart dart {{default_line_length}}
just _dart_linter_single {{mode}} {{dir_example_pure_dart_multi}}/dart dart {{default_line_length}}
just _dart_linter_single {{mode}} {{dir_example_with_flutter}} dart {{default_line_length}}
just dart_linter_pana
_dart_linter_single mode directory executable line_length:
cd {{directory}} && dart format \
--line-length {{line_length}} \
{{ if mode == "fix" { "--fix" } else { "--output=none --set-exit-if-changed" } }} \
.
cd {{directory}} && {{executable}} analyze --fatal-infos
dart_linter_pana:
flutter pub global activate pana
cd frb_dart && {{pana}} --no-warning --line-length 80 --exit-code-threshold 0
dart_check_included_source:
#!/usr/bin/env bash
set -euxo pipefail
git clone --depth 1 --filter=blob:none --sparse --branch stable https://github.com/dart-lang/sdk.git
cd sdk
git sparse-checkout set runtime/include
cd ..
cp -rf ./sdk/runtime/include/* ./frb_rust/src/dart_api/
rm -r sdk
git diff --exit-code
# ============================ (some of) CI ============================
ci_valgrind:
just install_ffigen_dependency
just install_valgrind
just dart_pub_get dart_only
just dart_test_valgrind
ci_codegen:
just install_ffigen_dependency
just dart_pub_get
just dart_check_included_source
just generate_all
just check_no_git_diff
# ============================ misc ============================
clean:
cd frb_dart && flutter clean
cd {{dir_example_pure_dart}}/dart && flutter clean
cd {{dir_example_pure_dart_multi}}/dart && flutter clean
cd {{dir_example_with_flutter}} && flutter clean
cargo clean
check_no_git_diff:
# Check nothing has changed (Use `just precommit` if error occurred)
git diff --exit-code
normalize_pubspec_lock:
just _normalize_pubspec_lock_one frb_example/pure_dart/dart/pubspec.lock
just _normalize_pubspec_lock_one frb_example/pure_dart_multi/dart/pubspec.lock
just _normalize_pubspec_lock_one frb_example/with_flutter/pubspec.lock
_normalize_pubspec_lock_one path:
sed -i "" -e 's/pub.flutter-io.cn/pub.dev/g' {{path}}
serve *args:
cd {{invocation_directory()}} && dart run {{justfile_directory()}}/frb_dart/bin/serve.dart {{args}}
use_flutter_rust_bridge_release:
cp ./frb_example/pure_dart/dart/pubspec.yaml.release ./frb_example/pure_dart/dart/pubspec.yaml
cp ./frb_example/pure_dart/rust/Cargo.toml.release ./frb_example/pure_dart/rust/Cargo.toml
cp ./frb_example/with_flutter/pubspec.yaml.release ./frb_example/with_flutter/pubspec.yaml
cp ./frb_example/with_flutter/rust/Cargo.toml.release ./frb_example/with_flutter/rust/Cargo.toml
configure_ndk:
#!/usr/bin/env bash
set -euxo pipefail
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
ANDROID_HOME=$HOME/Library/Android/sdk
SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
echo y | $SDKMANAGER "ndk;21.4.7075529"
ln -sfn $ANDROID_HOME/ndk/21.4.7075529 $ANDROID_HOME/ndk-bundle
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under GNU/Linux platform
ANDROID_ROOT=/usr/local/lib/android
ANDROID_SDK_ROOT=${ANDROID_ROOT}/sdk
SDKMANAGER=${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager
echo "y" | $SDKMANAGER "ndk;21.4.7075529"
ANDROID_NDK_ROOT=${ANDROID_SDK_ROOT}/ndk-bundle
ln -sfn $ANDROID_SDK_ROOT/ndk/21.4.7075529 $ANDROID_NDK_ROOT
fi
# ============================ precommit ============================
precommit: dart_pub_get generate_all rust_linter dart_linter
# ============================ releasing new versions ============================
release old_version new_version:
just _release_sanity_check_version {{old_version}} {{new_version}}
just _release_update_version {{old_version}} {{new_version}}
just precommit
just normalize_pubspec_lock
just _release_update_scoop
just _release_update_git {{old_version}} {{new_version}}
just _release_update_github {{old_version}} {{new_version}}
just _release_publish_all
_release_sanity_check_version old_version new_version:
grep -q 'version = "{{old_version}}"' Cargo.toml
grep -q '{{new_version}}' CHANGELOG.md
_release_update_version old_version new_version:
sed -i '' 's/version = "{{old_version}}"/version = "{{new_version}}"/g' Cargo.toml
sed -i '' 's/version: {{old_version}}/version: {{new_version}}/g' frb_dart/pubspec.yaml
_release_update_scoop:
cd frb_codegen && ./contrib/scoop.json.sh > ./contrib/flutter_rust_bridge_codegen.json
_release_update_git old_version new_version:
git add --all
git status && git diff --staged | grep ''
git commit -m "bump from {{old_version}} to {{new_version}}"
git push
_release_update_github old_version new_version:
awk '/## {{new_version}}/{flag=1; next} /## {{old_version}}/{flag=0} flag' CHANGELOG.md | gh release create v{{new_version}} --notes-file "-" --draft --title v{{new_version}}
echo 'A *DRAFT* release has been created. Please go to the webpage and really release if you find it correct.'
open https://github.com/fzyzcjy/flutter_rust_bridge/releases
_release_publish_all:
(cd frb_codegen && cargo publish)
(cd frb_rust && cargo publish)
(cd frb_macros && cargo publish)
(cd frb_dart && flutter pub publish --force --server=https://pub.dartlang.org)
install_ndk:
just _install_crate cargo-ndk
install_lipo:
just _install_crate cargo-lipo
_install_crate name="cargo-lipo":
#!/usr/bin/env bash
set -euxo pipefail
PACKAGE_NAME={{name}}
echo $PACKAGE_NAME
VERSION=$(cargo search $PACKAGE_NAME | grep "$PACKAGE_NAME" | cut -d '"' -f 2)
echo $VERSION
if ! [ -x "$(command -v $PACKAGE_NAME)" ]; then
echo "$PACKAGE_NAME not found. Installing version $VERSION ..."
cargo install $PACKAGE_NAME --version $VERSION
elif ! $PACKAGE_NAME --version | grep -q $VERSION; then
echo "Updating $PACKAGE_NAME to version $VERSION ..."
cargo install $PACKAGE_NAME --version $VERSION --force
else
echo "Already installed the correct version of $PACKAGE_NAME."
fi
# ============================ to be migrated ============================
# TODO - @Desdaemon
#dylib := if os() == "windows" {
# "flutter_rust_bridge_example.dll"
#} else if os() == "macos" {
# "libflutter_rust_bridge_example.dylib"
#} else {
# "libflutter_rust_bridge_example.so"
#}
#path_relative_linux_so := "target/x86_64-unknown-linux-gnu/debug/libflutter_rust_bridge_example.so"
#dir_tools := justfile_directory() / "tools"
#test: test-support test-pure test-integration
#test-pure:
# cd {{dir_example_pure_dart}}/rust && cargo b
# cd {{dir_example_pure_dart}}/dart && \
# dart pub get && \
# dart lib/main.dart ../../../target/debug/{{dylib}}
## TODO: Make ASan tests work for other platforms
#test-pure-asan $RUSTFLAGS="-Zsanitizer=address":
# ./tools/dartsdk/fetch.sh
# cd {{dir_example_pure_dart}}/rust && cargo +nightly b --target x86_64-unknown-linux-gnu
# cd {{dir_example_pure_dart}}/dart && \
# {{dir_tools}}/dartsdk/x64/dart pub get && \
# {{dir_tools}}/dartsdk/x64/dart lib/main.dart ../../../{{path_relative_linux_so}}
#test-pure-web *args:
# cd {{dir_example_pure_dart}}/dart && just serve --dart-input lib/main.web.dart --root web/ -c ../rust --port 8081 {{args}}
#test-flutter-web *args:
# cd {{dir_example_with_flutter}} && just serve -c rust {{args}}
#test-integration:
# cd {{dir_example_with_flutter}} && flutter test integration_test/main.dart
#test-support platform="chrome":
# cd frb_dart && dart pub get && \
# dart test test/*.dart && \
# dart test -p {{platform}} test/*.dart