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

Add WASM tests and CI job #29

Merged
merged 2 commits into from
Feb 28, 2024
Merged

Add WASM tests and CI job #29

merged 2 commits into from
Feb 28, 2024

Conversation

FreezyLemon
Copy link
Contributor

The way I understand it, there are 2 different "main" WASM configurations: wasm32-unknown-unknown which is the most basic WebAssembly configuration that is used by browsers, and wasm32-wasi, a newer extension to wasm32 which comes with a (small) standard library and some sort of component model.

These two targets have different limitations and very different tooling in Rust. I'll try to give an overview:

no wasm wasm32-unknown-unknown wasm32-wasi
criterion default no rayon1 no rayon
tests #[test] #[wasm_bindgen_test] #[test]
test cmd cargo test wasm-pack test 2
runtime native nodejs, browser wasmtime, wasmer etc.3
cfg target_arch != "wasm32" target_arch = "wasm32",
target_os = "unknown"
target_arch = "wasm32",
target_os = "wasi"4

That said, this PR implements a CI job and testing for wasm32-unknown-unknown in a way that should allow adding wasm32-wasi without breakage later.

  • Remove wasm feature (now detected automatically)
  • Split criterion dev-dependency into wasm and non-wasm
    • Disable default features on wasm
    • Disable html_reports feature in general (no benefit for CI, can be enabled locally if wanted)
  • Add wasm-bindgen dependencies only for wasm32-unknown-unknown. Including these on wasm32-wasi seems to cause problems
  • Add #[wasm_bindgen_test] attribute on all tests if wasm32-unknown-unknown is selected
  • Add CI job that runs wasm32 tests on chrome and firefox (these are preinstalled on Ubuntu runners)

Footnotes

  1. rayon doesn't work on wasm32, at least not out of the box. In criterion this means default-features = false

  2. Either cargo test --no-run & wasmtime <test binary> (or wasmer etc.) or cargo test with a test runner set in config.toml

  3. The goal of WASI is to be "run anywhere", but browsers don't support it yet. https://webassembly.sh/ is one option to run WASI in a browser.

  4. target_os = "wasi" is probably good enough, but for completeness, target_arch should be included too.

Copy link
Member

@Luni-4 Luni-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR! Your analysis is correct, that is the current scenario. This PR also fixes #21

Cargo.toml Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@FreezyLemon FreezyLemon requested a review from Luni-4 February 26, 2024 12:17
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.52%. Comparing base (6d417bd) to head (bc3ac7e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #29   +/-   ##
=======================================
  Coverage   66.52%   66.52%           
=======================================
  Files           4        4           
  Lines         923      923           
=======================================
  Hits          614      614           
  Misses        309      309           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FreezyLemon
Copy link
Contributor Author

FreezyLemon commented Feb 26, 2024

Since this is a core dependency of rav1e, I'd like to have some feedback from the rav1e folks on this. Not sure who to ask though. @lu-zero maybe?

@Luni-4 Luni-4 requested a review from lu-zero February 28, 2024 17:55
@@ -9,7 +9,6 @@ repository = "https://github.com/rust-av/v_frame"

[features]
serialize = ["serde", "aligned-vec/serde"]
wasm = ["wasm-bindgen"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to leave it as no-op to stay compatible with rav1e

Copy link
Contributor Author

@FreezyLemon FreezyLemon Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind, but we have some breaking changes in the next release anyways, and it might be a good time to remove this immediately?

If you prefer keeping a wasm feature, I'll do it no problem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's land as-is then.

Copy link
Member

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks fine beside that nit

@lu-zero lu-zero merged commit 31ef767 into rust-av:main Feb 28, 2024
6 checks passed
@FreezyLemon FreezyLemon deleted the add-wasm-ci branch February 29, 2024 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants