Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions templates/component-rust/content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.spin/
16 changes: 16 additions & 0 deletions templates/component-rust/content/Cargo.toml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "{{project-name | kebab_case}}"
authors = ["{{authors}}"]
description = "{{project-description}}"
version = "0.1.0"
rust-version = "1.78"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1"
wit-bindgen = "0.36.0"

[workspace]
9 changes: 9 additions & 0 deletions templates/component-rust/content/component.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package component:{{project-name | kebab_case}};

interface {{project-name | kebab_case}} {
hello: func() -> string;
}

world component {
export {{project-name | kebab_case}};
}
13 changes: 13 additions & 0 deletions templates/component-rust/content/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spin_manifest_version = 2

[application]
name = "{{project-name | kebab_case}}"
version = "0.1.0"
authors = ["{{authors}}"]
description = "{{project-description}}"

[component.{{project-name | kebab_case}}]
source = "target/wasm32-wasip2/release/{{project-name | snake_case}}.wasm"
[component.{{project-name | kebab_case}}.build]
command = "cargo build --target wasm32-wasip2 --release"
watch = ["src/**/*.rs", "Cargo.toml"]
14 changes: 14 additions & 0 deletions templates/component-rust/content/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
impl Guest for Exports {
fn hello() -> String {
"Hello from {{project-name | snake_case}}".to_string()
}
}

// Boilerplate below here
use crate::exports::component::{{project-name | snake_case}}::{{project-name | snake_case}}::Guest;
wit_bindgen::generate!({
world: "component",
path: "component.wit",
});
struct Exports;
export!(Exports);
6 changes: 6 additions & 0 deletions templates/component-rust/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/wasm32-wasip2/release/{{project-name | snake_case}}.wasm"
[component.{{project-name | kebab_case}}.build]
command = "cargo build --target wasm32-wasip2 --release"
workdir = "{{ output-path }}"
watch = ["src/**/*.rs", "Cargo.toml"]
12 changes: 12 additions & 0 deletions templates/component-rust/metadata/spin-template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
manifest_version = "1"
id = "component-rust"
description = "Pure Rust component to be used as a dependency for other component"
tags = ["rust"]

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
Loading