From 3169ed7218b58819a5dcf3e1010a04e810567a06 Mon Sep 17 00:00:00 2001 From: Daniel Hartig Date: Mon, 22 Feb 2021 10:19:04 -0600 Subject: [PATCH] Rust 1.34 support (#1119) * 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 --- runtimes/runtimes.go | 24 +++++++++- specification/html/spec_actions.md | 6 +++ .../integration/runtimetests/manifest.yaml | 18 +++++++ .../runtimetests/src/helloCargo.zip | Bin 0 -> 746 bytes tests/src/integration/runtimetests/src/lib.rs | 44 ++++++++++++++++++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/src/integration/runtimetests/src/helloCargo.zip create mode 100644 tests/src/integration/runtimetests/src/lib.rs diff --git a/runtimes/runtimes.go b/runtimes/runtimes.go index 76e083ee8..db1bea91a 100644 --- a/runtimes/runtimes.go +++ b/runtimes/runtimes.go @@ -43,8 +43,8 @@ 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" @@ -52,8 +52,8 @@ const ( 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" @@ -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 @@ -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 } } } @@ -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": [ diff --git a/specification/html/spec_actions.md b/specification/html/spec_actions.md index 56920c6da..6995348fc 100644 --- a/specification/html/spec_actions.md +++ b/specification/html/spec_actions.md @@ -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 | 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 @@ -222,6 +223,11 @@ following file extensions are recognized and will be run on the version of corre ruby Latest Ruby language runtime. + + .rs + rust + Latest Rust language runtime. + diff --git a/tests/src/integration/runtimetests/manifest.yaml b/tests/src/integration/runtimetests/manifest.yaml index 7cbf18957..c2084a007 100644 --- a/tests/src/integration/runtimetests/manifest.yaml +++ b/tests/src/integration/runtimetests/manifest.yaml @@ -150,6 +150,8 @@ 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: @@ -157,6 +159,22 @@ packages: 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: diff --git a/tests/src/integration/runtimetests/src/helloCargo.zip b/tests/src/integration/runtimetests/src/helloCargo.zip new file mode 100644 index 0000000000000000000000000000000000000000..53658a9fce9beee9a0ea480f705c9888644673f4 GIT binary patch literal 746 zcmWIWW@Zs#U|`^2a4ilAn)czxrWPP?GZ1qz$S^o37NzIwmE`BA<`|5*cy*Zn5_wIM;KZYJc-;VG$xmhKAT{<;J zrSt0agN!R}69eajzhKi9f2(hFBWB*;q>|SM-xc{T={U$Pe(n9_n`V$JY zifu5wa;i=Budd9VsN$^`1Qr$E5$=sTbku#?;lD*UcqgnrzB6zt-)f!jI~LzIv1TX_AcgT@7i*V&qFWv5R1ukb9rdh#(-=D!_3+*e90os%}} z*(%Y}J9koF8gng_nDcvz>&~6}=IM-=-7jri$1NVZxXb$odw@41lN>XyR3iaQI}8lK zz-L&}2x1|pAy!BlLJN0f^Dtu%*}M}#^N`~bXdWmoG0bCS1KG?3gbRSQ2{08fFaQ9M Co)l>S literal 0 HcmV?d00001 diff --git a/tests/src/integration/runtimetests/src/lib.rs b/tests/src/integration/runtimetests/src/lib.rs new file mode 100644 index 000000000..83598f8af --- /dev/null +++ b/tests/src/integration/runtimetests/src/lib.rs @@ -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 { + let input: Input = serde_json::from_value(args)?; + let output = Output { + greeting: format!("Hello, {}", input.name), + }; + serde_json::to_value(output) +}