Skip to content

Commit

Permalink
[Misc]: Push test 16
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Mar 6, 2024
1 parent c38335a commit ecca4cc
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Build binaries
run: |
cargo build --target aarch64-apple-ios --release
working-directory: codegen-v2
working-directory: rust-test
- name: Generate release report
run: |
./tools/release-size measure-rust > release-report.json
Expand All @@ -128,8 +128,8 @@ jobs:
toolchain: stable
- name: Build binaries
run: |
cargo build --target aarch64-apple-ios --release
working-directory: codegen-v2
cargo build --target armv7-linux-androideabi --release
working-directory: rust-test
- name: Generate release report
run: |
./tools/release-size measure-rust > release-report.json
Expand Down
89 changes: 89 additions & 0 deletions rust-test/Cargo.lock

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

10 changes: 10 additions & 0 deletions rust-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "rust-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
10 changes: 10 additions & 0 deletions rust-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::Serialize;

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

pub fn add(left: usize, right: usize) {
println!("{}", serde_json::to_string(&Foo {foo: left + right}).unwrap());
}
59 changes: 59 additions & 0 deletions tools/release-size
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3

import argparse
import json
import os

RUST_TARGETS = [
# "aarch64-apple-ios",
# "aarch64-linux-android",
"armv7-linux-androideabi",
# "wasm32-unknown-emscripten",
]
LIB_NAME = "libwallet_core_rs.a"


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)

print(json.dumps(result))


def compare_sizes(args):
print('```diff')

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

print(f'**{target}**')
print(f'- Size {before_value}')
print(f'+ Size {after_value} \t {diff:+.2f}')
print()
print("```")


if __name__ == '__main__':
parser = argparse.ArgumentParser(description="GitHub CI helper functions")
subparsers = parser.add_subparsers()

measure_parser = subparsers.add_parser('measure-rust', help="Measures Rust release binaries'")
measure_parser.set_defaults(func=measure_rust)

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

args = parser.parse_args()
args.func(args)

0 comments on commit ecca4cc

Please sign in to comment.