Skip to content

Commit 98f3569

Browse files
committed
Support build rustls into wasi
Signed-off-by: csh <[email protected]>
1 parent 088f62a commit 98f3569

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ wasmedge_rustls_api = { version = "0.1.0", optional = true, features = [
5858
"tokio_async",
5959
] }
6060

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

65+
[target.'cfg(target_os="wasi")'.dependencies.tokio-rustls-wasi]
66+
git = "https://github.com/second-state/tokio-rustls.git"
67+
branch = "v0.24.1"
68+
optional = true
69+
70+
6571
[target.'cfg(not(target_os="wasi"))'.dependencies.tokio-native-tls]
6672
version = "0.3.0"
6773
optional = true
@@ -106,7 +112,7 @@ tokio_wasi = { version = "1", features = [
106112
wasmedge_wasi_socket = "0.5"
107113

108114
[features]
109-
default = ["flate2/zlib", "common", "derive", "native-tls-tls", "binlog"]
115+
default = ["flate2/zlib", "common", "derive", "binlog"]
110116
default-rustls = [
111117
"flate2/rust_backend",
112118
"common",
@@ -121,10 +127,12 @@ common = [
121127
"mysql_common/frunk",
122128
]
123129
minimal = ["flate2/zlib"]
130+
wasmedge-tls = ["wasmedge_rustls_api"]
124131
native-tls-tls = ["native-tls", "tokio-native-tls"]
125132
rustls-tls = [
126133
"rustls",
127134
"tokio-rustls",
135+
"tokio-rustls-wasi",
128136
"webpki",
129137
"webpki-roots",
130138
"rustls-pemfile",

src/conn/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use mysql_common::{
1616
packets::{
1717
AuthPlugin, AuthSwitchRequest, CommonOkPacket, ErrPacket, HandshakePacket,
1818
HandshakeResponse, OkPacket, OkPacketDeserializer, OldAuthSwitchRequest, OldEofPacket,
19-
ResultSetTerminator, SslRequest,
19+
ResultSetTerminator,
2020
},
2121
proto::MySerialize,
2222
row::Row,
@@ -528,7 +528,7 @@ impl Conn {
528528

529529
Ok(())
530530
}
531-
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]
531+
532532
async fn switch_to_ssl_if_needed(&mut self) -> Result<()> {
533533
if self
534534
.inner
@@ -929,7 +929,6 @@ impl Conn {
929929
conn.inner.stream = Some(stream);
930930
conn.setup_stream()?;
931931
conn.handle_handshake().await?;
932-
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]
933932
conn.switch_to_ssl_if_needed().await?;
934933
conn.do_handshake_response().await?;
935934
conn.continue_auth().await?;
@@ -1452,7 +1451,10 @@ mod test {
14521451
#[test]
14531452
fn should_not_panic_if_dropped_without_tokio_runtime() {
14541453
let fut = Conn::new(get_opts());
1455-
let runtime = tokio::runtime::Runtime::new().unwrap();
1454+
let runtime = tokio::runtime::Builder::new_current_thread()
1455+
.enable_all()
1456+
.build()
1457+
.unwrap();
14561458
runtime.block_on(async {
14571459
fut.await.unwrap();
14581460
});

src/conn/pool/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,10 @@ mod test {
485485
}
486486
}
487487

488-
let runtime = tokio::runtime::Runtime::new().unwrap();
488+
let runtime = tokio::runtime::Builder::new_current_thread()
489+
.enable_all()
490+
.build()
491+
.unwrap();
489492
let database = Database {
490493
pool: Pool::new(get_opts()),
491494
};
@@ -854,7 +857,10 @@ mod test {
854857
fn should_not_panic_on_unclean_shutdown() {
855858
// run more than once to trigger different drop orders
856859
for _ in 0..10 {
857-
let rt = tokio::runtime::Runtime::new().unwrap();
860+
let rt = tokio::runtime::Builder::new_current_thread()
861+
.enable_all()
862+
.build()
863+
.unwrap();
858864
let (tx, rx) = tokio::sync::oneshot::channel();
859865
rt.block_on(async move {
860866
let pool = Pool::new(get_opts());
@@ -874,7 +880,10 @@ mod test {
874880
fn should_perform_clean_shutdown() {
875881
// run more than once to trigger different drop orders
876882
for _ in 0..10 {
877-
let rt = tokio::runtime::Runtime::new().unwrap();
883+
let rt = tokio::runtime::Builder::new_current_thread()
884+
.enable_all()
885+
.build()
886+
.unwrap();
878887
let (tx, rx) = tokio::sync::oneshot::channel();
879888
let jh = rt.spawn(async move {
880889
let pool = Pool::new(get_opts());

src/io/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Endpoint {
205205
not(feature = "rustls"),
206206
not(feature = "wasmedge-tls")
207207
))]
208-
pub async fn _make_secure(
208+
pub async fn make_secure(
209209
&mut self,
210210
_domain: String,
211211
_ssl_opts: crate::SslOpts,
@@ -435,7 +435,6 @@ impl Stream {
435435
pub(crate) fn set_tcp_nodelay(&self, val: bool) -> io::Result<()> {
436436
self.codec.as_ref().unwrap().get_ref().set_tcp_nodelay(val)
437437
}
438-
#[cfg(any(not(target_os = "wasi"), feature = "wasmedge-tls"))]
439438
pub(crate) async fn make_secure(
440439
&mut self,
441440
domain: String,

0 commit comments

Comments
 (0)