Skip to content

Commit

Permalink
Merge pull request #15 from initia-labs/feat/split-compiler
Browse files Browse the repository at this point in the history
feat: split compiler
  • Loading branch information
beer-1 authored Mar 20, 2024
2 parents 6282efa + dafc5f8 commit a4ca60f
Show file tree
Hide file tree
Showing 51 changed files with 2,068 additions and 1,167 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- "crates/**"
- '!crates/e2e-move-tests/**'
- "libmovevm/**"
- "libcompiler/**"
- "Cargo.toml"

concurrency:
Expand Down Expand Up @@ -69,6 +70,6 @@ jobs:
- name: Commit shared libraries
uses: EndBug/add-and-commit@v9
with:
add: '["api/libmovevm.dylib", "api/libmovevm.aarch64.so", "api/libmovevm.x86_64.so"]'
add: '["api/libmovevm.dylib", "api/libmovevm.aarch64.so", "api/libmovevm.x86_64.so", "api/libcompiler.dylib", "api/libcompiler.aarch64.so", "api/libcompiler.x86_64.so"]'
default_author: github_actions
message: "update shared libraries"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ lib*.a
# Move build result
**/build
!types/compiler/build

# Generated by Builders
**/artifacts/
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"

members = [
"libcompiler",
"libmovevm",
"crates/compiler",
"crates/gas",
Expand All @@ -13,7 +14,6 @@ members = [
"tools/generate-bcs-go",
"tools/precompile",
]
exclude = []

[profile.release]
opt-level = 3
Expand All @@ -25,7 +25,6 @@ codegen-units = 16
panic = 'unwind'
incremental = true
overflow-checks = true
strip = "debuginfo"

[profile.bench]
debug = true
Expand All @@ -45,6 +44,7 @@ codegen-units = 16
version = "0.1.0"
edition = "2021"
license = "BUSL-1.1"
license-file = "LICENSE"
homepage = "https://initia.xyz"
repository = "https://github.com/initia-labs/movevm"
rust-version = "1.76.0"
Expand Down
41 changes: 32 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ 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
COMPILER_SHARED_LIB_SRC = ""
COMPILER_SHARED_LIB_DST = ""
ifeq ($(OS),Windows_NT)
SHARED_LIB_SRC = movevm.dll
SHARED_LIB_DST = movevm.dll
COMPILER_SHARED_LIB_SRC = compiler.dll
COMPILER_SHARED_LIB_DST = compiler.dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SHARED_LIB_SRC = libmovevm.so
SHARED_LIB_DST = libmovevm.$(shell rustc --print cfg | grep target_arch | cut -d '"' -f 2).so
COMPILER_SHARED_LIB_SRC = libcompiler.so
COMPILER_SHARED_LIB_DST = libcompiler.$(shell rustc --print cfg | grep target_arch | cut -d '"' -f 2).so
endif
ifeq ($(UNAME_S),Darwin)
SHARED_LIB_SRC = libmovevm.dylib
SHARED_LIB_DST = libmovevm.dylib
COMPILER_SHARED_LIB_SRC = libcompiler.dylib
COMPILER_SHARED_LIB_DST = libcompiler.dylib
endif
endif

Expand All @@ -31,6 +39,8 @@ all: test-filenames build test
test-filenames:
echo $(SHARED_LIB_DST)
echo $(SHARED_LIB_SRC)
echo $(COMPILER_SHARED_LIB_DST)
echo $(COMPILER_SHARED_LIB_SRC)

test: precompile test-rust test-go

Expand Down Expand Up @@ -69,16 +79,18 @@ fmt:
cargo fmt

update-bindings:
# After we build libmovevm, 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 libmovevm/bindings.h api

cp libcompiler/bindings_compiler.h api

# 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:
cargo build -p movevm
cargo build -p compiler

cp -fp target/debug/$(SHARED_LIB_SRC) api/$(SHARED_LIB_DST)
cp -fp target/debug/$(COMPILER_SHARED_LIB_SRC) api/$(COMPILER_SHARED_LIB_DST)

make update-bindings

# use release build to actually ship - smaller and much faster
Expand All @@ -87,16 +99,22 @@ build-rust-debug:
# enable stripping through cargo (if that is desired).
build-rust-release:
cargo build -p movevm --release
cargo build -p compiler --release
rm -f api/$(SHARED_LIB_DST)
rm -f api/$(COMPILER_SHARED_LIB_DST)
cp -fp target/release/$(SHARED_LIB_SRC) api/$(SHARED_LIB_DST)
cp -fp target/release/$(COMPILER_SHARED_LIB_SRC) api/$(COMPILER_SHARED_LIB_DST)
make update-bindings
@ #this pulls out ELF symbols, 80% size reduction!

clean:
cargo clean
@-rm api/bindings.h
@-rm api/libmovevm.dylib
@-rm api/bindings_compiler.h
@-rm libmovevm/bindings.h
@-rm libcompiler/bindings_compiler.h
@-rm api/$(SHARED_LIB_DST)
@-rm api/$(COMPILER_SHARED_LIB_DST)
@echo cleaned.

# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
Expand All @@ -106,8 +124,10 @@ release-build-alpine:
docker run --rm -u $(USER_ID):$(USER_GROUP) \
-v $(shell pwd):/code/ \
$(BUILDERS_PREFIX)-alpine
cp libmovevm/artifacts/libmovevm_muslc.x86_64.a api
cp libmovevm/artifacts/libmovevm_muslc.aarch64.a api
cp artifacts/libmovevm_muslc.x86_64.a api
cp artifacts/libmovevm_muslc.aarch64.a api
cp artifacts/libcompiler_muslc.x86_64.a api
cp artifacts/libcompiler_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 $(ALPINE_TESTER) go build -tags muslc ./...
Expand All @@ -120,8 +140,10 @@ release-build-linux:
docker run --rm -u $(USER_ID):$(USER_GROUP) \
-v $(shell pwd):/code/ \
$(BUILDERS_PREFIX)-centos7
cp libmovevm/artifacts/libmovevm.x86_64.so api
cp libmovevm/artifacts/libmovevm.aarch64.so api
cp artifacts/libmovevm.x86_64.so api
cp artifacts/libmovevm.aarch64.so api
cp artifacts/libcompiler.x86_64.so api
cp artifacts/libcompiler.aarch64.so api
make update-bindings

# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
Expand All @@ -131,7 +153,8 @@ release-build-macos:
docker run --rm -u $(USER_ID):$(USER_GROUP) \
-v $(shell pwd):/code/ \
$(BUILDERS_PREFIX)-cross build_macos.sh
cp libmovevm/artifacts/libmovevm.dylib api
cp artifacts/libmovevm.dylib api
cp artifacts/libcompiler.dylib api
make update-bindings

release-build:
Expand Down
Loading

0 comments on commit a4ca60f

Please sign in to comment.