Skip to content

Commit

Permalink
hello-world on Rust 2015 (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevoronov authored Feb 22, 2019
1 parent 5536d0a commit 83b1a61
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 11 deletions.
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ lazy val `vm-hello-world` = (project in file("vm/examples/hello-world"))
rustVmExample("hello-world")
)

lazy val `vm-hello-world2` = (project in file("vm/examples/hello-world2/app"))
lazy val `vm-hello-world2-2015` = (project in file("vm/examples/hello-world2/app-2015"))
.settings(
rustVmExample("hello-world2/app")
rustVmExample("hello-world2/app-2015")
)

lazy val `vm-hello-world2-2018` = (project in file("vm/examples/hello-world2/app-2018"))
.settings(
rustVmExample("hello-world2/app-2018")
)

lazy val `vm-hello-world2-runner` = (project in file("vm/examples/hello-world2/runner"))
Expand All @@ -68,7 +73,8 @@ lazy val `vm-hello-world2-runner` = (project in file("vm/examples/hello-world2/r
cryptoHashing,
)
)
.dependsOn(vm, `vm-hello-world2`)
.dependsOn(vm, `vm-hello-world2-2015`)
.dependsOn(vm, `vm-hello-world2-2018`)
.enablePlugins(AutomateHeaderPlugin)

lazy val `vm-llamadb` = (project in file("vm/examples/llamadb"))
Expand Down

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

21 changes: 21 additions & 0 deletions vm/examples/hello-world2/app-2015/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "hello_world2_2015"
version = "0.1.0"
authors = ["Fluence Labs"]
publish = false
description = "Just a demo application for Fluence with logging ability"

[lib]
name = "hello_world2_2015"
path = "src/lib.rs"
crate-type = ["cdylib"]

[profile.release]
debug = false
lto = true
opt-level = "z"
panic = "abort"

[dependencies]
log = "0.4"
fluence = { version = "0.0.10", features = ["export_allocator", "wasm_logger"] }
File renamed without changes.
34 changes: 34 additions & 0 deletions vm/examples/hello-world2/app-2015/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2018 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//! A simple demo application for Fluence.
#![feature(custom_attribute)]
extern crate fluence;

extern crate log;

use fluence::sdk::*;
use log::info;

fn init() {
logger::WasmLogger::init_with_level(log::Level::Info).unwrap();
}

#[invocation_handler(init_fn = init)]
fn greeting(name: String) -> String {
info!("{} has been successfully greeted", name);
format!("Hello, world! From user {}", name)
}
94 changes: 94 additions & 0 deletions vm/examples/hello-world2/app-2018/Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "hello_world2"
name = "hello_world2_2018"
version = "0.1.0"
authors = ["Fluence Labs"]
publish = false
description = "Just a demo application for Fluence with logging ability"
edition = "2018"

[lib]
name = "hello_world2"
name = "hello_world2_2018"
path = "src/lib.rs"
crate-type = ["cdylib"]

Expand Down
1 change: 1 addition & 0 deletions vm/examples/hello-world2/app-2018/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import fluence.vm.{VmError, WasmVm}
import scala.language.higherKinds

/**
* A hello-world2 example runner that is an example of possible debugger of `hello_world2` backend application.
* A hello-world2 examples runner that is an example of possible debugger of `hello_world2` backend applications
* (written both on Rust 2015 and 2018).
* Internally it creates WasmVm and invokes the application with some parameters. Also can be used as a template for
* debugging other backend applications.
*/
Expand All @@ -46,9 +47,9 @@ object HelloWorldRunner extends IOApp {
/*
In correct execution the console output should be like this:
INFO [hello_world2] John has been successfully greeted
INFO [hello_world2] has been successfully greeted
INFO [hello_world2] Peter has been successfully greeted
INFO [hello_world2_2018] John has been successfully greeted
INFO [hello_world2_2018] has been successfully greeted
INFO [hello_world2_2018] Peter has been successfully greeted
[SUCCESS] Execution Results.
initState=ByteVector(32 bytes, 0x6f3ebb11cb3266aaf12c1eea3f6892c78f563dccb43d6c4b4b153ea10be3decf)
result1=Hello from Fluence to John
Expand Down Expand Up @@ -81,7 +82,7 @@ object HelloWorldRunner extends IOApp {
println(s"Starts for input file $value")
value
case None
throw new IllegalArgumentException("Full path for wasm file is required!")
throw new IllegalArgumentException("Please provide a full path for wasm file as the first CLI argument!")
}
}

Expand Down

0 comments on commit 83b1a61

Please sign in to comment.