-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
798 lines (654 loc) · 28.3 KB
/
Makefile
File metadata and controls
798 lines (654 loc) · 28.3 KB
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
# Makefile: Always run Cargo steps, but only re-run downstream generators when inputs change
.PHONY: help
# Parse the comment starting with a double ## next to a target as the target description
# in the help message
help: ## Show this help message
@grep -E '^[a-zA-Z0-9_.-]+:.*?## ' $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
SHELL := /usr/bin/env bash
# Only build in release mode if explicitly requested by
# setting the `RELEASE` variable to any non-empty value, e.g.
#
# make wasm RELEASE=1
#
# This will also optimize the Wasm binary.
ifeq ($(RELEASE),)
CARGO_BUILD_ARGS :=
XCODE_CONFIG := Debug
GRADLE_BUILD_TYPE := Debug
RELEASE_MODE := debug
else
CARGO_BUILD_ARGS := --release
XCODE_CONFIG := Release
GRADLE_BUILD_TYPE := Release
RELEASE_MODE := release
endif
TARGET_DIR := target/$(RELEASE_MODE)
# Detect host platform for NDK and library extensions
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
PLATFORM_DIR := linux-x86_64
LIBRARY_EXTENSION := so
else ifeq ($(UNAME_S),Darwin)
PLATFORM_DIR := darwin-x86_64
LIBRARY_EXTENSION := dylib
else
$(error Unsupported host platform $(UNAME_S))
endif
# Make platform-specific LLVM toolchain available to Android builds.
export PATH := $(PATH):$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(PLATFORM_DIR)/bin
# Default goal
.DEFAULT_GOAL := local
# Directory we store timestamps in
STAMPS := .stamps
# We're writing a timestamp into the file because CI relies on file hashes to
# change when the stamp files are updated.
TOUCH_STAMP = @mkdir -p $(STAMPS) && echo "$$(date)" > $@
#-------------------------------------------------------------------------------
# Rust file-based heuristics
#-------------------------------------------------------------------------------
# Relevant crates for FFI builds
CRATES := crypto crypto-ffi keystore crypto-macros
# Workspace-level Cargo config
WORKSPACE_CARGO_FILES := Cargo.toml Cargo.lock
# Per-crate manifests
CRATE_MANIFESTS := $(addsuffix /Cargo.toml,$(CRATES))
# Enumerate all .rs files in relevant crates
RUST_RS_FILES := $(shell find $(CRATES) \( -type d -name rust_modules -o -type d -name node_modules \) -prune -o \
-type f -name '*.rs' -print 2>/dev/null | LC_ALL=C sort)
# Files relevant to build interop
INTEROP_RS_FILES := $(shell find interop -type f -name '*.rs' 2>/dev/null | LC_ALL=C sort)
INTEROP_TS_FILES := $(shell find interop -type f -name '*.ts' -not -path "*/node_modules/*" 2>/dev/null | LC_ALL=C sort)
INTEROP_MANIFEST := interop/Cargo.toml
INTEROP_SOURCES := $(INTEROP_RS_FILES) $(INTEROP_TS_FILES) $(INTEROP_MANIFEST)
# Complete dependency set for FFI-related Cargo builds
RUST_SOURCES := $(WORKSPACE_CARGO_FILES) $(CRATE_MANIFESTS) $(RUST_RS_FILES)
# Used by CI to calculate a hash of prerequisite files of a make rule
%-hash-deps:
@if [ -z "$($*-deps)" ]; then \
echo "ERROR: The \"$*-deps\" variable doesn't exist in the Makefile."; exit 1; \
fi
@set -euo pipefail; \
hash=$$(sha256sum $($*-deps) | sha256sum | awk '{print $$1}'); \
echo "$$hash"
#-------------------------------------------------------------------------------
# Kotlin file-based heuristics
#-------------------------------------------------------------------------------
KT_WRAPPER = ./crypto-ffi/bindings/shared/src/commonMain/kotlin
KT_TESTS = ./crypto-ffi/bindings/shared/src/commonTest
KT_BENCHMARKS = ./crypto-ffi/bindings/jvm/src/jmh/
KT_INTEROP = ./interop/src/clients/android-interop/src/main/java
KT_FILES := $(shell find $(KT_WRAPPER) $(KT_TESTS) $(KT_INTEROP) $(KT_BENCHMARKS) -type f -name '*.kt')
KT_GRADLE_FILES = $(shell find . -type f -name '*.kts')
#-------------------------------------------------------------------------------
# Build FFI artifacts
#-------------------------------------------------------------------------------
# Build bindgen binary (independent of rust sources changing)
#
# We need to build this binary if it does not exist, or if the uniffi version
# has changed (see https://github.com/mozilla/uniffi-rs/issues/2622).
GET_UNIFFI_VERSION = perl -ne 'print "$1\n" if /^uniffi\s=\s"([^"]+)"/' Cargo.toml
UNIFFI_VERSION_FILE := $(STAMPS)/uniffi-version
# Version file: only rewrite if version changed
$(UNIFFI_VERSION_FILE): Cargo.lock
current_version="$$( $(GET_UNIFFI_VERSION) )"; \
if [ ! -f $@ ] || [ "$$(cat $@)" != "$$current_version" ]; then \
mkdir -p .stamps; \
echo "$$current_version" > $@; \
fi
UNIFFI_BINDGEN := $(TARGET_DIR)/uniffi-bindgen
uniffi-bindgen-deps := $(UNIFFI_VERSION_FILE)
$(UNIFFI_BINDGEN): $(uniffi-bindgen-deps)
cargo build $(CARGO_BUILD_ARGS) \
--locked \
--features uniffi/cli \
--bin uniffi-bindgen
# Build the FFI library
FFI_LIBRARY := $(TARGET_DIR)/libcore_crypto_ffi.$(LIBRARY_EXTENSION)
ffi-library-deps := $(RUST_SOURCES)
$(FFI_LIBRARY): $(ffi-library-deps)
cargo build $(CARGO_BUILD_ARGS) \
--locked \
--package core-crypto-ffi \
--lib
# Make aliases
.PHONY: uniffi-bindgen ffi-library
uniffi-bindgen: $(UNIFFI_BINDGEN) ## Build the uniffi bindgen binary
ffi-library: $(FFI_LIBRARY) ## Build the libcore_crypto_ffi library
#-------------------------------------------------------------------------------
# Use stamp files for generators: only re-run when inputs change
#-------------------------------------------------------------------------------
bindings-deps := $(UNIFFI_BINDGEN) $(FFI_LIBRARY)
# Swift bindings
UNIFFI_SWIFT_OUTPUT := crypto-ffi/bindings/swift/WireCoreCryptoUniffi/WireCoreCryptoUniffi/core_crypto_ffi.swift
bindings-swift-deps := $(bindings-deps)
ifneq ($(UNAME_S),Darwin)
$(UNIFFI_SWIFT_OUTPUT):
$(warning Skipping build for "bindings-swift", as swift bindings generation is only supported on \
Darwin because OpenSSL can't be cross-compiled on non-Darwin systems; this is "$(UNAME_S)".)
else
$(UNIFFI_SWIFT_OUTPUT): $(bindings-swift-deps)
mkdir -p crypto-ffi/bindings/swift/WireCoreCryptoUniffi/WireCoreCryptoUniffi
$(UNIFFI_BINDGEN) generate \
--config crypto-ffi/uniffi.toml \
--language swift \
--out-dir crypto-ffi/bindings/swift/WireCoreCryptoUniffi/WireCoreCryptoUniffi \
--library $(FFI_LIBRARY)
endif
.PHONY: bindings-swift swift
bindings-swift: $(UNIFFI_SWIFT_OUTPUT) ## Generate Swift bindings
swift: bindings-swift $(STAMPS)/docs-swift
# Kotlin-Android bindings
UNIFFI_ANDROID_OUTPUT := crypto-ffi/bindings/android/src/main/uniffi/com/wire/crypto/core_crypto_ffi.kt
bindings-kotlin-android-deps := $(bindings-deps)
$(UNIFFI_ANDROID_OUTPUT): $(bindings-kotlin-android-deps)
mkdir -p crypto-ffi/bindings/android/src/main/uniffi
$(UNIFFI_BINDGEN) generate \
--config crypto-ffi/uniffi-android.toml \
--language kotlin \
--no-format \
--out-dir crypto-ffi/bindings/android/src/main/uniffi \
--library $(FFI_LIBRARY)
.PHONY: bindings-kotlin-android
bindings-kotlin-android: $(UNIFFI_ANDROID_OUTPUT) ## Generate Kotlin bindings for Android
# Kotlin-JVM bindings
UNIFFI_JVM_OUTPUT := crypto-ffi/bindings/jvm/src/main/uniffi/com/wire/crypto/core_crypto_ffi.kt
bindings-kotlin-jvm-deps := $(bindings-deps)
$(UNIFFI_JVM_OUTPUT): $(bindings-kotlin-jvm-deps)
mkdir -p crypto-ffi/bindings/jvm/src/main/uniffi
$(UNIFFI_BINDGEN) generate \
--config crypto-ffi/uniffi.toml \
--language kotlin \
--no-format \
--out-dir crypto-ffi/bindings/jvm/src/main/uniffi \
--library $(FFI_LIBRARY)
.PHONY: bindings-kotlin-jvm
bindings-kotlin-jvm: $(UNIFFI_JVM_OUTPUT) ## Generate Kotlin bindings for JVM
# Grouped Kotlin bindings
.PHONY: bindings-kotlin
bindings-kotlin: bindings-kotlin-android bindings-kotlin-jvm ## Generate all Kotlin bindings
#-------------------------------------------------------------------------------
# iOS builds
#-------------------------------------------------------------------------------
ios-device-deps := $(RUST_SOURCES)
IOS_DEVICE := target/aarch64-apple-ios/$(RELEASE_MODE)/libcore_crypto_ffi.$(LIBRARY_EXTENSION)
$(IOS_DEVICE): $(ios-device-deps)
IPHONEOS_DEPLOYMENT_TARGET=16.4 \
cargo rustc --locked \
--target aarch64-apple-ios \
--crate-type=cdylib \
--crate-type=staticlib \
--package core-crypto-ffi \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: ios-device
ios-device: $(IOS_DEVICE) ## Build core-crypto-ffi for aarch64-apple-ios for iOS 16.4 (macOS only)
IOS_SIMULATOR_ARM := target/aarch64-apple-ios-sim/$(RELEASE_MODE)/libcore_crypto_ffi.$(LIBRARY_EXTENSION)
ios-simulator-arm-deps := $(RUST_SOURCES)
$(IOS_SIMULATOR_ARM): $(ios-simulator-arm-deps)
CRATE_CC_NO_DEFAULTS=1 \
TARGET_CFLAGS="--target=arm64-apple-ios16.0.0-simulator \
-mios-simulator-version-min=16.4 \
-isysroot $$(xcrun --show-sdk-path --sdk iphonesimulator)" \
cargo rustc --locked \
--target aarch64-apple-ios-sim \
--crate-type=cdylib \
--crate-type=staticlib \
--package core-crypto-ffi \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: ios-simulator-arm
ios-simulator-arm: $(IOS_SIMULATOR_ARM) ## Build core-crypto-ffi for aarch64-apple-ios-sim, iOS 16.4 (macOS only)
.PHONY: ios
ios: ios-device ios-simulator-arm
# Build XCFramework (macOS only)
ios-create-xcframework-deps := $(IOS_DEVICE) $(IOS_SIMULATOR_ARM) $(UNIFFI_SWIFT_OUTPUT)
$(STAMPS)/ios-create-xcframework: $(ios-create-xcframework-deps)
cd crypto-ffi/bindings/swift && \
set -e; \
xcodebuild archive \
-project 'WireCoreCryptoUniffi/WireCoreCryptoUniffi.xcodeproj' \
-scheme 'WireCoreCryptoUniffi' \
-configuration Release \
-archivePath 'WireCoreCryptoUniffi-ios.xcarchive' \
-destination 'generic/platform=ios' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES; \
xcodebuild archive \
-project 'WireCoreCryptoUniffi/WireCoreCryptoUniffi.xcodeproj' \
-scheme 'WireCoreCryptoUniffi' \
-configuration Release \
-archivePath 'WireCoreCryptoUniffi-simulator.xcarchive' \
-destination 'generic/platform=ios Simulator' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES; \
xcodebuild -create-xcframework \
-archive 'WireCoreCryptoUniffi-ios.xcarchive' \
-framework 'WireCoreCryptoUniffi.framework' \
-archive 'WireCoreCryptoUniffi-simulator.xcarchive' \
-framework 'WireCoreCryptoUniffi.framework' \
-output 'WireCoreCryptoUniffi.xcframework'; \
xcodebuild archive \
-project 'WireCoreCrypto/WireCoreCrypto.xcodeproj' \
-scheme 'WireCoreCrypto' \
-configuration Release \
-archivePath 'WireCoreCrypto-ios.xcarchive' \
-destination 'generic/platform=ios' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES; \
xcodebuild archive \
-project 'WireCoreCrypto/WireCoreCrypto.xcodeproj' \
-scheme 'WireCoreCrypto' \
-configuration Release \
-archivePath 'WireCoreCrypto-simulator.xcarchive' \
-destination 'generic/platform=ios Simulator' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES; \
xcodebuild -create-xcframework \
-archive 'WireCoreCrypto-ios.xcarchive' \
-framework 'WireCoreCrypto.framework' \
-archive 'WireCoreCrypto-simulator.xcarchive' \
-framework 'WireCoreCrypto.framework' \
-output 'WireCoreCrypto.xcframework'; \
zip -r WireCoreCrypto.xcframework.zip WireCoreCrypto.xcframework; \
zip -r WireCoreCryptoUniffi.xcframework.zip WireCoreCryptoUniffi.xcframework; \
rm -rf WireCoreCryptoUniffi.xcframework; \
rm -rf WireCoreCryptoUniffi-ios.xcarchive; \
rm -rf WireCoreCryptoUniffi-simulator.xcarchive; \
rm -rf WireCoreCrypto.xcframework; \
rm -rf WireCoreCrypto-ios.xcarchive; \
rm -rf WireCoreCrypto-simulator.xcarchive
$(TOUCH_STAMP)
.PHONY: ios-create-xcframework
ios-create-xcframework: $(STAMPS)/ios-create-xcframework ## Build the XCode framework (macOS only)
ios-test-deps := $(IOS_SIMULATOR_ARM) $(UNIFFI_SWIFT_OUTPUT) $(SWIFT_FILES)
$(STAMPS)/ios-test: $(ios-test-deps)
$(SHELL) scripts/run-ios-tests.sh $(XCODE_CONFIG)
$(TOUCH_STAMP)
#-------------------------------------------------------------------------------
# Android builds
#-------------------------------------------------------------------------------
# Check NDK env
.PHONY: android-env
android-env:
@if [ -z "$(ANDROID_NDK_HOME)" ]; then \
echo "ERROR: set ANDROID_NDK_HOME"; exit 1; \
fi
@ndk_version=$$(perl -ne 's/Pkg\.Revision = // and print' $(ANDROID_NDK_HOME)/source.properties) && \
echo "Using Android NDK $${ndk_version} at $(ANDROID_NDK_HOME)";
ANDROID_ARMv7 := target/armv7-linux-androideabi/$(RELEASE_MODE)/libcore_crypto_ffi.so
android-armv7-deps := $(RUST_SOURCES)
$(ANDROID_ARMv7): $(android-armv7-deps)
$(MAKE) android-env;
cargo rustc --locked \
--target armv7-linux-androideabi \
--package core-crypto-ffi \
--crate-type=cdylib --crate-type=staticlib \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: android-armv7
android-armv7: $(ANDROID_ARMv7) ## Build core-crypto-ffi for armv7-linux-androideabi
ANDROID_ARMv8 := target/aarch64-linux-android/$(RELEASE_MODE)/libcore_crypto_ffi.so
android-armv8-deps := $(RUST_SOURCES)
$(ANDROID_ARMv8): $(android-armv8-deps)
$(MAKE) android-env;
cargo rustc --locked \
--target aarch64-linux-android \
--package core-crypto-ffi \
--crate-type=cdylib --crate-type=staticlib \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: android-armv8
android-armv8: $(ANDROID_ARMv8) ## Build core-crypto-ffi for aarch64-linux-android
ANDROID_X86 := target/x86_64-linux-android/$(RELEASE_MODE)/libcore_crypto_ffi.so
android-x86-deps := $(RUST_SOURCES)
$(ANDROID_X86): $(android-x86-deps)
$(MAKE) android-env;
# Link clang_rt.builtins statically for x86_64 Android
cargo rustc --locked \
--target x86_64-linux-android \
--package core-crypto-ffi \
--crate-type=cdylib --crate-type=staticlib \
$(CARGO_BUILD_ARGS) -- \
-C strip=symbols \
-l static=clang_rt.builtins-x86_64-android \
-L $$($(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(PLATFORM_DIR)/bin/clang --print-resource-dir)/lib/linux
.PHONY: android-x86
android-x86: $(ANDROID_X86) ## Build core-crypto-ffi for x86_64-linux-android
.PHONY: android
android-deps := $(ANDROID_ARMv7) $(ANDROID_ARMv8) $(ANDROID_X86) $(UNIFFI_ANDROID_OUTPUT)
android: $(android-deps) ## Build all Android targets
cd crypto-ffi/bindings && \
./gradlew android:assemble$(GRADLE_BUILD_TYPE)
ifeq ($(UNAME_S),Linux)
ANDROID_TEST_LIB := $(ANDROID_X86)
android-test-lib-deps := $(android-x86-deps)
android-test-lib: android-x86 ## Build core-crypto-ffi for Android (automatically select the target based on the host machine)
else ifeq ($(UNAME_S),Darwin)
ANDROID_TEST_LIB := $(ANDROID_ARMv8)
android-test-lib-deps := $(android-armv8-deps)
android-test-lib: android-armv8
else
$(error Unsupported host platform for android-test-lib: $(UNAME_S))
endif
android-test-deps := $(ANDROID_TEST_LIB) $(UNIFFI_ANDROID_OUTPUT) $(KT_FILES)
$(STAMPS)/android-test: $(android-test-deps)
$(SHELL) scripts/run-android-tests.sh
$(TOUCH_STAMP)
#-------------------------------------------------------------------------------
# JVM native builds (Darwin + Linux)
#-------------------------------------------------------------------------------
# darwin build
JVM_DARWIN_LIB := target/aarch64-apple-darwin/$(RELEASE_MODE)/libcore_crypto_ffi.$(LIBRARY_EXTENSION)
jvm-darwin-deps := $(RUST_SOURCES)
$(JVM_DARWIN_LIB): $(jvm-darwin-deps)
cd crypto-ffi && \
cargo rustc --locked \
--target aarch64-apple-darwin \
--package core-crypto-ffi \
--crate-type=cdylib --crate-type=staticlib \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: jvm-darwin
jvm-darwin: $(JVM_DARWIN_LIB) ## Build core-crypto-ffi for JVM on aarch64-apple-darwin
# linux build
JVM_LINUX_LIB := target/x86_64-unknown-linux-gnu/$(RELEASE_MODE)/libcore_crypto_ffi.$(LIBRARY_EXTENSION)
jvm-linux-deps := $(RUST_SOURCES)
$(JVM_LINUX_LIB): $(jvm-linux-deps)
cd crypto-ffi && \
cargo rustc --locked \
--target x86_64-unknown-linux-gnu \
--package core-crypto-ffi \
--crate-type=cdylib --crate-type=staticlib \
$(CARGO_BUILD_ARGS) -- -C strip=symbols
.PHONY: jvm-linux
jvm-linux: $(JVM_LINUX_LIB) ## Build core-crypto-ffi for JVM on x86_64-unknown-linux-gnu
.PHONY: jvm
ifeq ($(UNAME_S),Linux)
JVM_LIB := $(JVM_LINUX_LIB)
jvm-deps := $(jvm-linux-deps)
jvm: jvm-linux ## Build core-crypto-ffi for JVM (automatically select the target based on the host machine)
else ifeq ($(UNAME_S),Darwin)
JVM_LIB := $(JVM_DARWIN_LIB)
jvm-deps := $(jvm-darwin-deps)
jvm: jvm-darwin
else
$(error Unsupported host platform for jvm: $(UNAME_S))
endif
jvm-test-deps := $(JVM_LIB) $(UNIFFI_JVM_OUTPUT) $(KT_FILES)
$(STAMPS)/jvm-test: $(jvm-test-deps)
cd crypto-ffi/bindings && \
./gradlew jvm:test --rerun
$(TOUCH_STAMP)
$(STAMPS)/jvm-bench: $(jvm-test-deps) $(KT_BENCHMARKS)
cd crypto-ffi/bindings && \
./gradlew :jvm:jmh
$(TOUCH_STAMP)
#-------------------------------------------------------------------------------
# KMP (Kotlin Multiplatform) builds
#-------------------------------------------------------------------------------
kmp-jvm-test-deps := $(FFI_LIBRARY) $(JVM_LIB) $(KT_FILES)
$(STAMPS)/kmp-jvm-test: $(kmp-jvm-test-deps)
cd crypto-ffi/bindings && \
./gradlew core-crypto-kmp:jvmTest --rerun
$(TOUCH_STAMP)
#-------------------------------------------------------------------------------
# TypeScript / JS tasks
#-------------------------------------------------------------------------------
JS_DIR := crypto-ffi/bindings/js
JS_SRC_DIR := $(JS_DIR)/src
PACKAGE_JSON := $(JS_DIR)/package.json
BUN_LOCK := $(JS_DIR)/bun.lock
BUNFIG := $(JS_DIR)/bunfig.toml
GEN_DIR := $(JS_SRC_DIR)/autogenerated
# find all .ts source files under src/ except `*.d.ts`
TS_SRCS := $(shell find $(JS_SRC_DIR) -type f -name '*.ts' -not -name '*.d.ts' 2>/dev/null | LC_ALL=C sort)
TS_OUT_DIR:= $(JS_DIR)/out
TS_OUT := $(TS_OUT_DIR)/corecrypto.d.ts $(TS_OUT_DIR)/corecrypto.js $(wildcard $(TS_OUT_DIR)/wasm-bindgen/*)
# In release mode, fail if the lockfile does not match
BUN_FROZEN_LOCKFILE := $(if $(RELEASE),--frozen-lockfile)
# Install JS deps with Bun
# We want the `node_modules` directory to exist, and we want never to manually create it,
# and we want to ensure that this runs if the directory does not exist. So:
NODE_MODULES := $(JS_DIR)/node_modules/.stamp
$(BUN_LOCK) $(NODE_MODULES) &: $(PACKAGE_JSON)
bun install $(BUN_FROZEN_LOCKFILE) --cwd $(JS_DIR)
# if the lockfile is unchanged, bun reports "no changes" and does not update the lock file
# which would be fine, bun is fast, except that every step thereafter is dirty
# so we update the mtime manually here
@touch $(BUN_LOCK)
# also ensure the `NODE_MODULES` stamp file exists / is current
@touch $(NODE_MODULES)
.PHONY: bun-deps
bun-deps: $(BUN_LOCK) $(NODE_MODULES) ## Install JS dependencies using bun
# always remove old outputs
.PHONY: ts-clean
ts-clean: ## Cleanup old TypeScript build outputs
@rm -rf $(TS_OUT_DIR) \
&& rm -rf $(GEN_DIR) \
&& rm -rf $(JS_DIR)/rust_modules
WASM_GEN := $(wildcard $(GEN_DIR)/wasm-bindgen/*) $(GEN_DIR)/core_crypto_ffi.ts
# As soon as ubrn allows reusage of an existing ffi lib, we need to depend on it here.
wasm-build-deps := $(RUST_SOURCES) $(BUN_LOCK) $(NODE_MODULES) $(PACKAGE_JSON) $(BUNFIG)
# index.web.ts is generated but unused so we remove it
# We remove library files because wasm-only symbols cause errors when running ios/jvm tests with these files
# Note that ubrn always generates these in debug mode
# We run ubrn in separated steps and copy our lock file and run cargo check to ensure rust_modules uses our wasm-bindgen version
$(WASM_GEN): $(wasm-build-deps)
cd $(JS_DIR) && \
bun ubrn build web --no-wasm-pack && \
cp ../../../Cargo.lock ./rust_modules/wasm/Cargo.lock && \
cd ./rust_modules/wasm && \
cargo check && \
cd ../../ && \
RUSTFLAGS="" bun ubrn build web $(CARGO_BUILD_ARGS) --no-cargo && \
rm src/index.web.ts && \
cd ../../../target/debug && \
rm libcore_crypto_ffi.a && \
rm libcore_crypto_ffi.d && \
rm libcore_crypto_ffi.$(LIBRARY_EXTENSION) && \
rm libcore_crypto_ffi.rlib
wasm-build: $(WASM_GEN)
# generate TypeScript defs only when corecrypto.js changed
ts-deps := $(TS_SRCS) $(WASM_GEN)
$(TS_OUT): $(ts-deps)
cd $(JS_DIR) && \
bun build src/CoreCrypto.ts \
--target browser \
--format esm \
--outdir out \
--entry-naming "corecrypto.[ext]" && \
mkdir -p out/autogenerated/ && \
mkdir -p out/autogenerated/wasm-bindgen && \
cp src/autogenerated/wasm-bindgen/index_bg.wasm out/autogenerated/wasm-bindgen/ && \
cp src/autogenerated/wasm-bindgen/index_bg.wasm.d.ts out/autogenerated/wasm-bindgen/ && \
bun x dts-bundle-generator \
--project tsconfig.json \
-o out/corecrypto.d.ts \
--no-check \
--export-referenced-types false \
src/CoreCrypto.ts
@touch $@
.PHONY: ts
ts: $(TS_OUT) ## Build the TypeScript wrapper
ts-test-deps := $(TS_OUT) $(TS_TEST_FILES)
# run WebDriver tests + bun’s built-in tests
$(STAMPS)/ts-test: $(ts-test-deps)
@set -euo pipefail; \
cd $(JS_DIR) && \
if [ -n "$(TEST)" ]; then \
bun x wdio run wdio.conf.ts --mochaOpts.grep "$(TEST)"; \
bun test --filter "$(TEST)"; \
else \
bun x wdio run wdio.conf.ts --spec test/wdio/*.test.ts; \
bun test; \
fi
$(TOUCH_STAMP)
# run WebDriver benches
.PHONY: ts-bench
ts-bench: $(TS_OUT) ## Run TypeScript wrapper benches in Chrome via wdio
cd $(JS_DIR) && \
bun x wdio run wdio.conf.ts --spec benches/**/*.bench.ts --log-level warn
web-package: $(TS_OUT) ## Package the ready-to-release tarball
@cd $(JS_DIR) && \
bun pm pack --quiet
#-------------------------------------------------------------------------------
# interop test
#-------------------------------------------------------------------------------
# We're not building the interop binary in release mode, so it's in `target/debug`.
INTEROP_OUT := target/debug/interop
.PHONY: interop-build
interop-build: $(INTEROP_OUT) ## Build the interop test binary (in debug mode, ignores any `RELEASE` value)
interop-build-deps := $(INTEROP_SOURCES)
$(INTEROP_OUT): $(interop-build-deps)
cargo build --bin interop
interop-test-deps := $(INTEROP_OUT) $(TS_OUT) $(ANDROID_TEST_LIB) $(UNIFFI_ANDROID_OUTPUT) $(KT_FILES) $(KT_GRADLE_FILES)
ifeq ($(UNAME_S),Darwin)
interop-test-deps := $(interop-test-deps) $(IOS_SIMULATOR_ARM) $(UNIFFI_SWIFT_OUTPUT) $(SWIFT_FILES)
endif
$(STAMPS)/interop-test: $(interop-test-deps)
$(SHELL) scripts/run-interop-test.sh $(XCODE_CONFIG)
$(TOUCH_STAMP)
#-------------------------------------------------------------------------------
# Documentation targets
#-------------------------------------------------------------------------------
# Rust generic docs
$(STAMPS)/docs-rust-generic: $(RUST_SOURCES)
cargo doc --no-deps
$(TOUCH_STAMP)
.PHONY: docs-rust-generic
docs-rust-generic: $(STAMPS)/docs-rust-generic ## Generate Rust docs for the host platform's default target ("generic")
# Rust WASM docs
$(STAMPS)/docs-rust-wasm: $(RUST_SOURCES)
cargo doc --no-deps --target=wasm32-unknown-unknown
$(TOUCH_STAMP)
.PHONY: docs-rust-wasm
docs-rust-wasm: $(STAMPS)/docs-rust-wasm ## Generate Rust docs for wasm32-unknown-unknown
# Kotlin docs
KOTLIN_SOURCES := $(shell find crypto-ffi/bindings/shared/src/commonMain/kotlin \
-type f -name '*.kt' 2>/dev/null | LC_ALL=C sort)
DOCS_KOTLIN := target/kotlin/doc/html/index.html
$(DOCS_KOTLIN): $(JVM_LIB) $(KOTLIN_SOURCES)
cd crypto-ffi/bindings && ./gradlew jvm:dokkaGeneratePublicationHtml
mkdir -p target/kotlin/doc
cp -R crypto-ffi/bindings/jvm/build/dokka/html/ target/kotlin/doc
.PHONY: docs-kotlin
docs-kotlin-deps := $(jvm-deps) $(KOTLIN_SOURCES)
docs-kotlin: $(DOCS_KOTLIN) ## Generate Kotlin docs
# TypeScript docs via Typedoc
$(STAMPS)/docs-ts: $(TS_OUT)
cd crypto-ffi/bindings/js && \
bun typedoc \
--basePath ./ \
--entryPoints src/CoreCrypto.ts \
--tsconfig tsconfig.json \
--out ../../../target/typescript/doc \
--readme none \
--treatWarningsAsErrors \
--plugin ./typedoc-ignore-warnings.cjs
$(TOUCH_STAMP)
.PHONY: docs-ts
docs-ts: $(STAMPS)/docs-ts ## Generate TypeScript docs
# Swift docs via Jazzy (macOS only)
docs-swift-deps := $(IOS_DEVICE) $(IOS_SIMULATOR_ARM) $(UNIFFI_SWIFT_OUTPUT)
$(STAMPS)/docs-swift: $(docs-swift-deps)
mkdir -p target/swift/doc
cd crypto-ffi/bindings/swift/WireCoreCrypto && \
jazzy \
--modules WireCoreCrypto,WireCoreCryptoUniffi \
--build-tool-arguments -project,WireCoreCrypto.xcodeproj,-scheme,WireCoreCrypto,-configuration,$(XCODE_CONFIG) \
-o ../../../../target/swift/doc
$(TOUCH_STAMP)
.PHONY: docs-swift
docs-swift: $(STAMPS)/docs-swift ## Generate Swift iOS docs (macOS only)
# Group all docs
.PHONY: docs
docs: docs-rust-generic docs-rust-wasm docs-kotlin docs-ts $(if $(filter Darwin,$(UNAME_S)),docs-swift) ## Generate all docs (excluding Swift on non-Darwin platforms)
#-------------------------------------------------------------------------------
# Aggregate targets
#-------------------------------------------------------------------------------
.PHONY: wasm bindings local all clean
wasm: ts ## Alias for ts
bindings: bindings-kotlin $(if $(filter Darwin,$(UNAME_S)),bindings-swift) ts ## Generate all bindings
local: bindings ts-fmt ## Generate and format all bindings
all: android wasm jvm $(if $(filter Darwin,$(UNAME_S)),ios) docs ## Generate bindings for all platforms (android, iOS, wasm) and generate docs
clean: ts-clean ## Run cargo clean and the ts-clean target, remove all stamps
cargo clean
rm -rf $(STAMPS)
#-------------------------------------------------------------------------------
# Formatting and linting
#-------------------------------------------------------------------------------
# Rust
$(STAMPS)/rust-fmt: $(RUST_SOURCES)
cargo +nightly fmt --all
$(TOUCH_STAMP)
.PHONY: rust-fmt
rust-fmt: $(STAMPS)/rust-fmt ## Format Rust files via cargo fmt
$(STAMPS)/rust-check: $(RUST_SOURCES)
cargo +nightly fmt --all -- --check && \
cargo check --locked --all-targets && \
cargo check --locked --target wasm32-unknown-unknown && \
cargo clippy --locked --all-targets && \
cargo clippy --locked --target wasm32-unknown-unknown
$(TOUCH_STAMP)
.PHONY: rust-check
rust-check: $(STAMPS)/rust-check ## Lint Rust files via cargo clippy and cargo check
# Swift
SWIFT_INTEROP = ./interop/src/clients/InteropClient
SWIFT_WRAPPER = ./crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto
SWIFT_TESTS = ./crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCryptoTests
SWIFT_FILES := $(shell find $(SWIFT_WRAPPER) $(SWIFT_TESTS) $(SWIFT_INTEROP) -type f -name '*.swift')
$(STAMPS)/swift-fmt: $(SWIFT_FILES)
swift format -r -i $(SWIFT_INTEROP) $(SWIFT_TESTS) $(SWIFT_WRAPPER)
$(TOUCH_STAMP)
.PHONY: swift-fmt
swift-fmt: $(STAMPS)/swift-fmt ## Format Swift files via swift-format
$(STAMPS)/swift-check: $(SWIFT_FILES)
swift format lint -r -s $(SWIFT_INTEROP) $(SWIFT_TESTS) $(SWIFT_WRAPPER) && \
swiftlint --strict $(SWIFT_INTEROP) $(SWIFT_TESTS) $(SWIFT_WRAPPER)
$(TOUCH_STAMP)
.PHONY: swift-check
swift-check: $(STAMPS)/swift-check ## Lint Swift files via swift-format and swift-lint
# Kotlin
$(STAMPS)/kotlin-fmt: $(KT_FILES) $(KT_GRADLE_FILES)
ktlint --format $(KT_FILES) $(KT_GRADLE_FILES)
$(TOUCH_STAMP)
.PHONY: kotlin-fmt
kotlin-fmt: $(STAMPS)/kotlin-fmt ## Format Kotlin files via ktlint
$(STAMPS)/kotlin-check: $(KT_FILES) $(KT_GRADLE_FILES)
ktlint $(KT_WRAPPER) $(KT_TESTS) $(KT_INTEROP) $(KT_GRADLE_FILES)
$(TOUCH_STAMP)
.PHONY: kotlin-check
kotlin-check: $(STAMPS)/kotlin-check ## Lint Kotlin files via ktlint
# TypeScript
TS_TEST_FILES := $(shell find $(JS_DIR)/test -type f -name '*.ts' 2>/dev/null | LC_ALL=C sort)
$(STAMPS)/ts-fmt: $(TS_SRCS) $(TS_TEST_FILES)
cd $(JS_DIR) && bun eslint --max-warnings=0 --fix
$(TOUCH_STAMP)
.PHONY: ts-fmt
ts-fmt: $(STAMPS)/ts-fmt ## Format TypeScript files via eslint
$(STAMPS)/ts-check: $(TS_SRCS) $(TS_TEST_FILES)
cd $(JS_DIR) && bun eslint --max-warnings=0 && \
bun x tsc --noEmit
$(TOUCH_STAMP)
.PHONY: ts-check
ts-check: $(STAMPS)/ts-check ## Lint TypeScript files via eslint and tsc
.PHONY: fmt
fmt: rust-fmt swift-fmt kotlin-fmt ts-fmt ## Format all files
.PHONY: check
check: rust-check swift-check kotlin-check ts-check ## Run all linters
#-------------------------------------------------------------------------------
# Lazy targets
#-------------------------------------------------------------------------------
LAZY_TARGETS := jvm-test kmp-jvm-test ts-test android-test ios-test interop-test jvm-bench
ts-test: ## Run TypeScript wrapper tests via wdio and bun. Optionally pass TEST=<test> to filter by test name.
kmp-jvm-test: ## Run Kotlin multi-platform tests on JVM
jvm-test: ## Run Kotlin tests on JVM
jvm-bench: ## Run the JVM benchmarks
android-test: ## Run Kotlin tests on Android
ios-test: ## Run Swift tests on iOS (macOS only)
interop-test: ## Run e2e interop test
ifeq ($(LAZY_MAKE),)
.PHONY: $(LAZY_TARGETS)
$(LAZY_TARGETS):
@rm -f $(STAMPS)/$@
@$(MAKE) $(STAMPS)/$@
else
$(LAZY_TARGETS): %: $(STAMPS)/%
endif