You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ms...@apache.org on 2019/03/06 08:20:25 UTC

[incubator-openwhisk-runtime-rust] branch master updated (36b4930 -> eaa26f0)

This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git.


    from 36b4930  first commit
     new 340ca11  action compiler
     new c3a89e1  reworked the source generation
     new 253b03a  fixed compilation
     new eaa26f0  hello demo working

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                            |  15 +++++
 example/hello/.gitignore             |  45 ++++++++++++++
 example/hello/Cargo.toml             |   8 +++
 example/hello/src/lib.rs             |  16 +++++
 rust1.32/Dockerfile                  |  26 +++++++++
 rust1.32/Makefile                    |  15 +++++
 rust1.32/compile                     | 110 +++++++++++++++++++++++++++++++++++
 rust1.32/src/Cargo.lock              |  52 +++++++++++++++++
 rust1.32/src/Cargo.toml              |   6 ++
 rust1.32/src/action_loop/Cargo.toml  |   9 +++
 rust1.32/src/action_loop/src/main.rs |  50 ++++++++++++++++
 rust1.32/src/actions/.gitignore      |   3 +
 rust1.32/src/actions/Cargo.toml      |   8 +++
 rust1.32/src/actions/src/lib.rs      |  10 ++++
 14 files changed, 373 insertions(+)
 create mode 100644 example/hello/.gitignore
 create mode 100644 example/hello/Cargo.toml
 create mode 100644 example/hello/src/lib.rs
 create mode 100644 rust1.32/Dockerfile
 create mode 100644 rust1.32/Makefile
 create mode 100755 rust1.32/compile
 create mode 100644 rust1.32/src/Cargo.lock
 create mode 100644 rust1.32/src/Cargo.toml
 create mode 100644 rust1.32/src/action_loop/Cargo.toml
 create mode 100644 rust1.32/src/action_loop/src/main.rs
 create mode 100644 rust1.32/src/actions/.gitignore
 create mode 100644 rust1.32/src/actions/Cargo.toml
 create mode 100644 rust1.32/src/actions/src/lib.rs


[incubator-openwhisk-runtime-rust] 03/05: reworked the source generation

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit c3a89e1e40ea4f1e4b39f709ef74c7e54550c36f
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Tue Mar 5 10:13:49 2019 +0100

    reworked the source generation
---
 example/hello/.gitignore                           | 45 ++++++++++++++++++
 example/hello/Cargo.toml                           |  8 ++++
 example/hello/src/lib.rs                           |  9 ++++
 rust1.32/Dockerfile                                |  3 +-
 rust1.32/compile                                   | 55 +++++++---------------
 rust1.32/src/Cargo.lock                            | 52 ++++++++++++++++++++
 rust1.32/src/Cargo.toml                            |  6 +++
 rust1.32/src/action_loop/Cargo.toml                |  9 ++++
 .../action_loop/src/main.rs}                       | 23 ++++++---
 rust1.32/src/actions/.gitignore                    |  3 ++
 rust1.32/src/actions/Cargo.toml                    |  8 ++++
 rust1.32/src/actions/src/lib.rs                    | 10 ++++
 12 files changed, 186 insertions(+), 45 deletions(-)

diff --git a/example/hello/.gitignore b/example/hello/.gitignore
new file mode 100644
index 0000000..72fc6b4
--- /dev/null
+++ b/example/hello/.gitignore
@@ -0,0 +1,45 @@
+
+# Created by https://www.gitignore.io/api/osx,rust
+# Edit at https://www.gitignore.io/?templates=osx,rust
+
+### OSX ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# End of https://www.gitignore.io/api/osx,rust
\ No newline at end of file
diff --git a/example/hello/Cargo.toml b/example/hello/Cargo.toml
new file mode 100644
index 0000000..315401c
--- /dev/null
+++ b/example/hello/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "actions"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+
diff --git a/example/hello/src/lib.rs b/example/hello/src/lib.rs
new file mode 100644
index 0000000..b507a82
--- /dev/null
+++ b/example/hello/src/lib.rs
@@ -0,0 +1,9 @@
+extern crate serde_json;
+
+use std::collections::HashMap;
+use serde_json::Value;
+
+pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
+    input_data.insert("hello".to_string(),Value::String("world".to_string()));
+    input_data
+}
diff --git a/rust1.32/Dockerfile b/rust1.32/Dockerfile
index 07a6bb9..411b44c 100644
--- a/rust1.32/Dockerfile
+++ b/rust1.32/Dockerfile
@@ -19,7 +19,8 @@ FROM rust:1.32
 COPY --from=builder /bin/proxy /bin/proxy
 RUN mkdir -p /action 
 ADD compile /bin/compile
-ADD compile.launcher.rs /bin/compile.launcher.rs
+ADD src /usr/src
+RUN cd /usr/src ; cargo build 
 ENV OW_COMPILER=/bin/compile
 WORKDIR /action
 ENTRYPOINT ["/bin/proxy"]
diff --git a/rust1.32/compile b/rust1.32/compile
index 0c3228d..343e76a 100755
--- a/rust1.32/compile
+++ b/rust1.32/compile
@@ -21,7 +21,8 @@
 from __future__ import print_function
 import os, sys, codecs, subprocess
 from os.path import abspath, exists, dirname
-import tempfile
+import time
+import shutil
 
 ## utils 
 # write a file creating intermediate directories
@@ -47,59 +48,39 @@ version = "0.1.0"
 serde_json = "1.0"
 """
 
-cargo_actionloop = """[package]
-name = "action_loop"
-version = "0.1.0"
-authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
-
-[dependencies]
-serde_json = "1.0"
-libc = "0.2.49"
-actions = { path = "../actions" }
-"""
-
-cargo_workspace = """
-[workspace]
-
-members = [
-"action_loop",
-"actions",
-]
-"""
-
-def build():
+def build(tgt_dir):
     pass
 
-def sources(main, src_dir, tgt_dir, launcher):
-    src_file = abspath("%s/exec" % src_dir)
-       
+def sources(main, src_dir):
+    # move away the action dir and replace with the new
+    tmpname = str(int(time.time()))
+    shutil.move("/usr/src/actions", "/usr/src/src%s" % tmpname)
+    shutil.move(src_dir, "/usr/src/actions")
+
     # move exec in the right place
+    src_file = "/usr/src/actions/exec"
     if exists(src_file):
-        os.makedirs(src_dir+"/src", mode=0o755, exist_ok=True)
-        copy_replace(src_file, src_dir+"/src/exec__.rs")
+        os.makedirs("/usr/src/actions/src", mode=0o755, exist_ok=True)
+        copy_replace(src_file, "/usr/src/actions/src/lib.rs")
     
     # add a cargo.toml if needed
-    cargo_action_file = src_dir+"/Cargo.toml"
+    cargo_action_file = "/usr/src/actions/Cargo.toml"
     if not exists(cargo_action_file):
         write_file(cargo_action_file, cargo_action)
 
     # write the boilerplate in a temp dir
-    os.makedirs("/tmp/src", mode=0o755, exist_ok=True)
-    tmp_dir = tempfile.mkdtemp(prefix='/tmp/src/')
-    copy_replace(launcher, tmp_dir+"/action_loop/src/main.rs",
+    launcher = "/usr/src/action_loop/tmp%s" % tmpname
+    shutil.move("/usr/src/action_loop/src/main.rs", launcher)
+    copy_replace(launcher, "/usr/src/action_loop/src/main.rs",
           "use actions::main as actionMain;",
           "use actions::%s as actionMain;" % main )
-    write_file(tmp_dir+"/action_loop/Cargo.toml", cargo_actionloop)
-    write_file(tmp_dir+"/Cargo.toml", cargo_workspace)
-    os.rename(src_dir, tmp_dir+"/actions")
-    return tmp_dir
 
 if __name__ == '__main__':
     if len(sys.argv) < 4:
         sys.stdout.write("usage: <main-function> <source-dir> <target-dir>\n")
         sys.stdout.flush()
         sys.exit(1)
-    dir = sources(sys.argv[1], abspath(sys.argv[2]), abspath(sys.argv[3]), abspath(sys.argv[0]+".launcher.rs"))
-    print(dir)
+    sources(sys.argv[1], abspath(sys.argv[2]))
+    build(abspath(sys.argv[3]))
     sys.stdout.flush()
     sys.stderr.flush()
diff --git a/rust1.32/src/Cargo.lock b/rust1.32/src/Cargo.lock
new file mode 100644
index 0000000..2015f28
--- /dev/null
+++ b/rust1.32/src/Cargo.lock
@@ -0,0 +1,52 @@
+[[package]]
+name = "action_loop"
+version = "0.1.0"
+dependencies = [
+ "actions 0.1.0",
+ "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "actions"
+version = "0.1.0"
+dependencies = [
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "itoa"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.49"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "ryu"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde"
+version = "1.0.89"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde_json"
+version = "1.0.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[metadata]
+"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
+"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e"
+"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
+"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
+"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
diff --git a/rust1.32/src/Cargo.toml b/rust1.32/src/Cargo.toml
new file mode 100644
index 0000000..b8121b6
--- /dev/null
+++ b/rust1.32/src/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+members = [
+"action_loop",
+"actions",
+]
diff --git a/rust1.32/src/action_loop/Cargo.toml b/rust1.32/src/action_loop/Cargo.toml
new file mode 100644
index 0000000..253fd02
--- /dev/null
+++ b/rust1.32/src/action_loop/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "action_loop"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+libc = "0.2.49"
+actions = { path = "../actions" }
\ No newline at end of file
diff --git a/rust1.32/compile.launcher.rs b/rust1.32/src/action_loop/src/main.rs
similarity index 61%
rename from rust1.32/compile.launcher.rs
rename to rust1.32/src/action_loop/src/main.rs
index 9f50140..e4e143d 100644
--- a/rust1.32/compile.launcher.rs
+++ b/rust1.32/src/action_loop/src/main.rs
@@ -11,6 +11,7 @@ use serde_json::{Value, Error};
 use actions::main as actionMain;
 
 fn main() {
+    let mut fd3 = unsafe { File::from_raw_fd(3)};
     loop {
         let mut buffer = String::new();
         io::stdin().read_line(&mut buffer).unwrap();
@@ -23,19 +24,27 @@ fn main() {
                         let mut unparsed_payload:Result<HashMap<String,Value>,Error> = serde_json::from_value(val);
                         match unparsed_payload {
                             Ok(value) => payload = value,
-                            Err(_) => eprintln!("Error parsing value json")
+                            Err(err) => {
+                                eprintln!("Error parsing value json: {}", err);
+                                continue
+                            }
                         }
                     } else {
                         env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
                     }
                 }
             }
-            Err(e) => eprintln!("Error: {}", e)
+            Err(e) =>{
+                eprintln!("Error: {}", e);
+                continue
+            }
+        }
+        
+        match serde_json::to_string(&actionMain(payload)){
+            Ok(result) => { write!(&mut fd3, "{}\n", result).expect("Error writting on fd3");}
+            Err(err) => {  eprintln!("Error parsing resul value json: {}", err);}
         }
-        let action_results = actionMain(payload);
-        let mut fd3 = unsafe { File::from_raw_fd(3) };
-        write!(&mut fd3, "{}", action_results);
-        stdout().flush();
-        stderr().flush();
+        stdout().flush().expect("Error flushing stdout");
+        stderr().flush().expect("Error flushing stderr");
     }
 }
diff --git a/rust1.32/src/actions/.gitignore b/rust1.32/src/actions/.gitignore
new file mode 100644
index 0000000..6936990
--- /dev/null
+++ b/rust1.32/src/actions/.gitignore
@@ -0,0 +1,3 @@
+/target
+**/*.rs.bk
+Cargo.lock
diff --git a/rust1.32/src/actions/Cargo.toml b/rust1.32/src/actions/Cargo.toml
new file mode 100644
index 0000000..315401c
--- /dev/null
+++ b/rust1.32/src/actions/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "actions"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+
diff --git a/rust1.32/src/actions/src/lib.rs b/rust1.32/src/actions/src/lib.rs
new file mode 100644
index 0000000..cbeafbd
--- /dev/null
+++ b/rust1.32/src/actions/src/lib.rs
@@ -0,0 +1,10 @@
+extern crate serde_json;
+
+use std::collections::HashMap;
+use serde_json::Value;
+
+
+pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
+    input_data.insert("added_key".to_string(),Value::String("test".to_string()));
+    input_data
+}


[incubator-openwhisk-runtime-rust] 05/05: hello demo working

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit eaa26f0d7b08c8b1fd38a48da51bd90fce93a867
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Wed Mar 6 09:18:38 2019 +0100

    hello demo working
---
 README.md                | 15 ++++++++++++++-
 example/hello/src/lib.rs | 13 ++++++++++---
 rust1.32/Makefile        |  7 +++++--
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index ca09760..d4e48bc 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,16 @@
 # incubator-openwhisk-runtime-rust
 
-Work in Progress! Do not use...
+Work in Progress! Do not use yet...
+
+
+# Work Done
+
+- implemented the actionloop
+- implemented the Docker image
+- implemented the action compiler
+
+# Work to do
+
+- Add the gradle build
+- Implement the mandatory scala tests
+- Submit and add to the list of supported runtimes
diff --git a/example/hello/src/lib.rs b/example/hello/src/lib.rs
index b507a82..5f43e8d 100644
--- a/example/hello/src/lib.rs
+++ b/example/hello/src/lib.rs
@@ -3,7 +3,14 @@ extern crate serde_json;
 use std::collections::HashMap;
 use serde_json::Value;
 
-pub fn main(mut input_data: HashMap<String, Value>) -> HashMap<String, Value> {
-    input_data.insert("hello".to_string(),Value::String("world".to_string()));
-    input_data
+pub fn main(args: HashMap<String, Value>) -> HashMap<String, Value> {
+    let name_opt = args.get("name");
+    let name = if name_opt.is_some() {
+        name_opt.unwrap().as_str().unwrap()    
+    } else {
+        "stranger"
+    };
+    let mut out = HashMap::new();
+    out.insert("greeting".to_string(), Value::String(format!("Hello, {}", name)));
+    out
 }
diff --git a/rust1.32/Makefile b/rust1.32/Makefile
index 46598eb..7ee6d5f 100644
--- a/rust1.32/Makefile
+++ b/rust1.32/Makefile
@@ -1,4 +1,4 @@
-USER?=openwhisk
+USER=docker.io/actionloop
 IMAGE=actionloop-rust-v1.32
 
 .PHONY: build
@@ -9,4 +9,7 @@ build:
 devel: build
 	docker run -ti -p 8080:8080 --entrypoint=bash  \
 	-v $(PWD):/mnt -e OW_COMPILER=/mnt/compile \
-	$(USER)/$(IMAGE)
+
+push: build
+	docker login
+	docker push $(USER)/$(IMAGE)


[incubator-openwhisk-runtime-rust] 02/05: action compiler

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 340ca11d071edc5b5d3b109569dbf9d4f88154f8
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Fri Mar 1 10:45:53 2019 +0100

    action compiler
---
 README.md                    |   2 +
 rust1.32/Dockerfile          |  25 +++++++++++
 rust1.32/Makefile            |  12 +++++
 rust1.32/compile             | 105 +++++++++++++++++++++++++++++++++++++++++++
 rust1.32/compile.launcher.rs |  41 +++++++++++++++++
 5 files changed, 185 insertions(+)

diff --git a/README.md b/README.md
index 89ddcdf..ca09760 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
 # incubator-openwhisk-runtime-rust
+
+Work in Progress! Do not use...
diff --git a/rust1.32/Dockerfile b/rust1.32/Dockerfile
new file mode 100644
index 0000000..07a6bb9
--- /dev/null
+++ b/rust1.32/Dockerfile
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+FROM actionloop/actionloop-v2:latest as builder
+FROM rust:1.32
+COPY --from=builder /bin/proxy /bin/proxy
+RUN mkdir -p /action 
+ADD compile /bin/compile
+ADD compile.launcher.rs /bin/compile.launcher.rs
+ENV OW_COMPILER=/bin/compile
+WORKDIR /action
+ENTRYPOINT ["/bin/proxy"]
diff --git a/rust1.32/Makefile b/rust1.32/Makefile
new file mode 100644
index 0000000..46598eb
--- /dev/null
+++ b/rust1.32/Makefile
@@ -0,0 +1,12 @@
+USER?=openwhisk
+IMAGE=actionloop-rust-v1.32
+
+.PHONY: build
+
+build:
+	docker build -t $(USER)/$(IMAGE) .
+
+devel: build
+	docker run -ti -p 8080:8080 --entrypoint=bash  \
+	-v $(PWD):/mnt -e OW_COMPILER=/mnt/compile \
+	$(USER)/$(IMAGE)
diff --git a/rust1.32/compile b/rust1.32/compile
new file mode 100755
index 0000000..0c3228d
--- /dev/null
+++ b/rust1.32/compile
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+"""Rust Action Builder
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+"""
+
+from __future__ import print_function
+import os, sys, codecs, subprocess
+from os.path import abspath, exists, dirname
+import tempfile
+
+## utils 
+# write a file creating intermediate directories
+def write_file(file, body):
+    os.makedirs(dirname(file), mode=0o755, exist_ok=True)
+    with open(file, mode="w", encoding="utf-8") as f:
+        f.write(body)
+
+# copy a file eventually replacing a substring
+def copy_replace(src, dst, match=None, replacement=""):
+    with codecs.open(src, 'r', 'utf-8') as s:
+        body = s.read()
+        if match:
+            body = body.replace(match, replacement)
+        write_file(dst, body)
+
+## cargo
+cargo_action = """[package]
+name = "actions"
+version = "0.1.0"
+
+[dependencies]
+serde_json = "1.0"
+"""
+
+cargo_actionloop = """[package]
+name = "action_loop"
+version = "0.1.0"
+authors = ["Roberto Diaz <ro...@theagilemonkeys.com>"]
+
+[dependencies]
+serde_json = "1.0"
+libc = "0.2.49"
+actions = { path = "../actions" }
+"""
+
+cargo_workspace = """
+[workspace]
+
+members = [
+"action_loop",
+"actions",
+]
+"""
+
+def build():
+    pass
+
+def sources(main, src_dir, tgt_dir, launcher):
+    src_file = abspath("%s/exec" % src_dir)
+       
+    # move exec in the right place
+    if exists(src_file):
+        os.makedirs(src_dir+"/src", mode=0o755, exist_ok=True)
+        copy_replace(src_file, src_dir+"/src/exec__.rs")
+    
+    # add a cargo.toml if needed
+    cargo_action_file = src_dir+"/Cargo.toml"
+    if not exists(cargo_action_file):
+        write_file(cargo_action_file, cargo_action)
+
+    # write the boilerplate in a temp dir
+    os.makedirs("/tmp/src", mode=0o755, exist_ok=True)
+    tmp_dir = tempfile.mkdtemp(prefix='/tmp/src/')
+    copy_replace(launcher, tmp_dir+"/action_loop/src/main.rs",
+          "use actions::main as actionMain;",
+          "use actions::%s as actionMain;" % main )
+    write_file(tmp_dir+"/action_loop/Cargo.toml", cargo_actionloop)
+    write_file(tmp_dir+"/Cargo.toml", cargo_workspace)
+    os.rename(src_dir, tmp_dir+"/actions")
+    return tmp_dir
+
+if __name__ == '__main__':
+    if len(sys.argv) < 4:
+        sys.stdout.write("usage: <main-function> <source-dir> <target-dir>\n")
+        sys.stdout.flush()
+        sys.exit(1)
+    dir = sources(sys.argv[1], abspath(sys.argv[2]), abspath(sys.argv[3]), abspath(sys.argv[0]+".launcher.rs"))
+    print(dir)
+    sys.stdout.flush()
+    sys.stderr.flush()
diff --git a/rust1.32/compile.launcher.rs b/rust1.32/compile.launcher.rs
new file mode 100644
index 0000000..9f50140
--- /dev/null
+++ b/rust1.32/compile.launcher.rs
@@ -0,0 +1,41 @@
+extern crate serde_json;
+extern crate actions;
+extern crate libc;
+
+use std::env;
+use std::io::{self, Write, stdout, stderr};
+use std::fs::File;
+use std::os::unix::io::FromRawFd;
+use std::collections::HashMap;
+use serde_json::{Value, Error};
+use actions::main as actionMain;
+
+fn main() {
+    loop {
+        let mut buffer = String::new();
+        io::stdin().read_line(&mut buffer).unwrap();
+        let parsed_input:Result<HashMap<String,Value>,Error> = serde_json::from_str(&buffer);
+        let mut payload:HashMap<String, Value> = HashMap::new();
+        match parsed_input {
+            Ok(n) => {
+                for (key, val) in n {
+                    if key == "value" {
+                        let mut unparsed_payload:Result<HashMap<String,Value>,Error> = serde_json::from_value(val);
+                        match unparsed_payload {
+                            Ok(value) => payload = value,
+                            Err(_) => eprintln!("Error parsing value json")
+                        }
+                    } else {
+                        env::set_var(format!("__OW_{}", key.to_uppercase()), val.to_string());
+                    }
+                }
+            }
+            Err(e) => eprintln!("Error: {}", e)
+        }
+        let action_results = actionMain(payload);
+        let mut fd3 = unsafe { File::from_raw_fd(3) };
+        write!(&mut fd3, "{}", action_results);
+        stdout().flush();
+        stderr().flush();
+    }
+}


[incubator-openwhisk-runtime-rust] 01/05: first commit

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 36b49303032acb92a5446b1f9c33c1ace2a5389e
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Thu Feb 28 16:54:31 2019 +0100

    first commit
---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..89ddcdf
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# incubator-openwhisk-runtime-rust


[incubator-openwhisk-runtime-rust] 04/05: fixed compilation

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git

commit 253b03af8de724bd97e43d059d97a93a9cb74ea4
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Tue Mar 5 17:09:12 2019 +0100

    fixed compilation
---
 rust1.32/compile | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/rust1.32/compile b/rust1.32/compile
index 343e76a..650904e 100755
--- a/rust1.32/compile
+++ b/rust1.32/compile
@@ -49,7 +49,31 @@ serde_json = "1.0"
 """
 
 def build(tgt_dir):
-    pass
+     # support RELEASE
+     cmd = ["cargo", "build"]
+     bin_dir = "debug"
+     if "RELEASE" in os.environ:
+         cmd += "--release"
+         bin_dir = "release"
+     env = {
+         "CARGO_HOME": "/usr/local/cargo",
+         "PATH": "/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+         "RUSTUP_HOME": "/usr/local/rustup"
+     }
+     p = subprocess.Popen(cmd,
+           stdout=subprocess.PIPE,
+           stderr=subprocess.PIPE,
+           cwd="/usr/src", env=env)
+     (o, e) = p.communicate()
+     if isinstance(o, bytes): o = o.decode('utf-8')
+     if isinstance(e, bytes): e = e.decode('utf-8')
+     if p.returncode != 0:
+        sys.stdout.write(o)
+        sys.stdout.write(e)
+     else:
+       shutil.move(
+             "/usr/src/target/%s/action_loop" % bin_dir, 
+             "%s/exec" % tgt_dir)
 
 def sources(main, src_dir):
     # move away the action dir and replace with the new