Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
target
.wireit
node_modules
dist
dist
lib
*.tsbuildinfo
28 changes: 21 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"rust/example-crate",
"rust/usuba",
"rust/usuba-compat"
]
Expand All @@ -9,10 +8,12 @@ members = [
resolver = "2"

[workspace.dependencies]
anyhow = { version = "1" }
async-trait = { version = "0.1" }
axum = { version = "0.7" }
blake3 = { version = "1.5" }
bytes = { version = "1" }
hyper-util = { version = "0.1", features = ["client", "client-legacy"] }
js-component-bindgen = { version = "1", features = ["transpile-bindgen"] }
js-sys = { version = "0.3" }
mime_guess = { version = "2" }
Expand All @@ -23,6 +24,7 @@ serde_json = { version = "1" }
tempfile = { version = "3" }
thiserror = { version = "1" }
tokio = { version = "1" }
tower-http = { version = "0.5" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter", "tracing-log", "json"] }
tracing-web = { version = "0.1" }
Expand All @@ -32,7 +34,8 @@ wasm-bindgen = { version = "0.2" }
wasmtime-environ = { version = "20" }
web-sys = { version = "0.3" }
wit-bindgen = { version = "0.25" }
wit-parser = { version = "0.208" }

[profile.release]
opt-level = 'z'
lto = true
lto = true
23 changes: 0 additions & 23 deletions rust/example-crate/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions rust/example-crate/README.md

This file was deleted.

25 changes: 0 additions & 25 deletions rust/example-crate/build-wasm-component.sh

This file was deleted.

6 changes: 0 additions & 6 deletions rust/example-crate/src/bin/cowsay.rs

This file was deleted.

30 changes: 0 additions & 30 deletions rust/example-crate/src/cowsayer/component.rs

This file was deleted.

9 changes: 0 additions & 9 deletions rust/example-crate/src/cowsayer/mod.rs

This file was deleted.

33 changes: 0 additions & 33 deletions rust/example-crate/src/cowsayer/native.rs

This file was deleted.

3 changes: 0 additions & 3 deletions rust/example-crate/src/lib.rs

This file was deleted.

12 changes: 0 additions & 12 deletions rust/example-crate/wit/cowsay.wit

This file was deleted.

1 change: 1 addition & 0 deletions rust/usuba-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
blake3 = { workspace = true }
js-component-bindgen = { workspace = true }
wit-bindgen = { workspace = true }
wasmtime-environ = { workspace = true, features = ["component-model", "compile"] }
2 changes: 1 addition & 1 deletion rust/usuba-compat/build-wasm-component.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ wasm-tools component new \
-o usuba_compat.component.wasm \
--adapt ./wasi_snapshot_preview1.reactor.wasm

jco transpile -O --tla-compat ./usuba_compat.component.wasm \
jco transpile --tla-compat ./usuba_compat.component.wasm \
-o ./usuba_compat

popd
Expand Down
20 changes: 18 additions & 2 deletions rust/usuba-compat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use js_component_bindgen::{transpile, TranspileOpts, Transpiled};
use js_component_bindgen::{transpile, InstantiationMode, TranspileOpts, Transpiled};
use wasmtime_environ::component::Export as WasmtimeExport;

wit_bindgen::generate!({
Expand All @@ -15,7 +15,10 @@ impl Guest for Polyfill {
.mappings
.map(|mappings| mappings.into_iter().collect()),
no_typescript: true,
instantiation: None,
instantiation: options
.instantiation
.unwrap_or_else(|| Instantiation::Automatic)
.into(),
import_bindings: None,
no_nodejs_compat: true,
base64_cutoff: 1024,
Expand All @@ -30,10 +33,23 @@ impl Guest for Polyfill {
.map(|transpiled| transpiled.into())
.map_err(|error| format!("{}", error))
}

fn hash(bytes: Vec<u8>) -> String {
blake3::hash(&bytes).to_string()
}
}

export!(Polyfill);

impl From<Instantiation> for Option<InstantiationMode> {
fn from(value: Instantiation) -> Self {
match value {
Instantiation::Automatic => None,
Instantiation::Manual => Some(InstantiationMode::Async),
}
}
}

impl From<Transpiled> for Artifacts {
fn from(value: Transpiled) -> Self {
Artifacts {
Expand Down
9 changes: 8 additions & 1 deletion rust/usuba-compat/wit/usuba-compat.wit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ world usuba-compat {

record polyfill-options {
name: string,
mappings: option<mappings>
mappings: option<mappings>,
instantiation: option<instantiation>
}

enum instantiation {
automatic,
manual
}

enum export-type {
Expand All @@ -21,4 +27,5 @@ world usuba-compat {
}

export polyfill: func(component: list<u8>, options: polyfill-options) -> result<artifacts, string>;
export hash: func(bytes: list<u8>) -> string;
}
4 changes: 4 additions & 0 deletions rust/usuba/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true, features = ["multipart"] }
blake3 = { workspace = true }
bytes = { workspace = true }
hyper-util = { workspace = true }
mime_guess = { workspace = true }
redb = { workspace = true }
rust-embed = { workspace = true }
Expand All @@ -19,9 +21,11 @@ serde_json = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "io-util", "process", "fs"] }
tower-http = { workspace = true, features = ["cors"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
wit-parser = { workspace = true }
# gcloud-sdk = { version = "0.24.6", features = ["google-cloud-aiplatform-v1"] }

Loading