patch structure init with integration test
This commit is contained in:
parent
0d4a1a80b2
commit
a41dc74567
1
VERSION-openeuler
Normal file
1
VERSION-openeuler
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.1.2-1
|
||||||
@ -2,14 +2,20 @@
|
|||||||
|
|
||||||
Name: WasmEngine
|
Name: WasmEngine
|
||||||
Version: v0.1.2
|
Version: v0.1.2
|
||||||
Release: 2
|
Release: 3
|
||||||
Summary: WasmEngine is a webassembly function engine, which provides high concurrency and sandbox security.
|
Summary: WasmEngine is a webassembly function engine, which provides high concurrency and sandbox security.
|
||||||
|
|
||||||
License: MulanPSL-2.0
|
License: MulanPSL-2.0
|
||||||
URL: https://gitee.com/openeuler/WasmEngine
|
URL: https://gitee.com/openeuler/WasmEngine
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: %{name}-%{version}.tar.gz
|
||||||
|
Source1: git-commit
|
||||||
|
Source2: VERSION-openeuler
|
||||||
|
Source3: apply-patches
|
||||||
|
Source4: gen-version.sh
|
||||||
|
Source5: series.conf
|
||||||
|
Source6: patch.tar.gz
|
||||||
|
|
||||||
BuildRequires: rust,cargo,rust-packaging
|
BuildRequires: rust,cargo,rust-packaging,git
|
||||||
BuildRequires: gcc,dtc,openssl-devel
|
BuildRequires: gcc,dtc,openssl-devel
|
||||||
|
|
||||||
%description
|
%description
|
||||||
@ -17,9 +23,16 @@ Based on Rust programming language, WasmEngine is a webassembly function engine,
|
|||||||
Summary: %{summary}
|
Summary: %{summary}
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -p1
|
cp %{SOURCE0} .
|
||||||
|
cp %{SOURCE1} .
|
||||||
|
cp %{SOURCE2} .
|
||||||
|
cp %{SOURCE3} .
|
||||||
|
cp %{SOURCE4} .
|
||||||
|
cp %{SOURCE5} .
|
||||||
|
cp %{SOURCE6} .
|
||||||
|
|
||||||
%build
|
%build
|
||||||
|
sh ./apply-patches
|
||||||
rm -f build.rs
|
rm -f build.rs
|
||||||
|
|
||||||
mkdir -p .cargo
|
mkdir -p .cargo
|
||||||
@ -47,6 +60,12 @@ rm -rf %{buildroot}
|
|||||||
%attr(550,root,root) %{_bindir}/wasm_engine
|
%attr(550,root,root) %{_bindir}/wasm_engine
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Aug 08 2022 jiangpengfei <jiangpengfei9@huawei.com> - v0.1.2-3
|
||||||
|
- Type: bugfix
|
||||||
|
- CVE: NA
|
||||||
|
- SUG: restart
|
||||||
|
- DESC: patch structure init, sync upstream patches
|
||||||
|
|
||||||
* Mon Aug 08 2022 xingweizheng <xingweizheng@huawei.com> - v0.1.2-2
|
* Mon Aug 08 2022 xingweizheng <xingweizheng@huawei.com> - v0.1.2-2
|
||||||
- Type: requirement
|
- Type: requirement
|
||||||
- CVE: NA
|
- CVE: NA
|
||||||
|
|||||||
38
apply-patches
Executable file
38
apply-patches
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved.
|
||||||
|
# Description: This shell script is used to apply patches for the project
|
||||||
|
# Author: lixiang172@huawei.com
|
||||||
|
# Create: 2020-08-21
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
pkg=WasmEngine
|
||||||
|
cwd=${PWD}
|
||||||
|
src=${cwd}/${pkg}
|
||||||
|
tar_file=WasmEngine-v"$(awk -F"-" '{print $1}' < VERSION-openeuler)".tar.gz
|
||||||
|
|
||||||
|
mkdir ${src} && tar -zxvf "${tar_file}" -C ${src} --strip-components 1
|
||||||
|
if [ ! -d patch ]; then
|
||||||
|
tar -zxvf patch.tar.gz
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "${src}"
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git config user.name 'build'
|
||||||
|
git config user.email 'build@obs.com'
|
||||||
|
git commit -m 'init build'
|
||||||
|
cd "${cwd}"
|
||||||
|
|
||||||
|
series=${cwd}/series.conf
|
||||||
|
while IPF= read -r line; do
|
||||||
|
if [[ "${line}" =~ ^patch* ]]; then
|
||||||
|
echo "git apply ${cwd}/${line}"
|
||||||
|
cd "${src}" && git apply "${cwd}/${line}"
|
||||||
|
fi
|
||||||
|
done <"${series}"
|
||||||
|
|
||||||
|
cd "${cwd}"
|
||||||
|
|
||||||
|
cp -rf "${src}"/* .
|
||||||
|
cp -f VERSION-openeuler VERSION
|
||||||
91
gen-version.sh
Executable file
91
gen-version.sh
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
###################################################################################################
|
||||||
|
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
# iSula-Kits licensed under the Mulan PSL v2.
|
||||||
|
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
# You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
# http://license.coscl.org.cn/MulanPSL2
|
||||||
|
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
# PURPOSE.
|
||||||
|
# See the Mulan PSL v2 for more details.
|
||||||
|
# Author: Xiang Li
|
||||||
|
# Create: 2020-05-18
|
||||||
|
# Description: This script used for update isula-build version and release. Enjoy and cherrs
|
||||||
|
###################################################################################################
|
||||||
|
|
||||||
|
# Basic info
|
||||||
|
top_dir=$(git rev-parse --show-toplevel)
|
||||||
|
version_file="${top_dir}/VERSION-openeuler"
|
||||||
|
spec_file="${top_dir}/isula-build.spec"
|
||||||
|
commit_file=${top_dir}/git-commit
|
||||||
|
color=$(tput setaf 2) # red
|
||||||
|
color_reset=$(tput sgr0)
|
||||||
|
|
||||||
|
# Commit ID
|
||||||
|
changeID=`git log -1 | grep Change-Id | awk '{print $2}' | head -c 40`
|
||||||
|
if [ "${changeID}" = "" ]; then
|
||||||
|
changeID=`date | sha256sum | head -c 40`
|
||||||
|
fi
|
||||||
|
echo "${changeID}" > ${top_dir}/git-commit
|
||||||
|
commit_id=$(cat ${commit_file}|cut -c1-7)
|
||||||
|
|
||||||
|
old_all=$(cat "${version_file}")
|
||||||
|
old_version=$(cat "${version_file}" | awk -F"-" '{print $1}')
|
||||||
|
old_release=$(cat "${version_file}" | awk -F"-" '{print $2}')
|
||||||
|
major_old_version=$(echo "${old_version}" | awk -F "." '{print $1}')
|
||||||
|
minor_old_version=$(echo "${old_version}" | awk -F "." '{print $2}')
|
||||||
|
revision_old_version=$(echo "${old_version}" | awk -F "." '{print $3}')
|
||||||
|
|
||||||
|
|
||||||
|
# Read user input
|
||||||
|
read -rp "update version: Major(1), Minor(2), Revision(3), Release(4) [1/2/3/4]: " input
|
||||||
|
case ${input} in
|
||||||
|
1)
|
||||||
|
major_old_version=$((major_old_version + 1))
|
||||||
|
minor_old_version="0"
|
||||||
|
revision_old_version="0"
|
||||||
|
new_release_num="1"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
minor_old_version=$((minor_old_version + 1))
|
||||||
|
revision_old_version="0"
|
||||||
|
new_release_num="1"
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
revision_old_version=$((revision_old_version + 1))
|
||||||
|
new_release_num="1"
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
new_release_num=$((old_release + 1))
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Wrong input, Version Not modified: ${old_version}"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
author=$(git config user.name)
|
||||||
|
email=$(git config user.email)
|
||||||
|
|
||||||
|
# VERSION format:
|
||||||
|
# Major.Minor.Revision
|
||||||
|
new_version=${major_old_version}.${minor_old_version}.${revision_old_version}
|
||||||
|
new_release="${new_release_num}"
|
||||||
|
new_all=${new_version}-${new_release_num}
|
||||||
|
new_changelog=$(cat << EOF
|
||||||
|
* $(date '+%a %b %d %Y') $author <$email> - $new_all\n- Type:\n- CVE:\n- SUG:\n- DESC:\n
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Replace version and release for spec and VERSION files
|
||||||
|
sed -i -e "s/^Version: .*$/Version: ${new_version}/g" "${spec_file}"
|
||||||
|
sed -i -e "s/^Release: .*$/Release: ${new_release}/g" "${spec_file}"
|
||||||
|
sed -i -e "/\%changelog/a$new_changelog" "${spec_file}"
|
||||||
|
echo "${new_all}" > "${version_file}"
|
||||||
|
|
||||||
|
if [[ "${old_all}" != "${new_all}" ]]; then
|
||||||
|
printf 'Version: %s -> %s\n' "${old_all}" "${color}${new_all}${color_reset}"
|
||||||
|
fi
|
||||||
|
|
||||||
1
git-commit
Normal file
1
git-commit
Normal file
@ -0,0 +1 @@
|
|||||||
|
72af9798974345d587fe8f3ea2c121adc1696651
|
||||||
667
patch/0001-add-experiments-to-tar.patch
Normal file
667
patch/0001-add-experiments-to-tar.patch
Normal file
@ -0,0 +1,667 @@
|
|||||||
|
From 6d7bed672d69a3fb60d98ff84182ff5eceb0c452 Mon Sep 17 00:00:00 2001
|
||||||
|
From: build <build@obs.com>
|
||||||
|
Date: Tue, 9 Aug 2022 19:06:59 +0800
|
||||||
|
Subject: [PATCH] add experiments to tar
|
||||||
|
|
||||||
|
---
|
||||||
|
experiments/application/add_one/Cargo.lock | 7 +
|
||||||
|
experiments/application/add_one/Cargo.toml | 11 ++
|
||||||
|
experiments/application/add_one/src/lib.rs | 4 +
|
||||||
|
.../authentication-wasi/Cargo.lock | 74 +++++++++
|
||||||
|
.../authentication-wasi/Cargo.toml | 10 ++
|
||||||
|
.../authentication-wasi/src/main.rs | 68 ++++++++
|
||||||
|
.../application/authentication/Cargo.lock | 154 ++++++++++++++++++
|
||||||
|
.../application/authentication/Cargo.toml | 18 ++
|
||||||
|
.../application/authentication/src/lib.rs | 91 +++++++++++
|
||||||
|
.../application/echo-string/Cargo.lock | 7 +
|
||||||
|
.../application/echo-string/Cargo.toml | 11 ++
|
||||||
|
.../application/echo-string/src/lib.rs | 5 +
|
||||||
|
experiments/application/fibonacci/Cargo.lock | 7 +
|
||||||
|
experiments/application/fibonacci/Cargo.toml | 8 +
|
||||||
|
experiments/application/fibonacci/src/main.rs | 18 ++
|
||||||
|
experiments/application/hello/Cargo.lock | 7 +
|
||||||
|
experiments/application/hello/Cargo.toml | 8 +
|
||||||
|
experiments/application/hello/src/main.rs | 3 +
|
||||||
|
18 files changed, 511 insertions(+)
|
||||||
|
create mode 100644 experiments/application/add_one/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/add_one/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/add_one/src/lib.rs
|
||||||
|
create mode 100644 experiments/application/authentication-wasi/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/authentication-wasi/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/authentication-wasi/src/main.rs
|
||||||
|
create mode 100644 experiments/application/authentication/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/authentication/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/authentication/src/lib.rs
|
||||||
|
create mode 100644 experiments/application/echo-string/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/echo-string/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/echo-string/src/lib.rs
|
||||||
|
create mode 100644 experiments/application/fibonacci/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/fibonacci/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/fibonacci/src/main.rs
|
||||||
|
create mode 100644 experiments/application/hello/Cargo.lock
|
||||||
|
create mode 100644 experiments/application/hello/Cargo.toml
|
||||||
|
create mode 100644 experiments/application/hello/src/main.rs
|
||||||
|
|
||||||
|
diff --git a/experiments/application/add_one/Cargo.lock b/experiments/application/add_one/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..f33516b5
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/add_one/Cargo.lock
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "authentication"
|
||||||
|
+version = "0.1.0"
|
||||||
|
diff --git a/experiments/application/add_one/Cargo.toml b/experiments/application/add_one/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..e218947f
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/add_one/Cargo.toml
|
||||||
|
@@ -0,0 +1,11 @@
|
||||||
|
+[package]
|
||||||
|
+name = "authentication"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
+
|
||||||
|
+[lib]
|
||||||
|
+crate-type = ["cdylib"]
|
||||||
|
diff --git a/experiments/application/add_one/src/lib.rs b/experiments/application/add_one/src/lib.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..da5a5692
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/add_one/src/lib.rs
|
||||||
|
@@ -0,0 +1,4 @@
|
||||||
|
+#[no_mangle]
|
||||||
|
+pub extern "C" fn add_one(x: i32) -> i32 {
|
||||||
|
+ x + 1
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/experiments/application/authentication-wasi/Cargo.lock b/experiments/application/authentication-wasi/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..7aa6e8f4
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication-wasi/Cargo.lock
|
||||||
|
@@ -0,0 +1,74 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "another_json_minimal"
|
||||||
|
+version = "0.0.2"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "77ba8341e1396c8a379f62de1b47f31256f2fe0846f5f95e9c60014d2102d9bd"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "authentication-wasi"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+dependencies = [
|
||||||
|
+ "another_json_minimal",
|
||||||
|
+ "md-5",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "block-buffer"
|
||||||
|
+version = "0.9.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
|
||||||
|
+dependencies = [
|
||||||
|
+ "generic-array",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "digest"
|
||||||
|
+version = "0.9.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||||
|
+dependencies = [
|
||||||
|
+ "generic-array",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "generic-array"
|
||||||
|
+version = "0.14.4"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
|
||||||
|
+dependencies = [
|
||||||
|
+ "typenum",
|
||||||
|
+ "version_check",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "md-5"
|
||||||
|
+version = "0.9.1"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
|
||||||
|
+dependencies = [
|
||||||
|
+ "block-buffer",
|
||||||
|
+ "digest",
|
||||||
|
+ "opaque-debug",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "opaque-debug"
|
||||||
|
+version = "0.3.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "typenum"
|
||||||
|
+version = "1.14.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "version_check"
|
||||||
|
+version = "0.9.3"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||||
|
diff --git a/experiments/application/authentication-wasi/Cargo.toml b/experiments/application/authentication-wasi/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..b862de82
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication-wasi/Cargo.toml
|
||||||
|
@@ -0,0 +1,10 @@
|
||||||
|
+[package]
|
||||||
|
+name = "authentication-wasi"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
+md-5 = { version="0.9", default-features = false }
|
||||||
|
+another_json_minimal = "0.0.2"
|
||||||
|
diff --git a/experiments/application/authentication-wasi/src/main.rs b/experiments/application/authentication-wasi/src/main.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..df00eae3
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication-wasi/src/main.rs
|
||||||
|
@@ -0,0 +1,68 @@
|
||||||
|
+use another_json_minimal::Json;
|
||||||
|
+use md5::{Digest, Md5};
|
||||||
|
+use std::{env, fmt::Write};
|
||||||
|
+
|
||||||
|
+#[derive(Default)]
|
||||||
|
+struct Response {
|
||||||
|
+ status: String,
|
||||||
|
+ body: String,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+fn main() {
|
||||||
|
+ let args: Vec<String> = env::args().collect();
|
||||||
|
+ if args.len() != 3 {
|
||||||
|
+ eprintln!("usage: authentication <URI> <BODY> <SECRET>");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ let arg_uri = &args[0];
|
||||||
|
+ let arg_body = &args[1];
|
||||||
|
+ let arg_secret = &args[2];
|
||||||
|
+
|
||||||
|
+ let arg_func = "argfunc";
|
||||||
|
+ let content = format!("{}#{}#{}", arg_uri, arg_body, arg_func);
|
||||||
|
+
|
||||||
|
+ // create a Md5 hasher instance
|
||||||
|
+ let mut hasher = Md5::new();
|
||||||
|
+ // process input message
|
||||||
|
+ hasher.update(content.as_bytes());
|
||||||
|
+ let result = hasher.finalize();
|
||||||
|
+
|
||||||
|
+ let slice = result.as_slice();
|
||||||
|
+ let mut hash = String::with_capacity(slice.len() * 2);
|
||||||
|
+ for &b in slice {
|
||||||
|
+ write!(&mut hash, "{:02x}", b).unwrap();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ let mut r: Response = Response::default();
|
||||||
|
+ let html: String;
|
||||||
|
+ if &hash == arg_secret {
|
||||||
|
+ r.status = "200".to_string();
|
||||||
|
+ html = "<html><h1>Auth Pass!</h1><p>hash ".to_owned() + &hash + "</p></html>";
|
||||||
|
+ r.body = html;
|
||||||
|
+ } else {
|
||||||
|
+ r.status = "403".to_string();
|
||||||
|
+ html = "<html><h1>Auth Forbidden!</h1><p>hash ".to_owned()
|
||||||
|
+ + &hash
|
||||||
|
+ + " secret "
|
||||||
|
+ + &arg_secret
|
||||||
|
+ + "</p></html>";
|
||||||
|
+ r.body = html;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //we use complicated another_json_minimal temporary
|
||||||
|
+ let mut json = Json::new();
|
||||||
|
+ let status = Json::OBJECT {
|
||||||
|
+ name: String::from("status"),
|
||||||
|
+ value: Box::new(Json::STRING(String::from(&r.status))),
|
||||||
|
+ };
|
||||||
|
+ json.add(status);
|
||||||
|
+ let body = Json::OBJECT {
|
||||||
|
+ name: String::from("body"),
|
||||||
|
+ value: Box::new(Json::STRING(String::from(&r.body))),
|
||||||
|
+ };
|
||||||
|
+ json.add(body);
|
||||||
|
+ let serialized = json.print();
|
||||||
|
+
|
||||||
|
+ println!("{}", serialized);
|
||||||
|
+}
|
||||||
|
diff --git a/experiments/application/authentication/Cargo.lock b/experiments/application/authentication/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..9d96c7b1
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication/Cargo.lock
|
||||||
|
@@ -0,0 +1,154 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "another_json_minimal"
|
||||||
|
+version = "0.0.2"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "77ba8341e1396c8a379f62de1b47f31256f2fe0846f5f95e9c60014d2102d9bd"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "authentication"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+dependencies = [
|
||||||
|
+ "another_json_minimal",
|
||||||
|
+ "md-5",
|
||||||
|
+ "serde",
|
||||||
|
+ "serde_json",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "block-buffer"
|
||||||
|
+version = "0.9.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
|
||||||
|
+dependencies = [
|
||||||
|
+ "generic-array",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "digest"
|
||||||
|
+version = "0.9.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||||
|
+dependencies = [
|
||||||
|
+ "generic-array",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "generic-array"
|
||||||
|
+version = "0.14.4"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
|
||||||
|
+dependencies = [
|
||||||
|
+ "typenum",
|
||||||
|
+ "version_check",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "itoa"
|
||||||
|
+version = "1.0.1"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "md-5"
|
||||||
|
+version = "0.9.1"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
|
||||||
|
+dependencies = [
|
||||||
|
+ "block-buffer",
|
||||||
|
+ "digest",
|
||||||
|
+ "opaque-debug",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "opaque-debug"
|
||||||
|
+version = "0.3.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "proc-macro2"
|
||||||
|
+version = "1.0.34"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
|
||||||
|
+dependencies = [
|
||||||
|
+ "unicode-xid",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "quote"
|
||||||
|
+version = "1.0.10"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||||
|
+dependencies = [
|
||||||
|
+ "proc-macro2",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "ryu"
|
||||||
|
+version = "1.0.9"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "serde"
|
||||||
|
+version = "1.0.132"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
|
||||||
|
+dependencies = [
|
||||||
|
+ "serde_derive",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "serde_derive"
|
||||||
|
+version = "1.0.132"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
|
||||||
|
+dependencies = [
|
||||||
|
+ "proc-macro2",
|
||||||
|
+ "quote",
|
||||||
|
+ "syn",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "serde_json"
|
||||||
|
+version = "1.0.73"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
|
||||||
|
+dependencies = [
|
||||||
|
+ "itoa",
|
||||||
|
+ "ryu",
|
||||||
|
+ "serde",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "syn"
|
||||||
|
+version = "1.0.82"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
|
||||||
|
+dependencies = [
|
||||||
|
+ "proc-macro2",
|
||||||
|
+ "quote",
|
||||||
|
+ "unicode-xid",
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "typenum"
|
||||||
|
+version = "1.14.0"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "unicode-xid"
|
||||||
|
+version = "0.2.2"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "version_check"
|
||||||
|
+version = "0.9.3"
|
||||||
|
+source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
+checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||||
|
diff --git a/experiments/application/authentication/Cargo.toml b/experiments/application/authentication/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..47729792
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication/Cargo.toml
|
||||||
|
@@ -0,0 +1,18 @@
|
||||||
|
+[package]
|
||||||
|
+name = "authentication"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
+md-5 = { version="0.9", default-features = false }
|
||||||
|
+another_json_minimal = "0.0.2"
|
||||||
|
+
|
||||||
|
+[lib]
|
||||||
|
+crate-type = ["cdylib"]
|
||||||
|
+
|
||||||
|
+[dev-dependencies]
|
||||||
|
+serde = { version = "1.0", features = ["derive"] }
|
||||||
|
+serde_json = "1.0"
|
||||||
|
+
|
||||||
|
diff --git a/experiments/application/authentication/src/lib.rs b/experiments/application/authentication/src/lib.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..0aa5d980
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/authentication/src/lib.rs
|
||||||
|
@@ -0,0 +1,91 @@
|
||||||
|
+use std::fmt::Write;
|
||||||
|
+
|
||||||
|
+use another_json_minimal::Json;
|
||||||
|
+use md5::{Digest, Md5};
|
||||||
|
+
|
||||||
|
+#[derive(Default)]
|
||||||
|
+struct Response {
|
||||||
|
+ status: String,
|
||||||
|
+ body: String,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[no_mangle]
|
||||||
|
+pub fn authentication(data: &str) -> (*mut u8, usize) {
|
||||||
|
+ // fulfill data p
|
||||||
|
+ let arg_func = "argfunc";
|
||||||
|
+ let json = match Json::parse(data.as_bytes()) {
|
||||||
|
+ Ok(json) => json,
|
||||||
|
+ Err((position, message)) => {
|
||||||
|
+ panic!("`{}` at position `{}`!!!", position, message);
|
||||||
|
+ }
|
||||||
|
+ };
|
||||||
|
+ let arg_uri = json.get("arg_uri").unwrap().print();
|
||||||
|
+ let arg_body = json.get("arg_body").unwrap().print();
|
||||||
|
+ let arg_secret = json.get("arg_secret").unwrap().print();
|
||||||
|
+
|
||||||
|
+ let content = format!("{}#{}#{}", arg_uri, arg_body, arg_func);
|
||||||
|
+
|
||||||
|
+ // create a Md5 hasher instance
|
||||||
|
+ let mut hasher = Md5::new();
|
||||||
|
+ // process input message
|
||||||
|
+ hasher.update(content.as_bytes());
|
||||||
|
+ let result = hasher.finalize();
|
||||||
|
+
|
||||||
|
+ let slice = result.as_slice();
|
||||||
|
+ let mut hash = String::with_capacity(slice.len() * 2);
|
||||||
|
+ for &b in slice {
|
||||||
|
+ write!(&mut hash, "{:02x}", b).unwrap();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ let mut r: Response = Response::default();
|
||||||
|
+ let html: String;
|
||||||
|
+ if hash == arg_secret {
|
||||||
|
+ r.status = "200".to_string();
|
||||||
|
+ html = "<html><h1>Auth Pass!</h1><p>hash ".to_owned() + &hash + "</p></html>";
|
||||||
|
+ r.body = html;
|
||||||
|
+ } else {
|
||||||
|
+ r.status = "403".to_string();
|
||||||
|
+ html = "<html><h1>Auth Forbidden!</h1><p>hash ".to_owned()
|
||||||
|
+ + &hash
|
||||||
|
+ + " secret "
|
||||||
|
+ + &arg_secret
|
||||||
|
+ + "</p></html>";
|
||||||
|
+ r.body = html;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //we use complicated another_json_minimal temporary
|
||||||
|
+ let mut json = Json::new();
|
||||||
|
+ let status = Json::OBJECT {
|
||||||
|
+ name: String::from("status"),
|
||||||
|
+ value: Box::new(Json::STRING(String::from(&r.status))),
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ json.add(status);
|
||||||
|
+ let body = Json::OBJECT {
|
||||||
|
+ name: String::from("body"),
|
||||||
|
+ value: Box::new(Json::STRING(String::from(&r.body))),
|
||||||
|
+ };
|
||||||
|
+ json.add(body);
|
||||||
|
+
|
||||||
|
+ let mut serialized = json.print();
|
||||||
|
+ (serialized.as_mut_ptr(), serialized.len())
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn test_authentication() {
|
||||||
|
+ use serde::{Deserialize, Serialize};
|
||||||
|
+ #[derive(Deserialize, Serialize, Default)]
|
||||||
|
+ struct Data {
|
||||||
|
+ arg_uri: String,
|
||||||
|
+ arg_body: String,
|
||||||
|
+ arg_secret: String,
|
||||||
|
+ }
|
||||||
|
+ let p: Data = Data {
|
||||||
|
+ arg_uri: "uri".to_string(),
|
||||||
|
+ arg_body: "body".to_string(),
|
||||||
|
+ arg_secret: "secrect".to_string(),
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ let serialized = serde_json::to_string(&p).unwrap();
|
||||||
|
+ let (_p, _l) = authentication(&serialized);
|
||||||
|
+}
|
||||||
|
diff --git a/experiments/application/echo-string/Cargo.lock b/experiments/application/echo-string/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..18266ede
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/echo-string/Cargo.lock
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "echo-string"
|
||||||
|
+version = "0.1.0"
|
||||||
|
diff --git a/experiments/application/echo-string/Cargo.toml b/experiments/application/echo-string/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..51c4cfa7
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/echo-string/Cargo.toml
|
||||||
|
@@ -0,0 +1,11 @@
|
||||||
|
+[package]
|
||||||
|
+name = "echo-string"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
+
|
||||||
|
+[lib]
|
||||||
|
+crate-type = ["cdylib"]
|
||||||
|
diff --git a/experiments/application/echo-string/src/lib.rs b/experiments/application/echo-string/src/lib.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..56f38f7e
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/echo-string/src/lib.rs
|
||||||
|
@@ -0,0 +1,5 @@
|
||||||
|
+#[no_mangle]
|
||||||
|
+pub fn echo_string(input: &str) -> (*const u8, usize) {
|
||||||
|
+ let r = input.to_owned() + "b";
|
||||||
|
+ (r.as_ptr(), r.len())
|
||||||
|
+}
|
||||||
|
diff --git a/experiments/application/fibonacci/Cargo.lock b/experiments/application/fibonacci/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..06a56e63
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/fibonacci/Cargo.lock
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "fibonacci"
|
||||||
|
+version = "0.1.0"
|
||||||
|
diff --git a/experiments/application/fibonacci/Cargo.toml b/experiments/application/fibonacci/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..9cd048ef
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/fibonacci/Cargo.toml
|
||||||
|
@@ -0,0 +1,8 @@
|
||||||
|
+[package]
|
||||||
|
+name = "fibonacci"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
diff --git a/experiments/application/fibonacci/src/main.rs b/experiments/application/fibonacci/src/main.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..4c6c79fb
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/fibonacci/src/main.rs
|
||||||
|
@@ -0,0 +1,18 @@
|
||||||
|
+use std::env;
|
||||||
|
+
|
||||||
|
+fn fib(n: u64) -> u64 {
|
||||||
|
+ if n <= 1 {
|
||||||
|
+ return n;
|
||||||
|
+ }
|
||||||
|
+ fib(n - 1) + fib(n - 2)
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+fn main() {
|
||||||
|
+ let args: Vec<String> = env::args().collect();
|
||||||
|
+
|
||||||
|
+ if args.len() != 1 {
|
||||||
|
+ eprintln!("only single parameter is needed");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ println!("{}", fib(args[0].parse::<u64>().unwrap()))
|
||||||
|
+}
|
||||||
|
diff --git a/experiments/application/hello/Cargo.lock b/experiments/application/hello/Cargo.lock
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..c3aedd77
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/hello/Cargo.lock
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+# This file is automatically @generated by Cargo.
|
||||||
|
+# It is not intended for manual editing.
|
||||||
|
+version = 3
|
||||||
|
+
|
||||||
|
+[[package]]
|
||||||
|
+name = "hello"
|
||||||
|
+version = "0.1.0"
|
||||||
|
diff --git a/experiments/application/hello/Cargo.toml b/experiments/application/hello/Cargo.toml
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..fb1ec2c9
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/hello/Cargo.toml
|
||||||
|
@@ -0,0 +1,8 @@
|
||||||
|
+[package]
|
||||||
|
+name = "hello"
|
||||||
|
+version = "0.1.0"
|
||||||
|
+edition = "2021"
|
||||||
|
+
|
||||||
|
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
+
|
||||||
|
+[dependencies]
|
||||||
|
diff --git a/experiments/application/hello/src/main.rs b/experiments/application/hello/src/main.rs
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..b3dbf1ae
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/experiments/application/hello/src/main.rs
|
||||||
|
@@ -0,0 +1,3 @@
|
||||||
|
+fn main() {
|
||||||
|
+ println!("Hello, Budda!");
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
1871
patch/0002-add-another_json_minimal-to-vendor.patch
Normal file
1871
patch/0002-add-another_json_minimal-to-vendor.patch
Normal file
File diff suppressed because it is too large
Load Diff
116
patch/0003-remove-unused-code-and-comments.patch
Normal file
116
patch/0003-remove-unused-code-and-comments.patch
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
From ed978016ca2d2619e5473cf998515e606d1324d8 Mon Sep 17 00:00:00 2001
|
||||||
|
From: meilier <xingweizheng@huawei.com>
|
||||||
|
Date: Fri, 5 Aug 2022 15:05:42 +0800
|
||||||
|
Subject: [PATCH 1/6] remove unused code and comments
|
||||||
|
|
||||||
|
---
|
||||||
|
src/function_store/module_store.rs | 17 +----------------
|
||||||
|
src/main.rs | 14 --------------
|
||||||
|
src/wrapper/environment.rs | 7 ++-----
|
||||||
|
3 files changed, 3 insertions(+), 35 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/function_store/module_store.rs b/src/function_store/module_store.rs
|
||||||
|
index cac3027..12616a6 100644
|
||||||
|
--- a/src/function_store/module_store.rs
|
||||||
|
+++ b/src/function_store/module_store.rs
|
||||||
|
@@ -1,8 +1,3 @@
|
||||||
|
-/*!
|
||||||
|
-Registries allow you to define "well-known" modules in the &environment that can be looked up by
|
||||||
|
-name and version.
|
||||||
|
-*/
|
||||||
|
-
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
use std::{collections::HashMap, sync::Arc, sync::RwLock};
|
||||||
|
use tracing::info;
|
||||||
|
@@ -24,10 +19,7 @@ impl ModuleStore {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- /// Insert module into the registry under a specific name, version and wasi capabilites.
|
||||||
|
- ///
|
||||||
|
- /// The version needs to be a correct semver string (e.g "1.2.3-alpha3") or the insertion will
|
||||||
|
- /// fail. If the exact same version and name exists it will be overwritten.
|
||||||
|
+ /// Insert module into the ModuleStore under a specific name, module and wasi capabilites.
|
||||||
|
pub fn insert(&self, name: &str, module: Module, wasi_cap: bool) -> Result<()> {
|
||||||
|
let mut writer = self.module_store.write().unwrap();
|
||||||
|
|
||||||
|
@@ -44,9 +36,6 @@ impl ModuleStore {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
- /// Remove module under name & version from registry
|
||||||
|
- ///
|
||||||
|
- /// Exact version matching is used for lookup.
|
||||||
|
pub fn remove(&self, name: &str) -> Result<()> {
|
||||||
|
let mut writer = self.module_store.write().unwrap();
|
||||||
|
|
||||||
|
@@ -113,8 +102,4 @@ impl ModuleEntry {
|
||||||
|
pub fn capability(&self) -> bool {
|
||||||
|
self.wasi_cap
|
||||||
|
}
|
||||||
|
-
|
||||||
|
- fn all(&self) -> ModuleEntry {
|
||||||
|
- self.clone()
|
||||||
|
- }
|
||||||
|
}
|
||||||
|
diff --git a/src/main.rs b/src/main.rs
|
||||||
|
index c4e7ec0..450910d 100644
|
||||||
|
--- a/src/main.rs
|
||||||
|
+++ b/src/main.rs
|
||||||
|
@@ -1,5 +1,4 @@
|
||||||
|
use anyhow::Context;
|
||||||
|
-use clap::Parser;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::{collections::HashMap, error::Error};
|
||||||
|
use tracing::{info, instrument, Level};
|
||||||
|
@@ -23,22 +22,9 @@ lazy_static::lazy_static! {
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
-#[derive(Parser, Debug)]
|
||||||
|
-#[clap(about, version, author)]
|
||||||
|
-struct Args {
|
||||||
|
- /// Log level used in wasm-engine, TRACE: 0, DEBUG: 1, INFO: 2(Default), WARN: 3, ERROR: 4
|
||||||
|
- #[clap(short, long, default_value = "2")]
|
||||||
|
- log_level: u8,
|
||||||
|
-
|
||||||
|
- /// dir that contains preload apps
|
||||||
|
- #[clap(short, long)]
|
||||||
|
- preload_apps: Option<String>,
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
#[instrument]
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||||
|
- let args = Args::parse();
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(EnvFilter::from_default_env())
|
||||||
|
.try_init()?;
|
||||||
|
diff --git a/src/wrapper/environment.rs b/src/wrapper/environment.rs
|
||||||
|
index b7ea873..bb9bde7 100644
|
||||||
|
--- a/src/wrapper/environment.rs
|
||||||
|
+++ b/src/wrapper/environment.rs
|
||||||
|
@@ -12,10 +12,7 @@ pub const UNIT_OF_COMPUTE_IN_INSTRUCTIONS: u64 = 100_000;
|
||||||
|
/// Environments let us set limits on instances:
|
||||||
|
/// * Memory limits
|
||||||
|
/// * Compute limits
|
||||||
|
-/// * Access to host functions
|
||||||
|
-///
|
||||||
|
-/// They also define the set of plugins. Plugins can be used to modify loaded Wasm modules.
|
||||||
|
-/// Plugins are WIP and not well documented.
|
||||||
|
+/// * Access to modules
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Environment {
|
||||||
|
runtime: WasmtimeRuntime,
|
||||||
|
@@ -36,7 +33,7 @@ impl Environment {
|
||||||
|
&self.runtime
|
||||||
|
}
|
||||||
|
|
||||||
|
- pub fn registry(&self) -> &ModuleStore {
|
||||||
|
+ pub fn store(&self) -> &ModuleStore {
|
||||||
|
&self.store
|
||||||
|
}
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
56
patch/0004-pull_wasm-return-result-do-not-panic.patch
Normal file
56
patch/0004-pull_wasm-return-result-do-not-panic.patch
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
From 0ce3f371a26deaf1c29a71af2fc7cfb8e5c25451 Mon Sep 17 00:00:00 2001
|
||||||
|
From: meilier <xingweizheng@huawei.com>
|
||||||
|
Date: Fri, 5 Aug 2022 00:59:24 +0800
|
||||||
|
Subject: [PATCH 2/6] pull_wasm return result, do not panic
|
||||||
|
|
||||||
|
---
|
||||||
|
src/function_store/pull.rs | 12 ++++++++----
|
||||||
|
1 file changed, 8 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/function_store/pull.rs b/src/function_store/pull.rs
|
||||||
|
index 40bbc15..2ba4185 100644
|
||||||
|
--- a/src/function_store/pull.rs
|
||||||
|
+++ b/src/function_store/pull.rs
|
||||||
|
@@ -1,3 +1,4 @@
|
||||||
|
+use anyhow::Result;
|
||||||
|
use flate2::read;
|
||||||
|
use oci_distribution::{manifest, secrets::RegistryAuth, Client, Reference};
|
||||||
|
use tar::Archive;
|
||||||
|
@@ -21,7 +22,7 @@ pub async fn pull_wasm(
|
||||||
|
auth: &RegistryAuth,
|
||||||
|
reference: &Reference,
|
||||||
|
output: &str,
|
||||||
|
-) {
|
||||||
|
+) -> Result<()> {
|
||||||
|
info!(?reference, ?output, "pulling wasm module");
|
||||||
|
|
||||||
|
let image_content = client
|
||||||
|
@@ -31,19 +32,22 @@ pub async fn pull_wasm(
|
||||||
|
vec![manifest::IMAGE_DOCKER_LAYER_GZIP_MEDIA_TYPE],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
- .expect("Cannot pull Wasm module")
|
||||||
|
+ .map_err(|err| anyhow::format_err!("Cannot pull Wasm module {}", err))?
|
||||||
|
.layers
|
||||||
|
.into_iter()
|
||||||
|
.next()
|
||||||
|
.map(|layer| layer.data)
|
||||||
|
- .expect("No data found");
|
||||||
|
+ .ok_or(anyhow::format_err!("No data found"))?;
|
||||||
|
|
||||||
|
// webassembly oci spec definition: https://github.com/solo-io/wasm/spec
|
||||||
|
// for IMAGE_DOCKER_LAYER_GZIP_MEDIA_TYPE, we need to unzip iamge_content
|
||||||
|
// into raw wasm file
|
||||||
|
let gz = read::GzDecoder::new(&image_content[..]);
|
||||||
|
let mut archive = Archive::new(gz);
|
||||||
|
- archive.unpack(output).expect("Cannot write to file");
|
||||||
|
+ archive
|
||||||
|
+ .unpack(output)
|
||||||
|
+ .map_err(|err| anyhow::format_err!("Cannot write to file: {}", err))?;
|
||||||
|
|
||||||
|
info!("Wasm module successfully written to {}", output);
|
||||||
|
+ Ok(())
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
From 3382e85c5be6fcf9bf79bf618eca7672b150543c Mon Sep 17 00:00:00 2001
|
||||||
|
From: meilier <xingweizheng@huawei.com>
|
||||||
|
Date: Fri, 5 Aug 2022 01:00:34 +0800
|
||||||
|
Subject: [PATCH 3/6] wasmengine could pull public https' repository image
|
||||||
|
|
||||||
|
---
|
||||||
|
src/function_store/local_store.rs | 27 ++++++++++++++++++++++++---
|
||||||
|
1 file changed, 24 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/function_store/local_store.rs b/src/function_store/local_store.rs
|
||||||
|
index d68c451..2afcd96 100644
|
||||||
|
--- a/src/function_store/local_store.rs
|
||||||
|
+++ b/src/function_store/local_store.rs
|
||||||
|
@@ -1,5 +1,6 @@
|
||||||
|
use super::pull;
|
||||||
|
use anyhow::{anyhow, Ok, Result};
|
||||||
|
+use oci_distribution::client::ClientConfig;
|
||||||
|
use oci_distribution::{secrets::RegistryAuth, Client, Reference};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
@@ -100,11 +101,13 @@ impl FunctionStore {
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
- let mut client = Client::new(pull::build_client_config(true));
|
||||||
|
- let reference: Reference = image_name.parse().expect("Not a valid image reference");
|
||||||
|
+ let mut client = Client::new(ClientConfig::default());
|
||||||
|
+ let reference: Reference = image_name
|
||||||
|
+ .parse()
|
||||||
|
+ .map_err(|err| anyhow::format_err!("Not a valid image reference: {}", err))?;
|
||||||
|
|
||||||
|
// pull the wasm image into the local func_store_path
|
||||||
|
- pull::pull_wasm(
|
||||||
|
+ let pull_result = pull::pull_wasm(
|
||||||
|
&mut client,
|
||||||
|
&RegistryAuth::Anonymous,
|
||||||
|
&reference,
|
||||||
|
@@ -112,6 +115,24 @@ impl FunctionStore {
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
+ if !pull_result.is_ok() {
|
||||||
|
+ let mut client = Client::new(pull::build_client_config(true));
|
||||||
|
+ pull::pull_wasm(
|
||||||
|
+ &mut client,
|
||||||
|
+ &RegistryAuth::Anonymous,
|
||||||
|
+ &reference,
|
||||||
|
+ func_store_dir.as_str(),
|
||||||
|
+ )
|
||||||
|
+ .await
|
||||||
|
+ .map_err(|err| {
|
||||||
|
+ anyhow::format_err!(
|
||||||
|
+ "Pull image both failed with https auth: {}, and insecure http: {}",
|
||||||
|
+ pull_result.unwrap_err(),
|
||||||
|
+ err
|
||||||
|
+ )
|
||||||
|
+ })?;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
// only one wasm module file should be in the func_store_dir
|
||||||
|
if read_dir(func_store_dir.clone()).unwrap().count() != 1 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
From e47f84d178d3f63b45e84c576b0f690b553f2135 Mon Sep 17 00:00:00 2001
|
||||||
|
From: meilier <xingweizheng@huawei.com>
|
||||||
|
Date: Fri, 5 Aug 2022 01:02:28 +0800
|
||||||
|
Subject: [PATCH 4/6] wasi use json as args for consistent wasm function invoke
|
||||||
|
|
||||||
|
---
|
||||||
|
.../authentication-wasi/src/main.rs | 18 ++++++++++++------
|
||||||
|
src/wrapper/wasmtime_runtime.rs | 10 ++++------
|
||||||
|
2 files changed, 16 insertions(+), 12 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/experiments/application/authentication-wasi/src/main.rs b/experiments/application/authentication-wasi/src/main.rs
|
||||||
|
index df00eae..91b7a87 100644
|
||||||
|
--- a/experiments/application/authentication-wasi/src/main.rs
|
||||||
|
+++ b/experiments/application/authentication-wasi/src/main.rs
|
||||||
|
@@ -10,14 +10,20 @@ struct Response {
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
- if args.len() != 3 {
|
||||||
|
- eprintln!("usage: authentication <URI> <BODY> <SECRET>");
|
||||||
|
+ if args.len() != 1 {
|
||||||
|
+ eprintln!("too many args");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- let arg_uri = &args[0];
|
||||||
|
- let arg_body = &args[1];
|
||||||
|
- let arg_secret = &args[2];
|
||||||
|
+ let json = match Json::parse(&args[0].as_bytes()) {
|
||||||
|
+ Ok(json) => json,
|
||||||
|
+ Err((position, message)) => {
|
||||||
|
+ panic!("`{}` at position `{}`!!!", position, message);
|
||||||
|
+ }
|
||||||
|
+ };
|
||||||
|
+ let arg_uri = json.get("arg_uri").unwrap().print();
|
||||||
|
+ let arg_body = json.get("arg_body").unwrap().print();
|
||||||
|
+ let arg_secret = json.get("arg_secret").unwrap().print();
|
||||||
|
|
||||||
|
let arg_func = "argfunc";
|
||||||
|
let content = format!("{}#{}#{}", arg_uri, arg_body, arg_func);
|
||||||
|
@@ -36,7 +42,7 @@ fn main() {
|
||||||
|
|
||||||
|
let mut r: Response = Response::default();
|
||||||
|
let html: String;
|
||||||
|
- if &hash == arg_secret {
|
||||||
|
+ if hash == arg_secret {
|
||||||
|
r.status = "200".to_string();
|
||||||
|
html = "<html><h1>Auth Pass!</h1><p>hash ".to_owned() + &hash + "</p></html>";
|
||||||
|
r.body = html;
|
||||||
|
diff --git a/src/wrapper/wasmtime_runtime.rs b/src/wrapper/wasmtime_runtime.rs
|
||||||
|
index 415dd57..6d5e9cc 100644
|
||||||
|
--- a/src/wrapper/wasmtime_runtime.rs
|
||||||
|
+++ b/src/wrapper/wasmtime_runtime.rs
|
||||||
|
@@ -64,11 +64,8 @@ impl WasmtimeRuntime {
|
||||||
|
}
|
||||||
|
let stdout = WritePipe::new_in_memory();
|
||||||
|
wasi = wasi.stdout(Box::new(stdout.clone()));
|
||||||
|
- let mut args: Vec<String> = Vec::new();
|
||||||
|
- for (_, v) in data {
|
||||||
|
- args.push(v);
|
||||||
|
- }
|
||||||
|
- wasi = wasi.args(&args)?;
|
||||||
|
+ let serialized = serde_json::to_string(&data)?;
|
||||||
|
+ wasi = wasi.args(&[serialized])?;
|
||||||
|
for preopen_dir_path in self.config.preopened_dirs() {
|
||||||
|
let preopen_dir = Dir::open_ambient_dir(preopen_dir_path, ambient_authority())?;
|
||||||
|
wasi = wasi.preopened_dir(preopen_dir, preopen_dir_path)?;
|
||||||
|
@@ -128,10 +125,11 @@ impl WasmtimeRuntime {
|
||||||
|
//let wasm_function = instance.get_func(&mut store, function).unwrap();
|
||||||
|
let wasm_function =
|
||||||
|
instance.get_typed_func::<(i32, i32), (i32, i32), _>(&mut store, function)?;
|
||||||
|
+
|
||||||
|
if serialized.len() > WASM_PAGE_SIZE as usize {
|
||||||
|
return Err(anyhow!("input args size larger than {}", WASM_PAGE_SIZE));
|
||||||
|
}
|
||||||
|
-
|
||||||
|
+ info!("serialized.len() is {}", serialized.len() as usize);
|
||||||
|
let memory = instance
|
||||||
|
.get_memory(&mut store, "memory")
|
||||||
|
.ok_or(anyhow::format_err!("failed to find `memory` export"))?;
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
23659
patch/0007-integration-test-init-for-wasmengine.patch
Normal file
23659
patch/0007-integration-test-init-for-wasmengine.patch
Normal file
File diff suppressed because it is too large
Load Diff
35
patch/0008-typo-fix.patch
Normal file
35
patch/0008-typo-fix.patch
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
From 0a83ca643d5e4f257ff0971878b12f23b9a3ff36 Mon Sep 17 00:00:00 2001
|
||||||
|
From: meilier <xingweizheng@huawei.com>
|
||||||
|
Date: Mon, 8 Aug 2022 10:48:31 +0800
|
||||||
|
Subject: [PATCH 6/6] typo fix
|
||||||
|
|
||||||
|
---
|
||||||
|
.gitignore | 1 +
|
||||||
|
src/main.rs | 2 +-
|
||||||
|
2 files changed, 2 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/.gitignore b/.gitignore
|
||||||
|
index 3c31371..a544b8b 100644
|
||||||
|
--- a/.gitignore
|
||||||
|
+++ b/.gitignore
|
||||||
|
@@ -3,3 +3,4 @@
|
||||||
|
*.swp
|
||||||
|
target
|
||||||
|
target-cover
|
||||||
|
+vendor
|
||||||
|
diff --git a/src/main.rs b/src/main.rs
|
||||||
|
index 450910d..547ade7 100644
|
||||||
|
--- a/src/main.rs
|
||||||
|
+++ b/src/main.rs
|
||||||
|
@@ -240,7 +240,7 @@ mod handlers {
|
||||||
|
|
||||||
|
Ok(Response {
|
||||||
|
status: http::StatusCode::OK.as_u16(),
|
||||||
|
- body: format!("delete function {} successfull!\n", func.function_name),
|
||||||
|
+ body: format!("delete function {} successfully!\n", func.function_name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
8
series.conf
Normal file
8
series.conf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
patch/0001-add-experiments-to-tar.patch
|
||||||
|
patch/0002-add-another_json_minimal-to-vendor.patch
|
||||||
|
patch/0003-remove-unused-code-and-comments.patch
|
||||||
|
patch/0004-pull_wasm-return-result-do-not-panic.patch
|
||||||
|
patch/0005-wasmengine-could-pull-public-https-repository-image.patch
|
||||||
|
patch/0006-wasi-use-json-as-args-for-consistent-wasm-function-i.patch
|
||||||
|
patch/0007-integration-test-init-for-wasmengine.patch
|
||||||
|
patch/0008-typo-fix.patch
|
||||||
Loading…
x
Reference in New Issue
Block a user