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

Static lib #49

Closed
wants to merge 4 commits into from
Closed
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
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
exclude = [".circleci/*", ".gitignore"]

[lib]
crate-type = ["cdylib"]
crate-type = ["dylib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[badges]
Expand Down
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all build build-rust build-go test docker-image docker-build docker-image-centos7

DOCKER_TAG := 0.6.3
DOCKER_TAG := 0.7.0
USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)

Expand Down Expand Up @@ -32,13 +32,19 @@ build-rust-debug:

# use release build to actually ship - smaller and much faster
build-rust-release:
cargo build --release --features backtraces
RUSTFLAGS="-C target-feature=-crt-static -C link-args=-fPIC" cargo build --release --target x86_64-unknown-linux-musl
cp target/release/libgo_cosmwasm.$(DLL_EXT) api
@ #this pulls out ELF symbols, 80% size reduction!

install-release-tools:
sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
rustup target add x86_64-unknown-linux-musl --toolchain=nightly


# implement stripping based on os
ifeq ($(DLL_EXT),so)
strip:
@ #this pulls out ELF symbols, 80% size reduction!
strip api/libgo_cosmwasm.so
else
# TODO: add for windows and osx
Expand All @@ -49,7 +55,8 @@ build-go:
go build ./...

test:
RUST_BACKTRACE=1 go test -v ./api .
# note: you must modify api/lib.go somehow after rebuilding the rust dll to relink it
RUST_BACKTRACE=1 go test -v -count=1 ./api .

docker-image-centos7:
docker build . -t go-cosmwasm:$(DOCKER_TAG)-centos7 -f ./Dockerfile.centos7
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ with a PR (on your fork). We will set up a proper CI system for building these b
but we are not there yet.

To build the rust side, try `make build-rust` and wait for it to compile. This depends on
`cargo` being installed with `rustc` version 1.37+. Generally, you can just use `rustup` to
install all this with no problems.
`cargo` being installed with `rustc` version 1.39+. Generally, you can just use `rustup` to
install all this with no problems. You will also need to run `make install-release-tools`
once to ensure you have the needed libraries to compile (for Ubuntu/Debian build, not needed for OSX).
1 change: 1 addition & 0 deletions api/lib.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api


// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lgo_cosmwasm
// #include <stdlib.h>
// #include "bindings.h"
Expand Down