forked from CosmWasm/wasmvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
98 lines (82 loc) · 3.87 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
.PHONY: all build build-rust build-go test
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0007
USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
SHARED_LIB_EXT = "" # File extension of the shared library
ifeq ($(OS),Windows_NT)
SHARED_LIB_EXT = dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SHARED_LIB_EXT = so
endif
ifeq ($(UNAME_S),Darwin)
SHARED_LIB_EXT = dylib
endif
endif
all: build test
build: build-rust build-go
build-rust: build-rust-release
# 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
build-rust-debug:
(cd libwasmvm && cargo build)
cp libwasmvm/target/debug/libwasmvm.$(SHARED_LIB_EXT) api
make update-bindings
# use release build to actually ship - smaller and much faster
#
# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
# enable stripping through cargo (if that is desired).
build-rust-release:
(cd libwasmvm && cargo build --release)
cp libwasmvm/target/release/libwasmvm.$(SHARED_LIB_EXT) api
make update-bindings
@ #this pulls out ELF symbols, 80% size reduction!
build-go:
go build ./...
test:
RUST_BACKTRACE=1 go test -v ./api ./types .
test-safety:
GODEBUG=cgocheck=2 go test -race -v -count 1 ./api
# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
release-build-alpine:
rm -rf libwasmvm/target/release
# build the muslc *.a file
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-alpine
cp libwasmvm/target/release/examples/libmuslc.a api/libwasmvm_muslc.a
make update-bindings
# try running go tests using this lib with muslc
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/testing -w /testing $(BUILDERS_PREFIX)-alpine go build -tags muslc .
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/testing -w /testing $(BUILDERS_PREFIX)-alpine go test -tags muslc ./api ./types
# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-build-linux:
rm -rf libwasmvm/target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-centos7
cp libwasmvm/target/release/deps/libwasmvm.so api
make update-bindings
# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
release-build-macos:
rm -rf libwasmvm/target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross
cp libwasmvm/target/x86_64-apple-darwin/release/deps/libwasmvm.dylib api
cp libwasmvm/bindings.h 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 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
test-alpine: release-build-alpine
# build a go binary
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/testing -w /testing $(BUILDERS_PREFIX)-alpine go build -tags muslc -o demo ./cmd
# run static binary in an alpine machines (not dlls)
docker run --rm --read-only -v $(shell pwd):/testing -w /testing alpine:3.14 ./demo ./api/testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/testing -w /testing alpine:3.13 ./demo ./api/testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/testing -w /testing alpine:3.12 ./demo ./api/testdata/hackatom.wasm
docker run --rm --read-only -v $(shell pwd):/testing -w /testing alpine:3.11 ./demo ./api/testdata/hackatom.wasm
# run static binary locally if you are on Linux
# ./muslc.exe ./api/testdata/hackatom.wasm