Skip to content

Commit

Permalink
Support build rustls into wasi
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed Dec 21, 2023
1 parent 088f62a commit 27c65f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords = ["mysql", "database", "asynchronous", "async", "wasi"]
license = "MIT/Apache-2.0"
name = "mysql_async_wasi"
readme = "README.md"
repository = "https://github.com/blackbeam/mysql_async"
repository = "https://github.com/WasmEdge/mysql_async_wasi"
version = "0.33.0"
exclude = ["test/*"]
edition = "2018"
Expand Down Expand Up @@ -58,10 +58,16 @@ wasmedge_rustls_api = { version = "0.1.0", optional = true, features = [
"tokio_async",
] }

[dependencies.tokio-rustls]
[target.'cfg(not(target_os="wasi"))'.dependencies.tokio-rustls]
version = "0.24.0"
optional = true

[target.'cfg(target_os="wasi")'.dependencies.tokio-rustls-wasi]
git = "https://github.com/second-state/tokio-rustls.git"
branch = "v0.24.1"
optional = true


[target.'cfg(not(target_os="wasi"))'.dependencies.tokio-native-tls]
version = "0.3.0"
optional = true
Expand Down Expand Up @@ -106,7 +112,7 @@ tokio_wasi = { version = "1", features = [
wasmedge_wasi_socket = "0.5"

[features]
default = ["flate2/zlib", "common", "derive", "native-tls-tls", "binlog"]
default = ["flate2/zlib", "common", "derive", "binlog"]
default-rustls = [
"flate2/rust_backend",
"common",
Expand All @@ -121,10 +127,12 @@ common = [
"mysql_common/frunk",
]
minimal = ["flate2/zlib"]
wasmedge-tls = ["wasmedge_rustls_api"]
native-tls-tls = ["native-tls", "tokio-native-tls"]
rustls-tls = [
"rustls",
"tokio-rustls",
"tokio-rustls-wasi",
"webpki",
"webpki-roots",
"rustls-pemfile",
Expand Down
10 changes: 6 additions & 4 deletions src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use mysql_common::{
packets::{
AuthPlugin, AuthSwitchRequest, CommonOkPacket, ErrPacket, HandshakePacket,
HandshakeResponse, OkPacket, OkPacketDeserializer, OldAuthSwitchRequest, OldEofPacket,
ResultSetTerminator, SslRequest,
ResultSetTerminator,
},
proto::MySerialize,
row::Row,
Expand Down Expand Up @@ -528,7 +528,7 @@ impl Conn {

Ok(())
}
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]

async fn switch_to_ssl_if_needed(&mut self) -> Result<()> {
if self
.inner
Expand Down Expand Up @@ -929,7 +929,6 @@ impl Conn {
conn.inner.stream = Some(stream);
conn.setup_stream()?;
conn.handle_handshake().await?;
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]
conn.switch_to_ssl_if_needed().await?;
conn.do_handshake_response().await?;
conn.continue_auth().await?;
Expand Down Expand Up @@ -1452,7 +1451,10 @@ mod test {
#[test]
fn should_not_panic_if_dropped_without_tokio_runtime() {
let fut = Conn::new(get_opts());
let runtime = tokio::runtime::Runtime::new().unwrap();
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
runtime.block_on(async {
fut.await.unwrap();
});
Expand Down
15 changes: 12 additions & 3 deletions src/conn/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ mod test {
}
}

let runtime = tokio::runtime::Runtime::new().unwrap();
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let database = Database {
pool: Pool::new(get_opts()),
};
Expand Down Expand Up @@ -854,7 +857,10 @@ mod test {
fn should_not_panic_on_unclean_shutdown() {
// run more than once to trigger different drop orders
for _ in 0..10 {
let rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let (tx, rx) = tokio::sync::oneshot::channel();
rt.block_on(async move {
let pool = Pool::new(get_opts());
Expand All @@ -874,7 +880,10 @@ mod test {
fn should_perform_clean_shutdown() {
// run more than once to trigger different drop orders
for _ in 0..10 {
let rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let (tx, rx) = tokio::sync::oneshot::channel();
let jh = rt.spawn(async move {
let pool = Pool::new(get_opts());
Expand Down
3 changes: 1 addition & 2 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Endpoint {
not(feature = "rustls"),
not(feature = "wasmedge-tls")
))]
pub async fn _make_secure(
pub async fn make_secure(
&mut self,
_domain: String,
_ssl_opts: crate::SslOpts,
Expand Down Expand Up @@ -435,7 +435,6 @@ impl Stream {
pub(crate) fn set_tcp_nodelay(&self, val: bool) -> io::Result<()> {
self.codec.as_ref().unwrap().get_ref().set_tcp_nodelay(val)
}
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]
pub(crate) async fn make_secure(
&mut self,
domain: String,
Expand Down

0 comments on commit 27c65f3

Please sign in to comment.