Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update document in macro * Refactor ewasm_main and add example - add ewasm_auto_assert_eq! - add hello example - rename `#[ewas_main(unwrap)]` to `#[ewas_main(auto)]` * Update README * Add CI for hello example
- Loading branch information
Showing
18 changed files
with
546 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
hello-example: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Super-Linter | ||
uses: github/super-linter@v3 | ||
env: | ||
VALIDATE_ALL_CODEBASE: false | ||
DEFAULT_BRANCH: main | ||
VALIDATE_RUST_2018: true | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: cachix/install-nix-action@v13 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-21.05-small | ||
|
||
- name: Default example test | ||
run: nix-shell --run 'run-example-test hello' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.'cfg(target_arch="wasm32")'] | ||
rustflags = ["-C", "link-arg=--export-table"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "hello-contract" | ||
version = "0.1.0" | ||
authors = ["Antonio Yang <yanganto@gmail.com>"] | ||
edition = "2018" | ||
description = "The example contract using sewup default feature" | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
sewup ={ version = "0.0.3", path = "../../sewup" } | ||
sewup-derive = { version = "0.0.3", path = "../../sewup-derive" } | ||
anyhow = "1.0.40" | ||
|
||
[profile.release] | ||
incremental = false | ||
panic = "abort" | ||
lto = true | ||
opt-level = "z" | ||
|
||
[profile.release.package.hello-contract] | ||
incremental = false | ||
opt-level = "z" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anyhow::Result; | ||
|
||
use sewup::primitives::Contract; | ||
use sewup_derive::{ewasm_fn, ewasm_fn_sig, ewasm_main, ewasm_test}; | ||
|
||
#[ewasm_fn] | ||
fn hello() -> Result<String> { | ||
Ok("hello world".to_string()) | ||
} | ||
|
||
#[ewasm_main(auto)] | ||
fn main() -> Result<String> { | ||
let contract = Contract::new()?; | ||
let greeting = match contract.get_function_selector()? { | ||
ewasm_fn_sig!(hello) => hello()?, | ||
_ => panic!("unknown handle"), | ||
}; | ||
Ok(greeting) | ||
} | ||
|
||
#[ewasm_test] | ||
mod tests { | ||
use super::*; | ||
use sewup_derive::{ewasm_assert_eq, ewasm_auto_assert_eq, ewasm_output_from}; | ||
|
||
#[ewasm_test] | ||
fn test_get_greeting() { | ||
ewasm_assert_eq!( | ||
hello(), | ||
vec![11, 0, 0, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] | ||
); | ||
ewasm_assert_eq!(hello(), ewasm_output_from!("hello world".to_string())); | ||
ewasm_auto_assert_eq!(hello(), "hello world".to_string()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.