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

feat(js): compile rattler_solve and rattler_repodata_gateway #1108

Merged
merged 25 commits into from
Feb 28, 2025

Conversation

baszalmstra
Copy link
Collaborator

This PR adds the ability to use both rattler_solve and rattler_repodata_gateway.

WASM does not support filesystem access without extensions like emscripten or wasi, neither are supported by our build. But rattler aggressively caches data to disk so this PR adds additional code paths to not cache anything (except for maybe in memory). This allows compiling rattler_repodata_gateway to WASM.

Its also not possible to spawn futures or run blocking code on a different thread. Concurrency is supported, and its also used. But spawning is not supported because there is no tokio runtime active. I worked around this by conditionally running blocking code on the current thread.

I did not yet expose these crates to the javascript API yet, that should be done in a separate PR. I did add a proof of concept that fetches repodata and performs a solve from javascript. This also supports sharded repodata!

Running a solve for python, matplotlib, numpy for emscripten-wasm32 in the browser takes 0.2 seconds (without any cache) and results in this nice view in the chrome network debugger:

image

(Uses https://prefix.dev/emscripten-forge-dev and https://prefix.dev/conda-forge)

@@ -1,8 +1,12 @@
#[cfg(not(target_arch = "wasm32"))]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rattler_cache is basically a library to cache stuff to disk. Most of the functionality is gated to not be available on wasm32.

.url(url.clone())
.body(body.to_string())
.unwrap(),
)
}

#[cfg(target_arch = "wasm32")]
pub(crate) fn create_404_response(_url: &Url, _body: &str) -> Response {
todo!("This is not implemented in reqwest, we need to contribute that.")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an issue, that might come up when we add support for middleware.

//
// Let's start by fetching the records. If an error occurs we immediately return the error.
// This will drop the sender and all other waiting tasks will receive an error.
let records = match tokio::spawn({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed the spawn here because I dont think its needed. All implementations fan out to spawn blocking when blocking operations are performed.

// self-referential field which indexes the data in the memory map with a
// sparsely parsed json struct. See [`LazyRepoData`].
#[cfg(any(unix, windows))]
self_cell::self_cell!(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced ouroborous with self_cell because I couldnt get to conditionally compile ouroboros. self_cell should also compile faster anyway.

# We want to use version 0.4.19 but its not released yet.
# https://github.com/Nullus157/async-compression/pull/319
async-compression = { git = "https://github.com/Nullus157/async-compression.git" }
bzip2 = { git = "https://github.com/baszalmstra/bzip2-rs.git", branch = "fix/wasm" }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to upstream this before merging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Done, right?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, now all we need is an async compression release! But we can merge without it

Copy link
Contributor

Choose a reason for hiding this comment

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

Want to undraft it and we merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lets go! 👍

@baszalmstra baszalmstra added the JS label Feb 27, 2025
@wolfv wolfv marked this pull request as ready for review February 28, 2025 07:31
@wolfv
Copy link
Contributor

wolfv commented Feb 28, 2025

I merged main in preparation of merging this!

@wolfv wolfv merged commit ea22fe9 into conda:main Feb 28, 2025
16 checks passed
This was referenced Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants