forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c38335a
commit ecca4cc
Showing
5 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |