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

Script to print sizes of all integration test contracts #1851

Merged
merged 5 commits into from
Jul 24, 2023
Merged
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
37 changes: 37 additions & 0 deletions scripts/contract_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

SCRIPT_NAME="${BASH_SOURCE[0]}"
MANIFEST_PATH=$1

function usage {
cat << EOF
Usage: ${SCRIPT_NAME} MANIFEST_PATH

Build and print the contract name and size for the given manifest path, if it is a valid ink! contract project.
Use with `find` (see EXAMPLES) to print the contract name and size for all ink! contracts in a directory.

MANIFEST_PATH
Path to the Cargo.toml manifest file for a contract project

EXAMPLES
${SCRIPT_NAME} ./Cargo.toml
find ./integration-tests/ -name "Cargo.toml" -exec ${SCRIPT_NAME} {} \;

EOF
}

if [ -z "$MANIFEST_PATH" ]; then
usage
exit 1
fi

BUILD_RESULT=$(cargo contract build --manifest-path "$MANIFEST_PATH" --release --quiet --output-json 2>/dev/null)

if [ $? -eq 0 ]; then
# only print the contract name and size if the build was successful
DEST_WASM=$(echo "$BUILD_RESULT" | jq -r .dest_wasm)
CONTRACT_NAME=$(basename "$DEST_WASM" .wasm)
CONTRACT_SIZE=$(stat -c %s "$DEST_WASM")

echo "$CONTRACT_NAME" "$CONTRACT_SIZE"
fi