Move the wasm lib, and cleanup rust directory and all references (#5585)

* git mv src/wasm-lib rust

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* mv wasm-lib to workspace

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* mv kcl-lib

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* mv derive docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* resolve file paths

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* clippy

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* move more shit

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix more paths

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* make yarn build:wasm work

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix scripts

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixups

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* better references

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix cargo ci

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix reference

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix more ci

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cargo sort

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix script

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fmt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix a dep

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* sort

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* remove unused deps

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Revert "remove unused deps"

This reverts commit fbabdb062e275fd5cbc1476f8480a1afee15d972.

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* deps;

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-03-01 13:59:01 -08:00
committed by GitHub
parent 0a2bf4b55f
commit c3bdc6f106
1443 changed files with 509 additions and 4274 deletions

View File

@ -0,0 +1,26 @@
//! Local implementation of threads with tokio.
pub struct JoinHandle {
inner: tokio::task::JoinHandle<()>,
}
impl JoinHandle {
pub fn new<F>(future: F) -> Self
where
F: std::future::Future<Output = ()> + Send + 'static,
{
Self {
inner: tokio::spawn(future),
}
}
}
impl crate::thread::Thread for JoinHandle {
fn abort(&self) {
self.inner.abort();
}
fn is_finished(&self) -> bool {
self.inner.is_finished()
}
}

View File

@ -0,0 +1,24 @@
//! An implementation of threads that works in wasm with promises and other platforms with tokio.
#![allow(dead_code)]
#![allow(unused_imports)]
#[cfg(not(target_arch = "wasm32"))]
mod local;
#[cfg(not(target_arch = "wasm32"))]
pub use local::JoinHandle;
#[cfg(target_arch = "wasm32")]
#[cfg(not(test))]
mod wasm;
#[cfg(target_arch = "wasm32")]
#[cfg(not(test))]
pub use wasm::JoinHandle;
pub trait Thread {
/// Abort a thread.
fn abort(&self);
/// Check if a thread is finished.
fn is_finished(&self) -> bool;
}

View File

@ -0,0 +1,36 @@
//! Implementation of thread using Promise for wasm.
pub struct JoinHandle {
inner: Option<crate::wasm::Promise>,
}
impl JoinHandle {
pub fn new<F>(future: F) -> Self
where
F: std::future::Future<Output = ()> + Send + 'static,
{
Self {
inner: Some(
wasm_bindgen_futures::future_to_promise(async move {
future.await;
Ok(wasm_bindgen::JsValue::NULL)
})
.into(),
),
}
}
}
impl crate::thread::Thread for JoinHandle {
fn abort(&self) {
if let Some(promise) = &self.inner {
let future = crate::wasm::JsFuture::from(promise.0.as_ref().unwrap().clone());
drop(future);
}
}
fn is_finished(&self) -> bool {
// no-op for now but we don't need it.
true
}
}