Skip to content

Commit 2f1d71d

Browse files
committed
libsql: add tls feature
This adds a new `tls` feature that is enabled by default, if this feature is disabled building a libsql connection will panic with a message asking you to configure a http connector. This allows users to bring their own http connector and more importantly their own TLS lib with their own versions without needing to compile rustls which we use by default. This resolves solana-sdk >2 build issues with uses an older version of `curve25519-dalek` that pings `zeroize` to `<1.4`. New versions of `rustls` require `1.7` of `zeroize` thus causing issues when building `rustls` for libsql with the `tls` feature.
1 parent 4023a3a commit 2f1d71d

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsql-replication/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
tonic = { version = "0.11", features = ["tls"] }
12+
tonic = { version = "0.11", default-features = false, features = ["codegen", "prost"] }
1313
prost = "0.12"
1414
libsql-sys = { version = "0.7", path = "../libsql-sys", default-features = false, features = ["wal", "rusqlite", "api"] }
1515
libsql-wal = { path = "../libsql-wal/", optional = true }

libsql/Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ libsql-hrana = { version = "0.2", path = "../libsql-hrana", optional = true }
1616
tokio = { version = "1.29.1", features = ["sync"], optional = true }
1717
tokio-util = { version = "0.7", features = ["io-util", "codec"], optional = true }
1818
parking_lot = { version = "0.12.1", optional = true }
19-
hyper = { workspace = true, features = ["client", "stream"], optional = true }
19+
hyper = { version = "0.14", features = ["client", "http1", "http2", "stream", "runtime"], optional = true }
2020
hyper-rustls = { version = "0.25", features = ["webpki-roots"], optional = true }
2121
base64 = { version = "0.21", optional = true }
2222
serde = { version = "1", features = ["derive"], optional = true }
@@ -31,7 +31,7 @@ anyhow = { version = "1.0.71", optional = true }
3131
bytes = { version = "1.4.0", features = ["serde"], optional = true }
3232
uuid = { version = "1.4.0", features = ["v4", "serde"], optional = true }
3333
tokio-stream = { version = "0.1.14", optional = true }
34-
tonic = { version = "0.11", features = ["tls", "tls-roots", "tls-webpki-roots"], optional = true}
34+
tonic = { version = "0.11", optional = true}
3535
tonic-web = { version = "0.11", optional = true }
3636
tower-http = { version = "0.4.4", features = ["trace", "set-header", "util"], optional = true }
3737
http = { version = "0.2", optional = true }
@@ -53,7 +53,7 @@ tempfile = { version = "3.7.0" }
5353
rand = "0.8.5"
5454

5555
[features]
56-
default = ["core", "replication", "remote"]
56+
default = ["core", "replication", "remote", "tls"]
5757
core = [
5858
"libsql-sys",
5959
"dep:bitflags",
@@ -88,7 +88,6 @@ replication = [
8888
"dep:tonic",
8989
"dep:tonic-web",
9090
"dep:tower-http",
91-
"dep:hyper-rustls",
9291
"dep:futures",
9392
"dep:libsql_replication",
9493
]
@@ -109,22 +108,26 @@ remote = [
109108
"hrana",
110109
"dep:tower",
111110
"dep:hyper",
111+
"dep:hyper",
112112
"dep:http",
113113
"dep:tokio",
114114
"dep:futures",
115115
"dep:bitflags",
116-
"dep:hyper-rustls",
117116
]
118117
wasm = ["hrana"]
119118
cloudflare = [
120119
"wasm",
121120
"dep:worker"
122121
]
123122
encryption = ["core", "libsql-sys/encryption", "dep:bytes"]
123+
tls = ["dep:hyper-rustls"]
124124

125125
[[bench]]
126126
name = "benchmark"
127127
harness = false
128128

129129
[package.metadata.docs.rs]
130130
rustdoc-args = ["--cfg", "docsrs"]
131+
132+
[package.metadata.cargo-udeps.ignore]
133+
normal = ["hyper-rustls"]

libsql/src/database.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ impl Database {
582582
}
583583
}
584584

585-
#[cfg(any(feature = "replication", feature = "remote"))]
585+
#[cfg(any(
586+
all(feature = "tls", feature = "replication"),
587+
all(feature = "tls", feature = "remote")
588+
))]
586589
fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>> {
587590
let mut http = hyper::client::HttpConnector::new();
588591
http.enforce_http(false);
@@ -596,6 +599,14 @@ fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnect
596599
.wrap_connector(http))
597600
}
598601

602+
#[cfg(any(
603+
all(not(feature = "tls"), feature = "replication"),
604+
all(not(feature = "tls"), feature = "remote")
605+
))]
606+
fn connector() -> Result<hyper::client::HttpConnector> {
607+
panic!("The `tls` feature is disabled, you must provide your own http connector");
608+
}
609+
599610
impl std::fmt::Debug for Database {
600611
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
601612
f.debug_struct("Database").finish()

libsql/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,32 @@
8888
//! that will allow you to sync you remote database locally.
8989
//! - `remote` this feature flag only includes HTTP code that will allow you to run queries against
9090
//! a remote database.
91+
//! - `tls` this feature flag disables the builtin TLS connector and instead requires that you pass
92+
//! your own connector for any of the features that require HTTP.
9193
9294
#![cfg_attr(docsrs, feature(doc_cfg))]
95+
#![cfg_attr(
96+
all(
97+
any(
98+
not(feature = "remote"),
99+
not(feature = "replication"),
100+
not(feature = "core")
101+
),
102+
feature = "tls"
103+
),
104+
allow(unused_imports)
105+
)]
106+
#![cfg_attr(
107+
all(
108+
any(
109+
not(feature = "remote"),
110+
not(feature = "replication"),
111+
not(feature = "core")
112+
),
113+
feature = "tls"
114+
),
115+
allow(dead_code)
116+
)]
93117

94118
#[macro_use]
95119
mod macros;

0 commit comments

Comments
 (0)