-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakefile
More file actions
111 lines (95 loc) · 3.67 KB
/
makefile
File metadata and controls
111 lines (95 loc) · 3.67 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
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin) # macOS
CORES := $(shell sysctl -n hw.ncpu)
else # Linux
CORES := $(shell nproc)
endif
JOBS := $(shell [ $(CORES) -gt 2 ] && expr $(CORES) - 2 || echo 1)
# Define the CLEAN flag (default is no) that will clean the build directory
CLEAN ?= no
# Define the RELEASE flag (default is yes) that will build in release mode
RELEASE ?= no
# Define the VERBOSE flag (default is no) that will print the commands
VERBOSE ?= no
# Define the CRATES_ONLY flag (default is no) that will build only the crates
CRATES_ONLY ?= no
# Define the CRATES_FORCE_REBUILD flag (default is no) that will force the crates to be rebuilt
CRATES_FORCE_REBUILD ?= no
# Define the INSPECTOR flag (default is no) that will build the inspector
INSPECTOR ?= no
# This makefile defines a function `build_crates` to build Rust crates using Cargo.
#
# Usage:
# $(call build_crates, <target>)
#
# Parameters:
# <target> - The target triple for which the crates should be built (e.g., x86_64-unknown-linux-gnu).
define build_crates
@start_time=$$(date +%s); \
build_args=""; \
if [ "$(RELEASE)" = "yes" ]; then \
build_args="$$build_args --release"; \
fi; \
if [ "$(VERBOSE)" = "yes" ]; then \
build_args="$$build_args --verbose"; \
fi; \
FORCE_REBUILD=$${CRATES_FORCE_REBUILD:-0} \
cargo build --target=$(1) $$build_args; \
end_time=$$(date +%s); \
elapsed_time=$$((end_time - start_time)); \
echo "Built the crates for $(1), +$${elapsed_time}s"
endef
define create_universal_apple_library
lipo -create -output build/output/crates/universal-apple-darwin/$(1)/$(2).a \
build/output/crates/aarch64-apple-darwin/$(1)/$(2).a \
build/output/crates/x86_64-apple-darwin/$(1)/$(2).a
endef
# This target creates a universal Apple binary by combining the binaries for
# aarch64-apple-darwin and x86_64-apple-darwin architectures using the `lipo` tool.
define create_universal_apple_binary
@start_time=$$(date +%s); \
RELEASE_DIR=$(if $(filter yes,$(RELEASE)),release,debug); \
mkdir -p build/output/crates/universal-apple-darwin/$$RELEASE_DIR; \
$(call create_universal_apple_library,$$RELEASE_DIR,libjsar_jsbindings); \
$(call create_universal_apple_library,$$RELEASE_DIR,libjsar_runtime_apis); \
end_time=$$(date +%s); \
elapsed_time=$$((end_time - start_time)); \
echo "Created the crates for universal-apple-darwin/$${RELEASE_DIR}, +$${elapsed_time}s"
endef
jsbundle:
@echo "Building jsbundle..."
node ./build/build-jsbundle.cjs \
--clean=$(CLEAN) \
--minify=$(MINIFY) \
--without-pack=$(NO_PACK)
darwin:
@echo "Building for darwin(JOBS=${JOBS})..."
@$(call build_crates,aarch64-apple-darwin)
@$(call build_crates,x86_64-apple-darwin)
@$(call create_universal_apple_binary)
ifeq ($(CRATES_ONLY), no)
$(MAKE) -C ./build darwin -j$(JOBS)
endif
android:
@echo "Building for android(JOBS=${JOBS})..."
@$(call build_crates,aarch64-linux-android)
ifeq ($(CRATES_ONLY), no)
$(MAKE) -C ./build android
endif
windows:
@echo "Building for windows(JOBS=${JOBS})..."
@$(call build_crates,x86_64-pc-windows-msvc)
ifeq ($(CRATES_ONLY), no)
$(MAKE) -C ./build windows
endif
lint:
@echo "Running tslint..."
npm run lint
@echo "Running clang-format..."
./tools/clang-format-check.sh
test:
cargo test
ifeq ($(CRATES_ONLY), no)
ctest --test-dir build/targets/darwin
endif
.PHONY: jsbundle darwin android test all