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

Test 2 #5

Open
wants to merge 10 commits into
base: master
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
49 changes: 13 additions & 36 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ jobs:
- name: Run tests in WASM
run: tools/rust-test wasm

upload-binary-sizes:
check-binary-sizes:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand All @@ -109,67 +108,45 @@ jobs:
- name: Install toolchain
run: |
rustup target add armv7-linux-androideabi

- name: Build binaries
run: |
cargo build --target armv7-linux-androideabi --release
working-directory: rust-test

- name: Generate release report
run: |
./tools/release-size measure-rust > release-report.json

- name: Upload release report
uses: actions/upload-artifact@v2
with:
name: release_report
name: release_report_1
path: release-report.json

check-binary-sizes:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
# TODO remove this step
- name: Install toolchain
run: |
rustup target add armv7-linux-androideabi
- name: Build binaries
run: |
cargo build --target armv7-linux-androideabi --release
working-directory: rust-test
- name: Generate release report
run: |
./tools/release-size measure-rust > release-report.json

# Download previous release report, compare the release binary sizes and post/update a comment in the Pull Request.
- name: Download previous release report
id: download_prev_report
if: github.event_name == 'pull_request'
uses: dawidd6/action-download-artifact@v3
with:
commit: ${{github.event.pull_request.base.sha}}
path: previous
if_no_artifact_found: warn
# Same artifact name as at the "Upload release report" step.
name: release_report
name: release_report_1

- name: Craft Comment Body
if: steps.download_prev_artifact.outputs.found_artifact == 'true'
id: craft_body
if: github.event_name == 'pull_request'
run: |
before_report=./previous/release-report.json
after_report=./release-report.json
markdown_diff=$(./tools/release-size compare $before_report $after_report)
echo "markdown_body=$markdown_diff" >> $GITHUB_OUTPUT
# Please note `previous/release-report.json` may not exist if the previous report was not found.
./tools/release-size compare previous/release-report.json release-report.json |
> report-diff.md

- name: Create or Update Comment
uses: edumserrano/find-create-or-update-comment@v2
if: steps.download_prev_artifact.outputs.found_artifact == 'true'
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: "Binary size comparison"
comment-author: 'github-actions[bot]'
edit-mode: replace
body: |
## Binary size comparison

${{ steps.craft_body.outputs.markdown_body }}
body-path: 'report-diff.md'
23 changes: 23 additions & 0 deletions rust-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ crate-type = ["staticlib", "rlib"] # Creates static lib
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rlp = "0.5.2"
2 changes: 2 additions & 0 deletions rust-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use serde::Serialize;
use rlp::RlpStream;

#[derive(Serialize)]
struct Foo {
foo: usize,
}

pub fn add(left: usize, right: usize) {
let _ = RlpStream::default();
println!("{}", serde_json::to_string(&Foo {foo: left + right}).unwrap());
}
45 changes: 31 additions & 14 deletions tools/release-size
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,50 @@ RUST_TARGETS = [
LIB_NAME = "libwallet_core_rs.a"


def display_size(size_kb: int) -> str:
if size_kb >= 10000:
size_mb = float(size_kb) / 1024
return f'{size_mb:+.2f} MB'
else:
return f'{size_kb} KB'


def measure_rust(_args):
result = {}

for target in RUST_TARGETS:
# TODO 'rust-test' to 'rust'
path = f'rust-test/target/{target}/release/{LIB_NAME}'
file_stats = os.stat(path)
file_size_mb = file_stats.st_size / 1024 / 1024
result[target] = round(file_size_mb, 2)
file_size_kb = file_stats.st_size / 1024
result[target] = int(file_size_kb)

print(json.dumps(result))


def compare_sizes(args):
print('```diff')
def display_target(target: str, before_kb: int, current_kb: int):
diff_kb = current_kb - before_kb
print(f'➡️ **{target}**')
print("```diff")
if before_kb == current_kb:
print(f' Size {display_size(before_kb)}')
else:
print(f'- Size {display_size(before_kb)}')
print(f'+ Size {display_size(current_kb)} \t {display_size(diff_kb)}')
print("```")

before_json = json.load(open(args.before, 'r'))
after_json = json.load(open(args.after, 'r'))
for target, after_value in after_json.items():
before_value = before_json[target]
diff = after_value - before_value
current_json = json.load(open(args.current, 'r'))
before_json = {}
if os.path.isfile(args.before):
before_json = json.load(open(args.before, 'r'))

print(f'**{target}**')
print(f'- Size {before_value}')
print(f'+ Size {after_value} \t {diff:+.2f}')
print("## Binary size comparison")
print()
for target, current_kb in current_json.items():
before_kb = before_json.get(target, 0)
display_target(target, before_kb, current_kb)
print()
print("```")


if __name__ == '__main__':
Expand All @@ -50,9 +67,9 @@ if __name__ == '__main__':
measure_parser.set_defaults(func=measure_rust)

compare_parser = subparsers.add_parser('compare',
help="Compares binary sizes. Takes 'before' and 'after' file names")
help="Compares binary sizes. Takes 'before' and 'current' file names")
compare_parser.add_argument('before')
compare_parser.add_argument('after')
compare_parser.add_argument('current')
compare_parser.set_defaults(func=compare_sizes)

args = parser.parse_args()
Expand Down
Loading