-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
1441 lines (1160 loc) · 39.2 KB
/
Makefile
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################
# Common defaults/definitions #
###############################
comma := ,
# Checks two given strings for equality.
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)
######################
# Project parameters #
######################
IMAGE_REPO := instrumentisto
IMAGE_NAME := $(strip \
$(if $(call eq,$(image),medea-demo-edge),medea-demo,\
$(or $(image),medea-control-api-mock)))
RUST_VER := 1.84
CHROME_VERSION := 131.0-chromedriver-131.0
FIREFOX_VERSION := 134.0-driver0.35.0
CARGO_NDK_VER := 3.5.4-ndkr27c-rust$(RUST_VER)
ANDROID_TARGETS := aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
ANDROID_SDK_COMPILE_VERSION = $(strip \
$(shell grep compileSdk flutter/android/build.gradle \
| awk -F'= ' '{print $$2}' | tr -d ' '))
ANDROID_SDK_MIN_VERSION = $(strip \
$(shell grep minSdk flutter/android/build.gradle \
| awk -F'= ' '{print $$2}' | tr -d ' '))
FLUTTER_RUST_BRIDGE_VER ?= $(strip \
$(shell grep -A1 'name = "flutter_rust_bridge"' Cargo.lock \
| grep -v 'flutter_rust_bridge' \
| cut -d'"' -f2))
IOS_TARGETS := aarch64-apple-ios x86_64-apple-ios
LINUX_TARGETS := x86_64-unknown-linux-gnu
MACOS_TARGETS := aarch64-apple-darwin x86_64-apple-darwin
WEB_TARGETS := wasm32-unknown-unknown
WINDOWS_TARGETS := x86_64-pc-windows-msvc
crate-dir = .
ifeq ($(crate),medea-client-api-proto)
crate-dir = proto/client-api
endif
ifeq ($(crate),medea-control-api-proto)
crate-dir = proto/control-api
endif
ifeq ($(crate),medea-control-api-mock)
crate-dir = mock/control-api
endif
ifeq ($(crate),medea-macro)
crate-dir = crates/medea-macro
endif
ifeq ($(crate),medea-reactive)
crate-dir = crates/medea-reactive
endif
crate-ver := $(strip \
$(shell grep -m1 'version = "' $(crate-dir)/Cargo.toml | cut -d '"' -f2))
###########
# Aliases #
###########
# Build all project executables.
#
# Usage:
# make build
build: build.jason
build.jason: cargo.build.jason
# Resolve all project dependencies.
#
# Usage:
# make deps
deps: cargo flutter yarn
docs: docs.rust
down: down.dev
fmt: cargo.fmt flutter.fmt
lint: cargo.lint flutter.lint
# Build and publish project crate everywhere.
#
# Usage:
# make release crate=(medea-jason|<crate-name>)
# [publish=(no|yes)]
release: release.cargo release.npm
# Run all project tests.
#
# Usage:
# make test
test:
@make test.unit
@make test.e2e up=yes dockerized=no
up: up.web
####################
# Running commands #
####################
# Stop non-dockerized Control API mock server.
#
# Usage:
# make down.control
down.control:
-killall medea-control-api-mock
down.demo: docker.down.demo
# Stop all processes in Medea and Jason development environment.
#
# Usage:
# make down.dev
down.dev:
@make docker.down.medea
@make down.control
down.medea: docker.down.medea
# Run Control API mock server.
#
# Usage:
# make up.control [background=(no|yes)]
up.control:
cargo build -p medea-control-api-mock
make wait.port port=6565
cargo run -p medea-control-api-mock $(if $(call eq,$(background),yes),&,)
up.demo: docker.up.demo
# Run Medea and Jason Flutter version locally.
#
# Usage:
# make up.flutter [device=<device-id>]
up.flutter:
$(MAKE) -j3 up.jason.flutter docker.up.medea up.control
# Run Medea and Jason web version locally.
#
# Usage:
# make up.web
up.web:
$(MAKE) -j3 up.jason.web docker.up.medea up.control
up.medea: docker.up.medea
# Run Jason E2E demo in development mode on native platform.
#
# Usage:
# make up.jason.native [debug=(yes|no)] [device=<device-id>]
up.jason.flutter:
cd flutter/example/ && \
flutter run $(if $(call eq,$(debug),no),--release,) \
$(if $(call eq,$(device),),,-d $(device))
# Run Jason E2E demo in development mode.
#
# Usage:
# make up.jason
up.jason.web:
npm run start --prefix=./e2e-demo
##################
# Cargo commands #
##################
# Resolve Cargo project dependencies.
#
# Usage:
# make cargo [cmd=(fetch|<cargo-cmd>)]
cargo:
cargo $(or $(cmd),fetch)
# Build `medea-jason` crate.
#
# Usage:
# make cargo.build.jason [args=<cargo-build-args>]
# [( [platform=web [targets=($(WEB_TARGETS)|<t1>[,<t2>...])]]
# | platform=all
# | platform=android [targets=($(ANDROID_TARGETS)|<t1>[,<t2>...])]
# | platform=ios [targets=($(IOS_TARGETS)|<t1>[,<t2>...])]
# | platform=linux [targets=($(LINUX_TARGETS)|<t1>[,<t2>...])]
# | platform=macos [targets=($(MACOS_TARGETS)|<t1>[,<t2>...])]
# | platform=windows [targets=($(WINDOWS_TARGETS)|<t1>[,<t2>...])] )]
# [debug=(yes|no)] [dockerized=(no|yes)]
cargo-build-platform = $(or $(platform),web)
cargo-build-targets-android = $(or $(targets),$(ANDROID_TARGETS))
cargo-build-targets-ios = $(or $(targets),$(IOS_TARGETS))
cargo-build-targets-linux = $(or $(targets),$(LINUX_TARGETS))
cargo-build-targets-macos = $(or $(targets),$(MACOS_TARGETS))
cargo-build-targets-web = $(or $(targets),$(WEB_TARGETS))
cargo-build-targets-windows = $(or $(targets),$(WINDOWS_TARGETS))
cargo.build.jason:
ifeq ($(platform),all)
@make cargo.build.jason platform=android
@make cargo.build.jason platform=ios
@make cargo.build.jason platform=linux
@make cargo.build.jason platform=macos
@make cargo.build.jason platform=web
@make cargo.build.jason platform=windows
else
ifeq ($(dockerized),yes)
ifeq ($(cargo-build-platform),web)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
-v "$(HOME)/.cargo/registry":/usr/local/cargo/registry \
-v "$(HOME):$(HOME)" \
-e XDG_CACHE_HOME=$(HOME) \
ghcr.io/instrumentisto/rust:$(RUST_VER) \
make cargo.build.jason debug=$(debug) dockerized=no \
platform=web args="$(args)" \
targets=$(targets) \
pre-install=yes
endif
ifeq ($(cargo-build-platform),android)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
-v "$(HOME)/.cargo/registry":/usr/local/cargo/registry \
-v "$(HOME):$(HOME)" \
-e XDG_CACHE_HOME=$(HOME) \
ghcr.io/instrumentisto/cargo-ndk:$(CARGO_NDK_VER) \
make cargo.build.jason debug=$(debug) dockerized=no \
platform=android args="$(args)" \
targets=$(targets)
endif
else
ifeq ($(cargo-build-platform),web)
ifeq ($(pre-install),yes)
cargo install wasm-pack
endif
@rm -rf ./pkg/
wasm-pack build -t web ./ $(if $(call eq,$(debug),no),,--dev) $(args)
endif
ifeq ($(cargo-build-platform),android)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets-android)),\
$(call cargo.build.medea-jason.android,$(target),$(debug)))
endif
ifeq ($(cargo-build-platform),ios)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets-ios)),\
$(call cargo.build.medea-jason.ios,$(target),$(debug)))
$(eval build := $(if $(call eq,$(debug),no),release,debug))
@rm -rf flutter/ios/lib/MedeaJason.xcframework
@mkdir -p flutter/ios/lib/
xcodebuild -create-xcframework \
$(foreach t,$(subst $(comma), ,$(cargo-build-targets-ios)),\
-library target/$(t)/$(build)/libmedea_jason.a) \
-output flutter/ios/lib/MedeaJason.xcframework
endif
ifeq ($(cargo-build-platform),linux)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets-linux)),\
$(call cargo.build.medea-jason.linux,$(target),$(debug)))
endif
ifeq ($(cargo-build-platform),macos)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets-macos)),\
$(call cargo.build.medea-jason.macos,$(target),$(debug)))
$(eval build := $(if $(call eq,$(debug),no),release,debug))
@mkdir -p ./flutter/macos/lib/
lipo -create $(foreach t,$(subst $(comma), ,$(cargo-build-targets-macos)),\
target/$(t)/$(build)/libmedea_jason.dylib) \
-output ./flutter/macos/lib/libmedea_jason.dylib
endif
ifeq ($(cargo-build-platform),windows)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets-windows)),\
$(call cargo.build.medea-jason.windows,$(target),$(debug)))
endif
endif
endif
define cargo.build.medea-jason.android
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cargo ndk -p $(ANDROID_SDK_MIN_VERSION) -t $(target) \
-o ./flutter/android/src/main/jniLibs \
--manifest-path=./Cargo.toml \
build $(if $(call eq,$(debug),no),--release,) $(args)
endef
define cargo.build.medea-jason.ios
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cargo rustc --target $(target) $(if $(call eq,$(debug),no),--release,) \
--crate-type=staticlib --manifest-path=./Cargo.toml \
$(args)
@mkdir -p ./flutter/ios/lib/$(target)/
cp -f target/$(target)/$(if $(call eq,$(debug),no),release,debug)/libmedea_jason.a \
./flutter/ios/lib/$(target)/libmedea_jason.a
endef
define cargo.build.medea-jason.linux
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cargo rustc --target $(target) $(if $(call eq,$(debug),no),--release,) \
--crate-type=cdylib --manifest-path=./Cargo.toml \
$(args)
@mkdir -p ./flutter/linux/lib/$(target)/
cp -f target/$(target)/$(if $(call eq,$(debug),no),release,debug)/libmedea_jason.so \
./flutter/linux/lib/$(target)/libmedea_jason.so
endef
define cargo.build.medea-jason.macos
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cargo rustc --target $(target) $(if $(call eq,$(debug),no),--release,) \
--crate-type=cdylib --manifest-path=./Cargo.toml \
$(args)
endef
define cargo.build.medea-jason.windows
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cargo rustc --target $(target) $(if $(call eq,$(debug),no),--release,) \
--crate-type=cdylib --manifest-path=./Cargo.toml \
$(args)
@mkdir -p ./flutter/windows/lib/$(target)/
cp -f target/$(target)/$(if $(call eq,$(debug),no),release,debug)/medea_jason.dll \
./flutter/windows/lib/$(target)/medea_jason.dll
endef
# Show permalink to CHANGELOG of a concrete version of project's Cargo crate.
#
# Usage:
# make cargo.changelog.link [crate=(medea-jason|<crate-name>)]
# [ver=($(crate-ver)|<version>)]
cargo-changelog-link-ver = $(if $(call eq,$(ver),),$(crate-ver),$(ver))
cargo.changelog.link:
@printf "https://github.com/instrumentisto/medea-jason/blob/$(or $(crate),medea-jason)-$(cargo-changelog-link-ver)/$(if $(call eq,$(crate-dir),.),,$(crate-dir)/)CHANGELOG.md#$(shell sed -n '/^## \[$(cargo-changelog-link-ver)\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' $(crate-dir)/CHANGELOG.md)"
# Format Rust sources with rustfmt.
#
# Usage:
# make cargo.fmt [check=(no|yes)]
cargo.fmt:
cargo +nightly fmt --all $(if $(call eq,$(check),yes),-- --check,)
# Generate sources using Cargo.
#
# Usage:
# make cargo.gen [( crate=medea-control-api-proto
# | crate=medea-jason [dockerized=(no|yes) )]
cargo.gen:
ifeq ($(crate),medea-control-api-proto)
@rm -rf $(crate-dir)/src/grpc/api.rs \
$(crate-dir)/src/grpc/callback.rs
cargo build -p $(crate) --all-features
endif
ifeq ($(crate),medea-jason)
cargo clean -p $(crate)
make cargo.build.jason platform=android args="--features dart-codegen" \
dockerized=$(dockerized)
make cargo.gen.bridge
make flutter.fmt
endif
# Generate Rust/Dart interop bridge.
#
# Usage:
# make cargo.gen.bridge
cargo.gen.bridge:
ifeq ($(shell which flutter_rust_bridge_codegen),)
cargo install flutter_rust_bridge_codegen --vers=$(FLUTTER_RUST_BRIDGE_VER)
else
ifneq ($(strip $(shell flutter_rust_bridge_codegen --version \
| cut -d ' ' -f2)),$(FLUTTER_RUST_BRIDGE_VER))
cargo install flutter_rust_bridge_codegen --force \
--vers=$(FLUTTER_RUST_BRIDGE_VER)
endif
endif
ifeq ($(shell which cbindgen),)
cargo install cbindgen
endif
ifeq ($(CURRENT_OS),macos)
ifeq ($(shell brew list | grep -Fx llvm),)
brew install llvm
endif
endif
flutter_rust_bridge_codegen generate \
--rust-input=crate::api::dart::api \
--rust-root=. \
--rust-output src/api/dart/api/api_bridge_generated.rs \
--no-add-mod-to-lib \
--dart-output=flutter/lib/src/native/ffi/frb \
--no-web \
--local
cd flutter && \
dart run build_runner build --delete-conflicting-outputs
# Lint Rust sources with Clippy.
#
# Usage:
# make cargo.lint
# [( workspace=yes
# | [workspace=no]
# [( [platform=all [targets=($(WEB_TARGETS)|<t1>[,<t2>...])]]
# | platform=web [targets=($(WEB_TARGETS)|<t1>[,<t2>...])]
# | platform=android [targets=($(ANDROID_TARGETS)|<t1>[,<t2>...])]
# | platform=ios [targets=($(IOS_TARGETS)|<t1>[,<t2>...])]
# | platform=linux [targets=($(LINUX_TARGETS)|<t1>[,<t2>...])]
# | platform=macos [targets=($(MACOS_TARGETS)|<t1>[,<t2>...])]
# | platform=windows [targets=($(WINDOWS_TARGETS)|<t1>[,<t2>...])]
# )] )]
cargo-lint-platform = $(or $(platform),all)
cargo-lint-targets-android = $(or $(targets),$(ANDROID_TARGETS))
cargo-lint-targets-ios = $(or $(targets),$(IOS_TARGETS))
cargo-lint-targets-linux = $(or $(targets),$(LINUX_TARGETS))
cargo-lint-targets-macos = $(or $(targets),$(MACOS_TARGETS))
cargo-lint-targets-web = $(or $(targets),$(WEB_TARGETS))
cargo-lint-targets-windows = $(or $(targets),$(WINDOWS_TARGETS))
cargo.lint:
ifeq ($(workspace),yes)
cargo clippy --workspace --all-features -- -D warnings
else
ifeq ($(cargo-lint-platform),all)
@make cargo.lint platform=android
@make cargo.lint platform=ios
@make cargo.lint platform=linux
@make cargo.lint platform=macos
@make cargo.lint platform=web
@make cargo.lint platform=windows
else
$(foreach target,$(subst $(comma), ,$(cargo-lint-targets-$(platform))),\
$(call cargo.lint.medea-jason,$(target)))
endif
endif
define cargo.lint.medea-jason
$(eval t := $(strip $(1)))
cargo $(if $(call eq,$(filter $(t),$(cargo-lint-targets-android)),),,ndk) \
clippy -p medea-jason --target=$(t) -- -D warnings
endef
# Show version of project's Cargo crate.
#
# Usage:
# make cargo.version [crate=(medea-jason|<crate-name>)]
cargo.version:
@printf "$(crate-ver)"
# Install or upgrade all the required project's targets for Rust.
#
# Usage:
# make rustup.targets [only=(android|ios|linux|web|windows)]
rustup-targets = $(ANDROID_TARGETS) \
$(IOS_TARGETS) \
$(LINUX_TARGETS) \
$(MACOS_TARGETS) \
$(WEB_TARGETS) \
$(WINDOWS_TARGETS)
ifeq ($(only),android)
rustup-targets = $(ANDROID_TARGETS)
endif
ifeq ($(only),ios)
rustup-targets = $(IOS_TARGETS)
endif
ifeq ($(only),linux)
rustup-targets = $(LINUX_TARGETS)
endif
ifeq ($(only),macos)
rustup-targets = $(MACOS_TARGETS)
endif
ifeq ($(only),web)
rustup-targets = $(WEB_TARGETS)
endif
ifeq ($(only),windows)
rustup-targets = $(WINDOWS_TARGETS)
endif
rustup.targets:
rustup target add $(rustup-targets)
####################
# Flutter commands #
####################
# Show Android SDK compile API version of medea_jason Flutter plugin.
#
# Usage:
# make flutter.android.version.compile
flutter.android.version.compile:
@printf "$(ANDROID_SDK_COMPILE_VERSION)"
# Show Android SDK minimal API version of medea_jason Flutter plugin.
#
# Usage:
# make flutter.android.version.min
flutter.android.version.min:
@printf "$(ANDROID_SDK_MIN_VERSION)"
# Resolve Flutter project dependencies.
#
# Usage:
# make flutter [cmd=(pub get|<flutter-cmd>)]
flutter:
cd flutter && \
flutter $(or $(cmd),pub get)
# Format Flutter Dart sources with dartfmt.
#
# Usage:
# make flutter.fmt [check=(no|yes)]
flutter.fmt:
dart format $(if $(call eq,$(check),yes), --set-exit-if-changed,) flutter/
ifeq ($(wildcard flutter/.packages),)
@make flutter cmd='pub get'
endif
@make flutter cmd='pub run import_sorter:main --no-comments \
$(if $(call eq,$(check),yes),--exit-if-changed,)'
# Run `build_runner` Flutter tool to generate project Dart sources.
#
# Usage:
# make flutter.gen [overwrite=(yes|no)]
flutter.gen:
ifeq ($(wildcard flutter/pubspec.lock),)
@make flutter
endif
cd flutter && \
flutter pub get && \
dart run build_runner build \
$(if $(call eq,$(overwrite),no),,--delete-conflicting-outputs)
# Lint Flutter Dart sources with dartanalyzer.
#
# Usage:
# make flutter.lint
flutter.lint:
ifeq ($(wildcard flutter/test/e2e/suite.g.dart),)
@make flutter.gen overwrite=yes
endif
flutter analyze flutter/
# Runs medea_jason Flutter plugin example app on attached device.
#
# Usage:
# make flutter.run [debug=(yes|no)] [device=<device-id>]
flutter.run:
cd flutter/example/ && \
flutter run $(if $(call eq,$(debug),no),--release,) \
$(if $(call eq,$(device),),,-d $(device))
# Generates assets required for Flutter Web Jason plugin.
#
# Usage:
# make flutter.web.assets
flutter.web.assets:
@rm -rf flutter/assets/pkg
wasm-pack build -d flutter/assets/pkg --no-typescript -t web
sed "s/medea_jason_bg.wasm/medea_jason_bg.wasm?$(strip \
$$(sha256sum flutter/assets/pkg/medea_jason_bg.wasm \
| cut -f 1 -d ' '))/g" \
flutter/assets/pkg/medea_jason.js > flutter/assets/pkg/.tmp.js
cp -f flutter/assets/pkg/.tmp.js flutter/assets/pkg/medea_jason.js
rm -rf flutter/assets/pkg/*.md \
flutter/assets/pkg/.gitignore \
flutter/assets/pkg/.tmp.js \
flutter/assets/pkg/package.json
@touch flutter/assets/pkg/.gitkeep
#################
# Yarn commands #
#################
# Resolve NPM project dependencies with Yarn.
#
# Optional 'cmd' parameter may be used for handy usage of docker-wrapped Yarn,
# for example: make yarn cmd='upgrade'
#
# Usage:
# make yarn [cmd=('install --pure-lockfile'|<yarn-cmd>)]
# [pkg=(e2e|medea-demo)]
# [dockerized=(yes|no)]
yarn-cmd = $(or $(cmd),install --pure-lockfile)
yarn-pkg-dir = $(if $(call eq,$(pkg),medea-demo),demo,e2e-demo)
yarn:
ifneq ($(dockerized),no)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
node:latest \
make yarn cmd='$(yarn-cmd)' pkg=$(pkg) dockerized=no
else
yarn --cwd=$(yarn-pkg-dir) $(yarn-cmd)
endif
# Show version of project's Yarn package.
#
# Usage:
# make cargo.version [pkg=medea-demo]
yarn.version:
@printf "$(strip $(shell grep -m1 '"version": "' demo/package.json \
| cut -d '"' -f4))"
##########################
# Documentation commands #
##########################
# Generate project documentation of Rust sources.
#
# Usage:
# make docs.rust [crate=(@all|medea-jason|<crate-name>)]
# [open=(yes|no)] [clean=(no|yes)]
# [dev=(no|yes)]
docs.rust:
ifeq ($(clean),yes)
@rm -rf target/doc/
endif
$(if $(call eq,$(or $(crate),@all),@all),\
cargo doc --workspace,\
cd $(crate-dir)/ && cargo doc)\
--no-deps \
$(if $(call eq,$(dev),yes),--document-private-items,) \
$(if $(call eq,$(open),no),,--open)
####################
# Testing commands #
####################
# Run Rust unit tests of project.
#
# Usage:
# make test.unit [( [crate=@all]
# | crate=<crate-name> [features=(all|<f1>[,<f2>...])]
# | crate=medea-jason
# [browser=(chrome|firefox|default)]
# [timeout=(60|<seconds>)] )]
webdriver-env = $(if $(call eq,$(browser),firefox),GECKO,CHROME)DRIVER_REMOTE
test.unit:
ifeq ($(or $(crate),@all),@all)
@make test.unit crate=medea-macro
@make test.unit crate=medea-reactive
@make test.unit crate=medea-client-api-proto
@make test.unit crate=medea-control-api-proto
@make test.unit crate=medea-jason
else
ifeq ($(crate),medea-jason)
ifeq ($(browser),default)
cd $(crate-dir)/ && \
WASM_BINDGEN_TEST_TIMEOUT=$(or $(timeout),60) \
cargo test --target wasm32-unknown-unknown --features mockable
else
@make docker.up.webdriver browser=$(browser)
sleep 10
cd $(crate-dir)/ && \
$(webdriver-env)="http://127.0.0.1:4444" \
WASM_BINDGEN_TEST_TIMEOUT=$(or $(timeout),60) \
cargo test --target wasm32-unknown-unknown --features mockable
@make docker.down.webdriver browser=$(browser)
endif
else
cargo test -p $(crate) $(if $(call eq,$(or $(features),all),all),\
--all-features ,\
--features $(features) )
endif
endif
test.e2e: test.e2e.browser
# Run browser E2E tests of project.
#
# Usage:
# make test.e2e.browser [(only=<regex>|only-tags=<tag-expression>)]
# [sfu=(no|yes)]
# [( [up=no]
# | up=yes [browser=(chrome|firefox)]
# [( [dockerized=no]
# | dockerized=yes [tag=(dev|<tag>)] [rebuild=(no|yes)] )]
# [debug=(yes|no)]
# [( [background=no]
# | background=yes [log=(no|yes)] )]
test-e2e-tags = $(if $(call eq,$(sfu),yes),not @mesh,not @sfu)
test.e2e.browser:
ifeq ($(up),yes)
ifeq ($(dockerized),yes)
ifeq ($(rebuild),yes)
@make docker.build image=medea-control-api-mock debug=$(debug) tag=$(tag)
endif
endif
@make docker.up.e2e browser=$(browser) background=yes log=$(log) \
dockerized=$(dockerized) tag=$(tag) debug=$(debug) \
rebuild=yes
@make wait.port port=4444
endif
$(if $(call eq,$(sfu),yes),SFU=true,) \
cargo test -p medea-e2e --test e2e \
$(if $(call eq,$(only),),\
-- --tags $(if $(call eq,$(only-tags),),\
'$(test-e2e-tags)','$(only-tags)'),\
-- --name '$(only)')
ifeq ($(up),yes)
@make docker.down.e2e
endif
# Run E2E native tests of project.
#
# Usage:
# make test.e2e.native [(only=<regex>|only-tags=<tag-expression>)]
# [sfu=(no|yes)]
# [device=<device-id>]
# [server=<server-ip>]
# [( [up=no]
# | up=yes [( [dockerized=no]
# | dockerized=yes [tag=(dev|<tag>)] [rebuild=(no|yes)] )]
# [debug=(yes|no)]
# [( [background=no]
# | background=yes [log=(no|yes)] )]
test.e2e.native:
ifeq ($(up),yes)
ifeq ($(dockerized),yes)
ifeq ($(rebuild),yes)
@make docker.build image=medea-control-api-mock debug=$(debug) tag=$(tag)
endif
endif
@make docker.up.e2e background=yes log=$(log) \
dockerized=$(dockerized) tag=$(tag) debug=$(debug) \
rebuild=no
endif
ifeq ($(wildcard flutter/test/e2e/suite.g.dart),)
@make flutter.gen overwrite=yes dockerized=$(dockerized)
endif
cd flutter/example/ && \
flutter drive --driver=test_driver/integration_test.dart \
--target=../test/e2e/suite.dart \
--dart-define=MOCKABLE=true \
$(if $(call eq,$(sfu),yes),--dart-define=SFU=true,) \
$(if $(call eq,$(server),),,--dart-define=IP_TEST_BASE=$(server)) \
$(if $(call eq,$(device),),,-d $(device))
ifeq ($(up),yes)
@make docker.down.e2e
endif
# Runs Flutter plugin integration tests on an attached device.
#
# Usage:
# make test.flutter [device=<device-id>]
test.flutter:
cd flutter/example/ && \
flutter drive --driver=test_driver/integration_test.dart \
--target=integration_test/jason.dart \
$(if $(call eq,$(device),),,-d $(device))
####################
# Waiting commands #
####################
# Waits for some port on localhost to become open.
#
# Usage:
# make wait.port [port=<port>]
wait.port:
while ! timeout 1 bash -c "echo > /dev/tcp/localhost/$(port)"; \
do sleep 1; done
######################
# Releasing commands #
######################
# Build and publish project crate to crates.io.
#
# Usage:
# make release.cargo crate=(medea-jason|<crate-name>)
# [token=($CARGO_REGISTRY_TOKEN|<cargo-token>)]
# [publish=(no|yes)]
release.cargo:
ifneq ($(filter $(crate),medea-jason medea-client-api-proto medea-control-api-proto medea-macro medea-reactive),)
cd $(crate-dir)/ && \
$(if $(call eq,$(publish),yes),\
cargo publish --token $(or $(token),$$CARGO_REGISTRY_TOKEN) ,\
cargo package --allow-dirty )
endif
release.helm: helm.package.release
# Build and publish project crate to NPM.
#
# Usage:
# make release.npm crate=medea-jason
# [publish=(no|yes)]
release.npm:
ifneq ($(filter $(crate),medea-jason),)
make cargo.build.jason platform=web debug=no dockerized=no
ifeq ($(publish),yes)
wasm-pack publish $(crate-dir)/pkg/
endif
endif
###################
# Docker commands #
###################
docker-env = $(strip $(if $(call eq,$(minikube),yes),\
$(subst export,,$(shell minikube docker-env | cut -d '\#' -f1)),))
# Build project Docker image with a given tag.
#
# Usage:
# make docker.build [debug=(yes|no)] [no-cache=(no|yes)]
# [image=(medea-control-api-mock|medea-demo|medea-demo-edge)]
# [tag=(dev|<tag>)]
# [minikube=(no|yes)]
docker-build-tag = $(if $(call eq,$(tag),),dev,$(tag))
docker-build-dir = .
ifeq ($(image),medea-demo)
docker-build-dir = demo
endif
docker-build-file = $(docker-build-dir)/Dockerfile
ifeq ($(image),medea-control-api-mock)
docker-build-file = mock/control-api/Dockerfile
endif
ifeq ($(image),medea-demo-edge)
docker-build-file = Dockerfile
endif
docker.build:
$(docker-env) \
docker build $(if $(call eq,$(minikube),yes),,--network=host) --force-rm \
$(if $(call eq,$(no-cache),yes),\
--no-cache --pull,) \
--build-arg rust_ver=$(RUST_VER) \
--build-arg rustc_mode=$(if $(call eq,$(debug),no),release,debug) \
--build-arg rustc_opts=$(if $(call eq,$(debug),no),--release,) \
--build-arg debug=$(if $(call eq,$(debug),no),no,yes) \
-t $(IMAGE_REPO)/$(IMAGE_NAME):$(docker-build-tag) \
-f $(docker-build-file) $(docker-build-dir)/
# Stop dockerized Control API mock server and remove all related containers.
#
# Usage:
# make docker.down.control
docker.down.control:
-docker stop medea-control-api-mock
# Stop demo application in Docker Compose environment
# and remove all related containers.
#
# Usage:
# make docker.down.demo
docker.down.demo:
docker compose -f demo/docker-compose.yml down --rmi=local -v
# Stop E2E tests environment in Docker Compose and remove all related
# containers.
#
# Usage:
# make docker.down.e2e
docker.down.e2e: down.control
@make docker.down.medea
docker compose -f e2e/docker-compose.yml down --rmi=local -v
# Stop Medea media server in Docker Compose environment
# and remove all related containers.
#
# Usage:
# make docker.down.medea
docker.down.medea:
docker compose -f docker-compose.medea.yml down --rmi=local -v
# Stop dockerized WebDriver and remove all related containers.
#
# Usage:
# make docker.down.webdriver [browser=(chrome|firefox)]
docker.down.webdriver:
-docker stop medea-webdriver-$(if $(call eq,$(browser),),chrome,$(browser))
# Pull project Docker images from Container Registry.
#
# Usage:
# make docker.pull
# [image=(medea-control-api-mock|medea-demo)]
# [repos=($(IMAGE_REPO)|<prefix-1>[,<prefix-2>...])]