forked from apache/shenyu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE apache#4612] prepare shenyu-wasm
- Loading branch information
hailang
committed
Jul 10, 2023
1 parent
1cd6444
commit 43fc5bb
Showing
20 changed files
with
1,309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: build wasm | ||
|
||
on: [push] | ||
|
||
jobs: | ||
linux: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- name: Build with rust | ||
run: | | ||
cd ${{ github.workspace }}/shenyu-wasm/shenyu-wasm-build | ||
/home/runner/.cargo/bin/cargo clean | ||
/home/runner/.cargo/bin/cargo build --release | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: lib | ||
path: shenyu-wasm/shenyu-wasm-build/target/release/lib* | ||
if-no-files-found: error | ||
|
||
mac: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- name: Build with rust | ||
run: | | ||
cd ${{ github.workspace }}/shenyu-wasm/shenyu-wasm-build | ||
/Users/runner/.cargo/bin/cargo clean | ||
/Users/runner/.cargo/bin/cargo build --release | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: lib | ||
path: shenyu-wasm/shenyu-wasm-build/target/release/lib* | ||
if-no-files-found: error | ||
|
||
windows: | ||
runs-on: windows-2019 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- name: Build with rust | ||
run: | | ||
cd ${{ github.workspace }}/shenyu-wasm/shenyu-wasm-build | ||
C://Users//runneradmin//.cargo//bin//cargo.exe clean | ||
C://Users//runneradmin//.cargo//bin//cargo.exe build --release | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: lib | ||
path: shenyu-wasm/shenyu-wasm-build/target/release/*.dll | ||
if-no-files-found: error | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: lib | ||
path: shenyu-wasm/shenyu-wasm-build/target/release/*.lib | ||
if-no-files-found: error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ Thumbs.db | |
# agent build ignore | ||
/agent/ | ||
|
||
/**/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu</artifactId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>shenyu-wasm</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>shenyu-wasm-runtime</module> | ||
</modules> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
publish = false | ||
name = "shenyu-wasm-build" | ||
version = "0.1.0" | ||
authors = ["zhangzicheng@apache.org"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
wasmer = { git = "https://github.com/wasmerio/wasmer", rev = "1.0.0" } | ||
wasmer-runtime = { git = "https://github.com/wasmerio/wasmer", rev = "1.0.0" } | ||
wasmer-runtime-core = { git = "https://github.com/wasmerio/wasmer", rev = "1.0.0" } | ||
jni = "0.16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
pub use jni::errors::Error; | ||
use jni::{errors::ErrorKind, JNIEnv}; | ||
use std::thread; | ||
|
||
pub fn runtime_error(message: String) -> Error { | ||
Error::from_kind(ErrorKind::Msg(message)) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum JOption<T> { | ||
Some(T), | ||
None, | ||
} | ||
|
||
impl<T> JOption<T> { | ||
pub fn unwrap_or(self, default: T) -> T { | ||
match self { | ||
JOption::Some(result) => result, | ||
JOption::None => default, | ||
} | ||
} | ||
} | ||
|
||
pub fn joption_or_throw<T>(env: &JNIEnv, result: thread::Result<Result<T, Error>>) -> JOption<T> { | ||
match result { | ||
Ok(result) => match result { | ||
Ok(result) => JOption::Some(result), | ||
Err(error) => { | ||
if !env.exception_check().unwrap() { | ||
env.throw_new("java/lang/RuntimeException", &error.to_string()) | ||
.expect("Cannot throw an `java/lang/RuntimeException` exception."); | ||
} | ||
|
||
JOption::None | ||
} | ||
}, | ||
Err(ref error) => { | ||
env.throw_new("java/lang/RuntimeException", format!("{:?}", error)) | ||
.expect("Cannot throw an `java/lang/RuntimeException` exception."); | ||
|
||
JOption::None | ||
} | ||
} | ||
} |
Oops, something went wrong.