-
Notifications
You must be signed in to change notification settings - Fork 106
/
Makefile
160 lines (134 loc) · 6.38 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
# Builds the Rust library libwasmvm
BUILDERS_PREFIX := cosmwasm/libwasmvm-builder:0102
# Contains a full Go dev environment including CGO support in order to run Go tests on the built shared library
# This image is currently not published.
ALPINE_TESTER := cosmwasm/alpine-tester:local
USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
SHARED_LIB_SRC = "" # File name of the shared library as created by the Rust build system
SHARED_LIB_DST = "" # File name of the shared library that we store
ifeq ($(OS),Windows_NT)
SHARED_LIB_SRC = wasmvm.dll
SHARED_LIB_DST = wasmvm.dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SHARED_LIB_SRC = libwasmvm.so
SHARED_LIB_DST = libwasmvm.$(shell rustc --print cfg | grep target_arch | cut -d '"' -f 2).so
endif
ifeq ($(UNAME_S),Darwin)
SHARED_LIB_SRC = libwasmvm.dylib
SHARED_LIB_DST = libwasmvm.dylib
endif
endif
test-filenames:
echo $(SHARED_LIB_DST)
echo $(SHARED_LIB_SRC)
.PHONY: build
build:
make build-libwasmvm
make build-go
# Use debug build for quick testing.
# In order to use "--features backtraces" here we need a Rust nightly toolchain, which we don't have by default
.PHONY: build-libwasmvm-debug
build-libwasmvm-debug:
(cd libwasmvm && cargo build)
cp libwasmvm/target/debug/$(SHARED_LIB_SRC) internal/api/$(SHARED_LIB_DST)
make update-bindings
# use release build to actually ship - smaller and much faster
.PHONY: build-libwasmvm
build-libwasmvm:
(cd libwasmvm && cargo build --release)
cp libwasmvm/target/release/$(SHARED_LIB_SRC) internal/api/$(SHARED_LIB_DST)
make update-bindings
# build and show the Rust documentation of the wasmvm
.PHONY: doc-rust
doc-rust:
(cd libwasmvm && cargo doc --no-deps --open)
.PHONY: build-go
build-go:
go build ./...
go build -o build/demo ./cmd/demo
.PHONY: test
test:
# Use package list mode to include all subdirectores. The -count=1 turns off caching.
RUST_BACKTRACE=1 go test -v -count=1 ./...
.PHONY: test-safety
test-safety:
# Use package list mode to include all subdirectores. The -count=1 turns off caching.
GOEXPERIMENT=cgocheck2 go test -race -v -count=1 ./...
# Run all Go benchmarks
.PHONY: bench
bench:
go test -bench . -benchtime=2s -run=^Benchmark ./...
# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
release-build-alpine:
# build the muslc *.a file
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-alpine
cp libwasmvm/artifacts/libwasmvm_muslc.x86_64.a internal/api
cp libwasmvm/artifacts/libwasmvm_muslc.aarch64.a internal/api
make update-bindings
# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-build-linux:
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-debian build_gnu_x86_64.sh
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-debian build_gnu_aarch64.sh
cp libwasmvm/artifacts/libwasmvm.x86_64.so internal/api
cp libwasmvm/artifacts/libwasmvm.aarch64.so internal/api
make update-bindings
# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
release-build-macos:
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos.sh
cp libwasmvm/artifacts/libwasmvm.dylib internal/api
make update-bindings
# Creates a release build in a containerized build environment of the static library for macOS (.a)
release-build-macos-static:
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos_static.sh
cp libwasmvm/artifacts/libwasmvmstatic_darwin.a internal/api/libwasmvmstatic_darwin.a
make update-bindings
# Creates a release build in a containerized build environment of the shared library for Windows (.dll)
release-build-windows:
docker run --rm -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_windows.sh
cp libwasmvm/artifacts/wasmvm.dll internal/api
make update-bindings
update-bindings:
# After we build libwasmvm, we have to copy the generated bindings for Go code to use.
# We cannot use symlinks as those are not reliably resolved by `go get` (https://github.com/CosmWasm/wasmvm/pull/235).
cp libwasmvm/bindings.h internal/api
release-build:
# Write like this because those must not run in parallel
make release-build-alpine
make release-build-linux
make release-build-macos
make release-build-windows
.PHONY: create-tester-image
create-tester-image:
docker build -t $(ALPINE_TESTER) - < ./Dockerfile.alpine_tester
test-alpine: release-build-alpine create-tester-image
# try running go tests using this lib with muslc
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go build -tags muslc ./...
# Use package list mode to include all subdirectores. The -count=1 turns off caching.
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go test -tags muslc -count=1 ./...
@# Build a Go demo binary called ./demo that links the static library from the previous step.
@# Whether the result is a statically linked or dynamically linked binary is decided by `go build`
@# and it's a bit unclear how this is decided. We use `file` to see what we got.
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) ./build_demo.sh
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) file ./demo
@# Run the demo binary on Alpine machines
@# See https://de.wikipedia.org/wiki/Alpine_Linux#Versionen for supported versions
docker run --rm --read-only -v $(shell pwd):/mnt/testrun -w /mnt/testrun alpine:3.18 ./demo ./testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/mnt/testrun -w /mnt/testrun alpine:3.17 ./demo ./testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/mnt/testrun -w /mnt/testrun alpine:3.16 ./demo ./testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/mnt/testrun -w /mnt/testrun alpine:3.15 ./demo ./testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/mnt/testrun -w /mnt/testrun alpine:3.14 ./demo ./testdata/hackatom.wasm
@# Run binary locally if you are on Linux
@# ./demo ./testdata/hackatom.wasm
.PHONY: format
format:
find . -name '*.go' -type f | xargs gofumpt -w -s
find . -name '*.go' -type f | xargs misspell -w
.PHONY: lint
lint:
golangci-lint run
.PHONY: lint-fix
lint-fix:
golangci-lint run --fix