diff --git a/Makefile b/Makefile index 36b1d959..df1ad60c 100644 --- a/Makefile +++ b/Makefile @@ -57,43 +57,29 @@ build-go: test: # Use package list mode to include all subdirectores. The -count=1 turns off caching. - RUST_BACKTRACE=1 go test -v -count=1 ./... -tags mocks - + RUST_BACKTRACE=1 go test -v -count=1 ./... test-safety: # Use package list mode to include all subdirectores. The -count=1 turns off caching. - GODEBUG=cgocheck=2 go test -race -v -count=1 ./... -tags mocks + GODEBUG=cgocheck=2 go test -race -v -count=1 ./... # 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/artifacts/libwasmvm_static.a api - cp libwasmvm/artifacts/libwasmvm_static.aarch64.a api + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-alpine + cp libwasmvm/artifacts/libwasmvm_muslc.a api + cp libwasmvm/artifacts/libwasmvm_muslc.aarch64.a api make update-bindings # 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 $(BUILDERS_PREFIX):alpine go build -tags static ./... + 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 $(BUILDERS_PREFIX):alpine go test -tags 'static mocks' -count=1 ./... - -# Creates a release build in a containerized build environment of the static library for glibc Linux (.a) -release-build-linux-static: - rm -rf libwasmvm/target/release - # build the glibc *.a file - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX):static - cp libwasmvm/artifacts/libwasmvm_static.a api - cp libwasmvm/artifacts/libwasmvm_static.aarch64.a api - make update-bindings - # 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):static go build -tags static ./... - # 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):static go test -tags='static mocks' -count=1 ./... + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go test -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags muslc -count=1 ./... # 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 + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-centos7 cp libwasmvm/artifacts/libwasmvm.x86_64.so api cp libwasmvm/artifacts/libwasmvm.aarch64.so api make update-bindings @@ -102,7 +88,7 @@ release-build-linux: release-build-macos: rm -rf libwasmvm/target/x86_64-apple-darwin/release rm -rf libwasmvm/target/aarch64-apple-darwin/release - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX):cross build_macos.sh + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos.sh cp libwasmvm/artifacts/libwasmvm.dylib api make update-bindings @@ -115,7 +101,6 @@ release-build: # Write like this because those must not run in parallel make release-build-alpine make release-build-linux - make release-build-linux-static make release-build-macos test-alpine: release-build-alpine @@ -134,11 +119,3 @@ test-alpine: release-build-alpine @# Run binary locally if you are on Linux @# ./demo ./api/testdata/hackatom.wasm - -test-static: release-build-linux-static - # build a go binary - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):static go build -tags='static mocks' -o static.exe ./cmd - # run static binary in an alpine machines (not dlls) - docker run --rm --read-only -v $(shell pwd):/code -w /code centos ./static.exe ./api/testdata/hackatom.wasm - # run static binary locally if you are on Linux - # ./static.exe ./api/testdata/hackatom.wasm diff --git a/README.md b/README.md index 723f4eab..2bf45c1e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,6 @@ This repository is forked from [CosmWasm/wasmvm](https://github.com/CosmWasm/was This is a wrapper around the [CosmWasm VM](https://github.com/line/cosmwasm/tree/main/packages/vm). It allows you to compile, initialize and execute CosmWasm smart contracts -from Go applications, in particular from [x/wasm](https://github.com/line/lfb-sdk/tree/main/x/wasm). +from Go applications, in particular from [x/wasm](https://github.com/line/lbm-sdk/tree/main/x/wasm). For more detail, see the [original document](https://github.com/CosmWasm/wasmvm#readme) diff --git a/api/callbacks.go b/api/callbacks.go index a9dfb86a..36c65c56 100644 --- a/api/callbacks.go +++ b/api/callbacks.go @@ -92,17 +92,17 @@ func recoverPanic(ret *C.GoError) { type Gas = uint64 -// GasMeter is a copy of an interface declaration from lfb-sdk -// Defined in https://github.com/line/lfb-sdk/blob/main/store/types/gas.go +// GasMeter is a copy of an interface declaration from lbm-sdk +// Defined in https://github.com/line/lbm-sdk/blob/main/store/types/gas.go type GasMeter interface { GasConsumed() Gas } /****** DB ********/ -// KVStore copies a subset of types from lfb-sdk +// KVStore copies a subset of types from lbm-sdk // We may wish to make this more generic sometime in the future, but not now -// Original KVStore is defined in https://github.com/line/lfb-sdk/blob/main/store/types/store.go +// Original KVStore is defined in https://github.com/line/lbm-sdk/blob/main/store/types/store.go type KVStore interface { Get(key []byte) []byte Set(key, value []byte) @@ -120,7 +120,7 @@ type KVStore interface { ReverseIterator(start, end []byte) Iterator } -// Iterator copies a subset of types from lfb-sdk +// Iterator copies a subset of types from lbm-sdk type Iterator interface { // Valid returns whether the current iterator is valid. Once invalid, the Iterator remains // invalid forever. diff --git a/api/link_glibclinux_aarch64.go b/api/link_glibclinux_aarch64.go index c5e81a44..4509441a 100644 --- a/api/link_glibclinux_aarch64.go +++ b/api/link_glibclinux_aarch64.go @@ -1,5 +1,5 @@ -//go:build linux && !static && arm64 -// +build linux,!static,arm64 +//go:build linux && !muslc && arm64 +// +build linux,!muslc,arm64 package api diff --git a/api/link_glibclinux_x86_64.go b/api/link_glibclinux_x86_64.go index 213daa2a..be822149 100644 --- a/api/link_glibclinux_x86_64.go +++ b/api/link_glibclinux_x86_64.go @@ -1,5 +1,5 @@ -//go:build linux && !static && amd64 -// +build linux,!static,amd64 +//go:build linux && !muslc && amd64 +// +build linux,!muslc,amd64 package api diff --git a/api/link_muslc.go b/api/link_muslc.go new file mode 100644 index 00000000..c12e14c4 --- /dev/null +++ b/api/link_muslc.go @@ -0,0 +1,7 @@ +//go:build linux && muslc +// +build linux,muslc + +package api + +// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm_muslc +import "C" diff --git a/api/link_static.go b/api/link_static.go deleted file mode 100644 index 08f3f718..00000000 --- a/api/link_static.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build linux && static -// +build linux,static - -package api - -// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm_static -lm -ldl -import "C" diff --git a/api/mocks.go b/api/mocks.go index 7378901a..1f432dcc 100644 --- a/api/mocks.go +++ b/api/mocks.go @@ -1,6 +1,3 @@ -//go:build mocks -// +build mocks - package api import ( @@ -179,7 +176,7 @@ func MockIBCPacketTimeout(myChannel string, data []byte) types.IBCPacketTimeoutM } /*** Mock GasMeter ****/ -// This code is borrowed from lfb-sdk store/types/gas.go +// This code is borrowed from lbm-sdk store/types/gas.go // ErrorOutOfGas defines an error thrown when an action results in out of gas. type ErrorOutOfGas struct { @@ -242,7 +239,7 @@ func (g *mockGasMeter) ConsumeGas(amount Gas, descriptor string) { } /*** Mock KVStore ****/ -// Much of this code is borrowed from lfb-sdk store/transient.go +// Much of this code is borrowed from lbm-sdk store/transient.go // Note: these gas prices are all in *wasmer gas* and (sdk gas * 100) // diff --git a/build_demo.sh b/build_demo.sh index 9892a265..6407875c 100755 --- a/build_demo.sh +++ b/build_demo.sh @@ -6,7 +6,7 @@ set -e # Note we are not using bash here but the Alpine default shell # See "2. If you really need CGO, but not netcgo" in https://dubo-dubon-duponey.medium.com/a-beginners-guide-to-cross-compiling-static-cgo-pie-binaries-golang-1-16-792eea92d5aa # See also https://github.com/rust-lang/rust/issues/78919 for why we need -Wl,-z,muldefs -go build -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags static \ +go build -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags muslc \ -o demo ./cmd/demo # Or static-pie if you really want to diff --git a/builders/Dockerfile.alpine b/builders/Dockerfile.alpine index d2b4de5c..26757287 100644 --- a/builders/Dockerfile.alpine +++ b/builders/Dockerfile.alpine @@ -1,5 +1,3 @@ -# > docker build -t line/wasmvm-builder:alpine -f Dockerfile.alpine . - # This image is used for two things (which is not ideal, but yeah): # 1. Build the static Rust library # 2. Execute Go tests that use and test this library @@ -54,4 +52,4 @@ RUN mkdir /.cargo RUN chmod +rx /.cargo COPY guest/cargo-config /.cargo/config -CMD ["/opt/build_linux_static.sh"] +CMD ["/opt/build_muslc.sh"] diff --git a/builders/Dockerfile.centos7 b/builders/Dockerfile.centos7 index 1c66e515..dd08c4d2 100644 --- a/builders/Dockerfile.centos7 +++ b/builders/Dockerfile.centos7 @@ -1,5 +1,3 @@ -# > docker build -t line/wasmvm-builder:centos7 -f Dockerfile.centos7 . - FROM centos:centos7 RUN yum -y update \ @@ -35,15 +33,6 @@ RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rust && cargo --version \ && rustc --version -RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \ - && chmod +x rustup-init \ - && ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.57.0 \ - && rm rustup-init \ - && chmod -R a+w $RUSTUP_HOME $CARGO_HOME \ - && rustup --version \ - && cargo --version \ - && rustc --version - # Add aarch64 as a target of compilation RUN rustup target add aarch64-unknown-linux-gnu diff --git a/builders/Dockerfile.cross b/builders/Dockerfile.cross index 5d5027b8..a9048c4d 100644 --- a/builders/Dockerfile.cross +++ b/builders/Dockerfile.cross @@ -1,5 +1,3 @@ -# > docker build -t line/wasmvm-builder:cross -f Dockerfile.cross . - FROM rust:1.57.0-bullseye # Install build dependencies diff --git a/builders/Dockerfile.static b/builders/Dockerfile.static deleted file mode 100644 index 7580008d..00000000 --- a/builders/Dockerfile.static +++ /dev/null @@ -1,36 +0,0 @@ -# > docker build -t line/wasmvm-builder:static -f Dockerfile.static . - -FROM golang:1.17 - -ENV RUSTUP_HOME=/usr/local/rustup \ - CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH - -WORKDIR /tmp -RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \ - && chmod +x rustup-init \ - && ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.57.0 \ - && rm rustup-init \ - && chmod -R a+w $RUSTUP_HOME $CARGO_HOME \ - && rustup --version \ - && cargo --version \ - && rustc --version - -# prepare go cache dirs -RUN mkdir -p /.cache/go-build -RUN chmod -R 777 /.cache - -# allow non-root user to download more deps later -RUN chmod -R 777 /usr/local/cargo - -## COPY BUILD SCRIPTS -WORKDIR /code - -COPY guest/*.sh /opt/ -RUN chmod +x /opt/*.sh - -RUN mkdir /.cargo -RUN chmod +rx /.cargo -COPY guest/cargo-config /.cargo/config - -CMD ["/opt/build_linux_static.sh"] diff --git a/builders/Makefile b/builders/Makefile index 5c2b5a04..74f3a024 100644 --- a/builders/Makefile +++ b/builders/Makefile @@ -2,27 +2,21 @@ BUILDERS_PREFIX := line/wasmvm-builder .PHONY: docker-image-centos7 docker-image-centos7: - docker build --pull . -t $(BUILDERS_PREFIX):centos7 -f ./Dockerfile.centos7 + docker build --pull . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7 .PHONY: docker-image-cross docker-image-cross: - docker build --pull . -t $(BUILDERS_PREFIX):cross -f ./Dockerfile.cross + docker build --pull . -t $(BUILDERS_PREFIX)-cross -f ./Dockerfile.cross .PHONY: docker-image-alpine docker-image-alpine: - docker build --pull . -t $(BUILDERS_PREFIX):alpine -f ./Dockerfile.alpine - -.PHONY: docker-image-static -docker-image-static: - docker build --pull . -t $(BUILDERS_PREFIX):static -f ./Dockerfile.static + docker build --pull . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine .PHONY: docker-images -docker-images: docker-image-centos7 docker-image-cross docker-image-alpine docker-image-static +docker-images: docker-image-centos7 docker-image-cross docker-image-alpine -# TODO publish images to registry # .PHONY: docker-publish # docker-publish: docker-images -# docker push $(BUILDERS_PREFIX):cross -# docker push $(BUILDERS_PREFIX):centos7 -# docker push $(BUILDERS_PREFIX):alpine -# docker push $(BUILDERS_PREFIX):static +# docker push $(BUILDERS_PREFIX)-cross +# docker push $(BUILDERS_PREFIX)-centos7 +# docker push $(BUILDERS_PREFIX)-alpine diff --git a/builders/guest/build_linux_static.sh b/builders/guest/build_muslc.sh similarity index 51% rename from builders/guest/build_linux_static.sh rename to builders/guest/build_muslc.sh index e108af6a..00098a59 100755 --- a/builders/guest/build_linux_static.sh +++ b/builders/guest/build_muslc.sh @@ -1,13 +1,16 @@ #!/bin/sh set -e # Note we are not using bash here but the Alpine default shell +# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to +# enable stripping through cargo (if that is desired). + echo "Starting aarch64-unknown-linux-musl build" export CC=/opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc -cargo build --release --target aarch64-unknown-linux-musl --example staticlib +cargo build --release --target aarch64-unknown-linux-musl --example muslc unset CC echo "Starting x86_64-unknown-linux-musl build" -cargo build --release --target x86_64-unknown-linux-musl --example staticlib +cargo build --release --target x86_64-unknown-linux-musl --example muslc -cp target/aarch64-unknown-linux-musl/release/examples/libstaticlib.a artifacts/libwasmvm_static.aarch64.a -cp target/x86_64-unknown-linux-musl/release/examples/libstaticlib.a artifacts/libwasmvm_static.a +cp target/aarch64-unknown-linux-musl/release/examples/libmuslc.a artifacts/libwasmvm_muslc.aarch64.a +cp target/x86_64-unknown-linux-musl/release/examples/libmuslc.a artifacts/libwasmvm_muslc.a diff --git a/ibc_test.go b/ibc_test.go index 90a468b2..5f9cbee3 100644 --- a/ibc_test.go +++ b/ibc_test.go @@ -1,6 +1,3 @@ -//go:build mocks -// +build mocks - package cosmwasm import ( diff --git a/lib_test.go b/lib_test.go index 10cd33db..983340f2 100644 --- a/lib_test.go +++ b/lib_test.go @@ -1,6 +1,3 @@ -//go:build mocks -// +build mocks - package cosmwasm import ( diff --git a/libwasmvm/Cargo.toml b/libwasmvm/Cargo.toml index 2ebc02e8..bcc26818 100644 --- a/libwasmvm/Cargo.toml +++ b/libwasmvm/Cargo.toml @@ -16,7 +16,7 @@ crate-type = ["cdylib"] # the example is to allow us to compile a static lib with the same codebase as we compile the # normal dynamic libs (best workaround I could find to override crate-type on the command line) [[example]] -name = "staticlib" +name = "muslc" path = "src/lib.rs" crate-type = ["staticlib"] diff --git a/types/ibc.go b/types/ibc.go index 68794344..31d6d338 100644 --- a/types/ibc.go +++ b/types/ibc.go @@ -149,8 +149,8 @@ type IBCPacketTimeoutMsg struct { } // TODO: test what the sdk Order.String() represents and how to parse back -// `Order` in Proto files: https://github.com/line/lfb-sdk/blob/main/proto/ibc/core/channel/v1/channel.proto -// `ORder` in Auto-gen code: https://github.com/line/lfb-sdk/blob/main/x/ibc/core/04-channel/types/channel.pb.go +// `Order` in Proto files: https://github.com/line/lbm-sdk/blob/main/proto/ibc/core/channel/v1/channel.proto +// `ORder` in Auto-gen code: https://github.com/line/lbm-sdk/blob/main/x/ibc/core/04-channel/types/channel.pb.go type IBCOrder = string // These are the only two valid values for IbcOrder diff --git a/types/msg.go b/types/msg.go index 5665364b..e2109755 100644 --- a/types/msg.go +++ b/types/msg.go @@ -112,7 +112,7 @@ type BankMsg struct { Burn *BurnMsg `json:"burn,omitempty"` } -// SendMsg contains instructions for a lfb-sdk/SendMsg +// SendMsg contains instructions for a lbm-sdk/SendMsg // It has a fixed interface here and should be converted into the proper SDK format before dispatching type SendMsg struct { ToAddress string `json:"to_address"` @@ -282,7 +282,7 @@ type ExecuteMsg struct { // InstantiateMsg will create a new contract instance from a previously uploaded CodeID. // This allows one contract to spawn "sub-contracts". type InstantiateMsg struct { - // CodeID is the reference to the wasm byte code as used by the lfb-sdk + // CodeID is the reference to the wasm byte code as used by the lbm-sdk CodeID uint64 `json:"code_id"` // Msg is assumed to be a json-encoded message, which will be passed directly // as `userMsg` when calling `Init` on a new contract with the above-defined CodeID