-
Notifications
You must be signed in to change notification settings - Fork 55
/
Makefile
131 lines (105 loc) · 3.9 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
ifeq ($(OS),Windows_NT)
build_os := windows
build_arch := amd64
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
build_os := darwin
endif
ifeq ($(UNAME_S),Linux)
build_os := linux
endif
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
build_arch = amd64
else ifeq ($(ARCH),arm64)
build_arch = arm64
else
$(error Architecture not supported yet)
endif
endif
# Compile everything!
build: build-headers build-rust build-java
# Compile the Rust part (only for one target).
# We relay this command to the others, to make sure that
# artifacts are set properly.
build-rust: build-rust-$(build_arch)-$(build_os)
# Compile the Rust part.
build-rust-all-targets: build-rust-amd64-darwin build-rust-arm64-darwin build-rust-amd64-linux build-rust-amd64-windows
build-rust-amd64-darwin:
rustup target add x86_64-apple-darwin
cargo build --release --target=x86_64-apple-darwin
mkdir -p artifacts/darwin-amd64
cp target/x86_64-apple-darwin/release/libwasmer_jni.dylib artifacts/darwin-amd64
install_name_tool -id "@rpath/libwasmer_jni.dylib" ./artifacts/darwin-amd64/libwasmer_jni.dylib
test -h target/current || ln -s x86_64-apple-darwin/release target/current
build-rust-arm64-darwin:
rustup target add aarch64-apple-darwin
cargo build --release --target=aarch64-apple-darwin
mkdir -p artifacts/darwin-arm64
cp target/aarch64-apple-darwin/release/libwasmer_jni.dylib artifacts/darwin-arm64
install_name_tool -id "@rpath/libwasmer_jni.dylib" ./artifacts/darwin-arm64/libwasmer_jni.dylib
test -h target/current || ln -s aarch64-apple-darwin/release target/current
build-rust-amd64-linux:
rustup target add x86_64-unknown-linux-gnu
cargo build --release --target=x86_64-unknown-linux-gnu
mkdir -p artifacts/linux-amd64
cp target/x86_64-unknown-linux-gnu/release/libwasmer_jni.so artifacts/linux-amd64/
test -h target/current || ln -s x86_64-unknown-linux-gnu/release target/current
build-rust-amd64-windows:
rustup target add x86_64-pc-windows-msvc
cargo build --release --target=x86_64-pc-windows-msvc
mkdir -p artifacts/windows-amd64
cp target/x86_64-pc-windows-msvc/release/wasmer_jni.dll artifacts/windows-amd64/
mkdir -p target/current
cp target/x86_64-pc-windows-msvc/release/wasmer_jni.dll target/current/
# Compile the Java part (incl. `build-test`, see `gradlew`).
build-java:
"./gradlew" --info build
# Generate the Java C headers.
build-headers:
"./gradlew" --info generateJniHeaders
# Run the tests.
test: build-headers build-rust test-rust build-java
# Run the Rust tests.
test-rust: test-rust-$(build_arch)-$(build_os)
test-rust-amd64-darwin:
cargo test --lib --release --target=x86_64-apple-darwin
test-rust-arm64-darwin:
cargo test --lib --release --target=aarch64-apple-darwin
test-rust-amd64-linux:
cargo test --lib --release --target=x86_64-unknown-linux-gnu
test-rust-amd64-windows:
cargo test --lib --release --target=x86_64-pc-windows-msvc
# Run the Java tests.
test-java:
"./gradlew" --info test
# Test the examples.
test-examples:
@for example in $(shell find examples -name "*Example.java") ; do \
example=$${example#examples/}; \
example=$${example%Example.java}; \
echo "Testing $${example}"; \
make run-example EXAMPLE=$${example}; \
done
# Generate JavaDoc.
javadoc:
"./gradlew" javadoc
@echo "\n\n"'Open `build/docs/javadoc/index.html`.'
# Make a JAR-file.
package:
"./gradlew" --info jar
# Publish the package artifact to a public repository
publish:
"./gradlew" --info uploadToBintray
# Run a specific example, with `make run-example EXAMPLE=Simple` for instance.
run-example:
$(eval JAR := $(shell find ./build/libs/ -name "wasmer-jni-*.jar"))
@cd examples; \
javac -classpath "../${JAR}" ${EXAMPLE}Example.java; \
java -Djava.library.path=$(CURDIR)/artifacts/$(build_os)-$(build_arch) -classpath ".:../${JAR}" -enableassertions ${EXAMPLE}Example
# Clean
clean:
cargo clean
rm -rf build
rm -rf artifacts