From ea2fa19d5202cc0ba4f054b47979c05b1ec2b656 Mon Sep 17 00:00:00 2001 From: dongcool <95206510+dongcool@users.noreply.github.com> Date: Thu, 23 Mar 2023 10:30:09 +0800 Subject: [PATCH 1/4] update rust version --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7946639b..29ad6f4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,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 @@ -48,7 +48,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 From 25c9b3d6ebf6d67a5ac692fb0a044dd172cc38dc Mon Sep 17 00:00:00 2001 From: dongcool <95206510+dongcool@users.noreply.github.com> Date: Thu, 23 Mar 2023 10:38:24 +0800 Subject: [PATCH 2/4] update --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29ad6f4b..f862343e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,7 @@ on: - 'contracts/**' - 'tests/**' - 'Cargo.*' + - '.github/**' env: CARGO_TERM_COLOR: always From 204152ab69a061c7a3bfd67b91392902a8826c2a Mon Sep 17 00:00:00 2001 From: dongcool <95206510+dongcool@users.noreply.github.com> Date: Thu, 23 Mar 2023 11:41:59 +0800 Subject: [PATCH 3/4] dockerfile --- Dockerfile | 18 ++++++++++++++++++ README.md | 2 ++ makefile | 28 ++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a22e89d1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +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 + +ADD contracts/linear/Cargo.toml . +ADD Cargo.lock . + +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* diff --git a/README.md b/README.md index 7bac312b..dd7c99d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/makefile b/makefile index 57ea841d..6fc4ddf6 100644 --- a/makefile +++ b/makefile @@ -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 @@ -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 From 46a57da2068c46a4597bc4244561a53698e5367e Mon Sep 17 00:00:00 2001 From: dongcool <95206510+dongcool@users.noreply.github.com> Date: Thu, 23 Mar 2023 11:46:21 +0800 Subject: [PATCH 4/4] comments --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index a22e89d1..4c6f78e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,11 @@ 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 && \