-
Notifications
You must be signed in to change notification settings - Fork 256
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
feat: add compiled code size tests #412
Conversation
@@ -24,5 +24,7 @@ jobs: | |||
- uses: Swatinem/rust-cache@v1 | |||
- name: Test Format | |||
run: cargo fmt -- --check | |||
- name: Add wasm32 target | |||
run: rustup target add wasm32-unknown-unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, this should not be necessary? actions-rs/toolchain@v1
already installs this target, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's what I assumed, but there might be something internal which installs it for a different toolchain, not sure. Just added that as a workaround and was going to look into it today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obesrvation: this yml sets a horribly outdated toolchain at the start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this CI is something I would like to improve/rewrite in the future, as it only checks formatting and runs tests, to give some context into why I thought just to add a workaround for now. I can create an issue for this now, because I think it's a standard to at least check clippy as well.
fn check_example_size(example: &str) -> usize { | ||
let status = std::process::Command::new("cargo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add Command::new("rustup").args(&["target", "add", "wasm32-unknown-unknown"]).status().unwrap()
here, so that the test just works in more cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, that seems like a bad implication to update a user's toolchain unknowingly through running a test, maybe if this test was ignored by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems so, but I don't think that's the case. Like, when you run cargo test
, cargo automatically updates the index and downloads crates, and that doesn't cause problems. Similarly, if you run cargo test
in a project with rustup-toolchain
, rustup automatically downloads the toolchain without asking for confirmation.
Really, cargo build --target xxx
should just work. The reason it doesn't is a sad historical incident -- target management was implemented in rustup, while it really belongs to cargo. So this pattern is a work-around for a bug in the toolchain.
Empirically, I've been using rustup commands in CI in various projects (example from rust-analyzer: https://github.com/rust-analyzer/rust-analyzer/blob/master/xtask/src/main.rs#L80-L89), and it never caused problems.
But maybe I am biased -- I am pretty found of various toolchain hacks which streamline workflows :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's a fair point. I'll make this change
b9b4c8e
to
a5b9778
Compare
reverted the change @matklad as there were interactions through rustup which don't play well in the test, locally and on CI. Let me know if you have a strong opinion on this and I can push the commit again and try to find a way around |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have strong opinion! I think it wold be useful, but not critical, to understand what those bad interactions are, but, even if we do that, it should be done separately from this PR.
for posterity, the logs locally were:
and CI run: https://github.com/near/near-sdk-rs/actions/runs/832347131 |
Aha, that's because |
That's a good point, I assumed the overlap wouldn't be an issue because once installed the next call would be just a check. I'll explore in a future PR |
hey, looks my issue from a while ago about this is seeing some recent progress: rust-lang/rustup#988 |
cc @matklad as he suggested adding these before making other changes/refactoring.
The tests compile to wasm using release and any other usual flags and check the output wasm binary size.
The test checks to make sure it's no larger than 10% of what it currently is, to accommodate for external/platform discrepancies. Still feels a bit janky to me to test like this personally, but seems like it might be a reasonable check to have.