Skip to content

Commit

Permalink
Rust 1.34 support (#1119)
Browse files Browse the repository at this point in the history
* Verified working wskdeploy with rust

* Added unit tests

* Working tests; rs file extension still does not work

* Added headers to files and removed un-needed Cargo source files

* Merge resolution

Co-authored-by: Daniel Hartig <dhartig@Daniels-MacBook-Pro.local>
  • Loading branch information
kingledion and Daniel Hartig authored Feb 22, 2021
1 parent 503192d commit 3169ed7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
24 changes: 22 additions & 2 deletions runtimes/runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ const (
PHP_FILE_EXTENSION = "php"
ZIP_FILE_EXTENSION = "zip"
RUBY_FILE_EXTENSION = "rb"
RUST_FILE_EXTENSION = "rs"
GO_FILE_EXTENSION = "go"
RUST_FILE_EXTENSION = "rs"
NODEJS_RUNTIME = "nodejs"
SWIFT_RUNTIME = SWIFT_FILE_EXTENSION
PYTHON_RUNTIME = "python"
JAVA_RUNTIME = JAVA_FILE_EXTENSION
DOTNET_RUNTIME = ZIP_FILE_EXTENSION
PHP_RUNTIME = PHP_FILE_EXTENSION
RUBY_RUNTIME = "ruby"
RUST_RUNTIME = "rust"
GO_RUNTIME = GO_FILE_EXTENSION
RUST_RUNTIME = "rust"
HTTP_CONTENT_TYPE_KEY = "Content-Type"
HTTP_CONTENT_TYPE_VALUE = "application/json; charset=UTF-8"
RUNTIME_NOT_SPECIFIED = "NOT SPECIFIED"
Expand Down Expand Up @@ -214,6 +214,8 @@ func FileExtensionRuntimes(op OpenWhiskInfo) (ext map[string]string) {
} else if strings.Contains(k, DOTNET_RUNTIME) {
ext[CSHARP_FILE_EXTENSION] = k
ext[ZIP_FILE_EXTENSION] = k
} else if strings.Contains(k, RUST_RUNTIME) {
ext[RUST_FILE_EXTENSION] = k
}
}
return
Expand Down Expand Up @@ -243,6 +245,8 @@ func FileRuntimeExtensions(op OpenWhiskInfo) (rte map[string]string) {
rte[v[i].Kind] = GO_FILE_EXTENSION
} else if strings.Contains(k, DOTNET_RUNTIME) {
rte[v[i].Kind] = CSHARP_FILE_EXTENSION
} else if strings.Contains(k, RUST_RUNTIME) {
rte[v[i].Kind] = RUST_FILE_EXTENSION
}
}
}
Expand Down Expand Up @@ -503,6 +507,22 @@ var RUNTIME_DETAILS = []byte(`{
"attachmentType": "text/plain"
}
}
],
"rust": [
{
"kind": "rust:1.34",
"default": true,
"deprecated": false,
"attached": {
"attachmentName": "codefile",
"attachmentType": "text/plain"
},
"image": {
"prefix": "openwhisk",
"name": "actionloop-rust-v1.34",
"tag": "latest"
}
}
]
},
"blackboxes": [
Expand Down
6 changes: 6 additions & 0 deletions specification/html/spec_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ The following runtime values are currently supported by the OpenWhisk platform "
| swift@3.1.1 **(deprecated)** | swift:3.1.1 | [openwhisk/action-swift-v3.1.1](https://hub.docker.com/r/openwhisk/action-swift-v3.1.1) | nightly | Swift 3.1.1 language runtime |
| dotnet&nbsp;&#124; dotnet@2.2 (default) | dotnet:2.2 | [openwhisk/action-dotnet-v2.2](https://hub.docker.com/r/openwhisk/action-dotnet-v2.2) | nightly | .NET Core 2.2 runtime |
| dotnet@3.1 | dotnet:3.1 | [openwhisk/action-dotnet-v3.1](https://hub.docker.com/r/openwhisk/action-dotnet-v3.1) | nightly | .NET Core 3.1 runtime |
| rust@1.34 | rust:1.34 | openwhisk/actionloop-rust-v1.34:latest | Latest Rust 1.34 language runtime |
| language:default | N/A | N/A | N/A | Permit the OpenWhisk platform to select the correct default language runtime. |
See the file [runtimes.json](https://github.com/apache/openwhisk/blob/master/ansible/files/runtimes.json) in
Expand Down Expand Up @@ -222,6 +223,11 @@ following file extensions are recognized and will be run on the version of corre
<td>ruby</td>
<td>Latest Ruby language runtime.</td>
</tr>
<tr>
<td>.rs</td>
<td>rust</td>
<td>Latest Rust language runtime.</td>
</tr>
</table>
</html>

Expand Down
18 changes: 18 additions & 0 deletions tests/src/integration/runtimetests/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,31 @@ packages:
runtime: dotnet:2.2
main: Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main
zipaction-with-explicit-runtime:
annotations:
web-export: true
function: src/helloworld
runtime: nodejs:default
inputs:
name: string
place: string
outputs:
payload: string
# hellorust134-with-explicit-runtime:
# function: src/lib.rs
# runtime: rust:1.34
# inputs:
# name: string
# place: string
# outputs:
# payload: string
hellocargo134-with-explicit-runtime:
function: src/helloCargo.zip
runtime: rust:1.34
inputs:
name: string
place: string
outputs:
payload: string
TestImplicitRuntimes:
actions:
greetingnodejs-without-explicit-runtime:
Expand Down
Binary file not shown.
44 changes: 44 additions & 0 deletions tests/src/integration/runtimetests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.
*/

extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Input {
#[serde(default = "stranger")]
name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Output {
greeting: String,
}

fn stranger() -> String {
"stranger".to_string()
}

pub fn main(args: Value) -> Result<Value, Error> {
let input: Input = serde_json::from_value(args)?;
let output = Output {
greeting: format!("Hello, {}", input.name),
};
serde_json::to_value(output)
}

0 comments on commit 3169ed7

Please sign in to comment.