Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert linux_static #70

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 9 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 5 additions & 5 deletions api/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/link_glibclinux_aarch64.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && !static && arm64
// +build linux,!static,arm64
//go:build linux && !muslc && arm64
// +build linux,!muslc,arm64

package api

Expand Down
4 changes: 2 additions & 2 deletions api/link_glibclinux_x86_64.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && !static && amd64
// +build linux,!static,amd64
//go:build linux && !muslc && amd64
// +build linux,!muslc,amd64

package api

Expand Down
7 changes: 7 additions & 0 deletions api/link_muslc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build linux && muslc
// +build linux,muslc

package api

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm_muslc
import "C"
7 changes: 0 additions & 7 deletions api/link_static.go

This file was deleted.

7 changes: 2 additions & 5 deletions api/mocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build mocks
// +build mocks

package api

import (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
//
Expand Down
2 changes: 1 addition & 1 deletion build_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
11 changes: 0 additions & 11 deletions builders/Dockerfile.centos7
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# > docker build -t line/wasmvm-builder:centos7 -f Dockerfile.centos7 .

FROM centos:centos7

RUN yum -y update \
Expand Down Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions builders/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# > docker build -t line/wasmvm-builder:cross -f Dockerfile.cross .

FROM rust:1.57.0-bullseye

# Install build dependencies
Expand Down
36 changes: 0 additions & 36 deletions builders/Dockerfile.static

This file was deleted.

20 changes: 7 additions & 13 deletions builders/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions ibc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build mocks
// +build mocks

package cosmwasm

import (
Expand Down
3 changes: 0 additions & 3 deletions lib_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build mocks
// +build mocks

package cosmwasm

import (
Expand Down
2 changes: 1 addition & 1 deletion libwasmvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions types/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down