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

chore: update rust and use Docker to build #163

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'contracts/**'
- 'tests/**'
- 'Cargo.*'
- '.github/**'

env:
CARGO_TERM_COLOR: always
Expand All @@ -23,7 +24,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1 # stable
toolchain: 1.68.0 # stable
override: true
- uses: Swatinem/rust-cache@v1
# Set up Node environment
Expand All @@ -48,7 +49,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1 # stable
toolchain: 1.68.0 # stable
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v1
# Run lint
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM rust:1.68.0
LABEL description="Container for builds"

ENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
ENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

RUN apt-get update && apt-get install -y git less vim clang

RUN rustup default 1.68.0
RUN rustup target add wasm32-unknown-unknown

# Cargo files are needed to install and cache dependencies
ADD contracts/linear/Cargo.toml .
ADD Cargo.lock .

# a trick to run cargo build
RUN mkdir -p src && echo "fn main() {}" > src/lib.rs && \
RUSTFLAGS="-C link-arg=-s" cargo build -p linear --target wasm32-unknown-unknown --release && \
rm Cargo.toml && \
rm -rf ./src/ target/release/deps/my-project* target/release/my-project*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ In order to use it, run `npm i` first.
- `git push origin release/v1.0.x`
- Create a PR from the release branch
- Once the PR is merged, publish a new release on GitHub
- Build release artifacts to deploy:
- `make release`


## Manage
Expand Down
28 changes: 26 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ RFLAGS="-C link-arg=-s"

all: linear

linear: contracts/linear
release:
$(call docker_build)
mkdir -p res
cp target/wasm32-unknown-unknown/release/linear.wasm ./res/linear.wasm

linear: contracts/linear check-rustc-version
rustup target add wasm32-unknown-unknown
RUSTFLAGS=$(RFLAGS) cargo build -p linear --target wasm32-unknown-unknown --release
mkdir -p res
cp target/wasm32-unknown-unknown/release/linear.wasm ./res/linear.wasm

linear_test: contracts/linear
linear_test: contracts/linear check-rustc-version
rustup target add wasm32-unknown-unknown
RUSTFLAGS=$(RFLAGS) cargo build -p linear --target wasm32-unknown-unknown --features "test"
mkdir -p res
Expand Down Expand Up @@ -77,3 +82,22 @@ test-mock-fungible-token: mock-fungible-token
@mkdir -p ./tests/compiled-contracts/
cp ./res/mock_fungible_token.wasm ./tests/compiled-contracts/mock_fungible_token.wasm
cd tests && npx near-workspaces-ava __tests__/mock-fungible-token/**.ts --verbose

check-rustc-version:
@RUSTC_VERSION=$$(rustc --version | awk '{print $$2}'); \
if [ "$$RUSTC_VERSION" != "1.68.0" ]; then \
echo "Error: Rustc version is $$RUSTC_VERSION but 1.68.0 is required." && exit 1; \
else \
echo "Rustc version $$RUSTC_VERSION is installed."; \
fi

define docker_build
docker build -t near-builder:1.68.0 .
docker run \
--mount type=bind,source=${PWD},target=/host \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
-w /host \
-e RUSTFLAGS=$(RFLAGS) \
-i -t near-builder:1.68.0 \
make
endef