|
| 1 | +#!/bin/bash |
| 2 | +# Usage: ./build.sh [contract-name] |
| 3 | +# Purpose: Builds a CosmWasm smart contract using the cosmwasm/optimizer Docker image. |
| 4 | +# - Defaults to building the 'injective-cosmwasm-mock' contract if no argument is provided. |
| 5 | +# - Specify a contract name (e.g., 'atomic-order-example') to build a different contract. |
| 6 | +# - The contract must be a directory in 'contracts/' (e.g., 'contracts/[contract-name]'). |
| 7 | +# - Run from the workspace root (e.g., cw-injective) to ensure access to the workspace Cargo.toml. |
| 8 | +# Examples: |
| 9 | +# ./build.sh # Builds injective-cosmwasm-mock |
| 10 | +# ./build.sh atomic-order-example # Builds atomic-order-example |
| 11 | +# ./build.sh dummy # Builds dummy |
| 12 | +# ./build.sh injective-cosmwasm-stargate-example # Builds injective-cosmwasm-stargate-example |
| 13 | +# Output: Produces an optimized .wasm file in target/wasm32-unknown-unknown/release/ |
| 14 | + |
| 15 | +ARCH="" |
| 16 | + |
| 17 | +# Set architecture suffix for arm64 |
| 18 | +if [[ $(arch) = "arm64" ]]; then |
| 19 | + ARCH=-arm64 |
| 20 | +fi |
| 21 | + |
| 22 | +# Default contract name |
| 23 | +DEFAULT_CONTRACT="injective-cosmwasm-mock" |
| 24 | +CONTRACT=${1:-$DEFAULT_CONTRACT} |
| 25 | + |
| 26 | +# Validate that the contract directory exists |
| 27 | +if [[ ! -d "contracts/$CONTRACT" ]]; then |
| 28 | + echo "Error: Contract directory 'contracts/$CONTRACT' does not exist." |
| 29 | + echo "Available contracts:" |
| 30 | + ls -1 contracts/ |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Run the optimizer with the specified or default contract |
| 35 | +docker run --rm -v "$(pwd)":/code \ |
| 36 | + -v "$HOME/.cargo/git":/usr/local/cargo/git \ |
| 37 | + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ |
| 38 | + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ |
| 39 | + cosmwasm/optimizer${ARCH}:0.16.1 /code/contracts/$CONTRACT |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
0 commit comments