-
Notifications
You must be signed in to change notification settings - Fork 260
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
Templates: add a Rust template for non-trigger components #2970
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
.spin/ |
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] |
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}}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
spin_manifest_version = 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels extremely awkward to create a I feel like the ask here is for the manifest to provide for building and referencing library components but I am not sold that mixing them in with "application" components is the way to go right now: perhaps we should step back and ask how we should represent library components in the manifest, then create a template as part of that? |
||
|
||
[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"] |
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); |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use wasip1 everywhere else - is p2 stable enough that we should be moving to it? |
||
[component.{{project-name | kebab_case}}.build] | ||
command = "cargo build --target wasm32-wasip2 --release" | ||
workdir = "{{ output-path }}" | ||
watch = ["src/**/*.rs", "Cargo.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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove "pure" e.g.
Suggested change
or something like that? |
||||||
tags = ["rust"] | ||||||
|
||||||
[add_component] | ||||||
skip_files = ["spin.toml"] | ||||||
[add_component.snippets] | ||||||
component = "component.txt" | ||||||
|
||||||
[parameters] | ||||||
project-description = { type = "string", prompt = "Description", default = "" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the status of the wasm32-wasip2 target in 1.78?