Skip to content

Commit

Permalink
Merge pull request #1663 from tursodatabase/lucio/resolve-solana-build
Browse files Browse the repository at this point in the history
libsql: add `tls` feature
  • Loading branch information
LucioFranco authored Sep 20, 2024
2 parents de45f4e + 2f1d71d commit 2fc60b8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libsql-replication/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tonic = { version = "0.11", features = ["tls"] }
tonic = { version = "0.11", default-features = false, features = ["codegen", "prost"] }
prost = "0.12"
libsql-sys = { version = "0.7", path = "../libsql-sys", default-features = false, features = ["wal", "rusqlite", "api"] }
libsql-wal = { path = "../libsql-wal/", optional = true }
Expand Down
13 changes: 8 additions & 5 deletions libsql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ libsql-hrana = { version = "0.2", path = "../libsql-hrana", optional = true }
tokio = { version = "1.29.1", features = ["sync"], optional = true }
tokio-util = { version = "0.7", features = ["io-util", "codec"], optional = true }
parking_lot = { version = "0.12.1", optional = true }
hyper = { workspace = true, features = ["client", "stream"], optional = true }
hyper = { version = "0.14", features = ["client", "http1", "http2", "stream", "runtime"], optional = true }
hyper-rustls = { version = "0.25", features = ["webpki-roots"], optional = true }
base64 = { version = "0.21", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
Expand All @@ -31,7 +31,7 @@ anyhow = { version = "1.0.71", optional = true }
bytes = { version = "1.4.0", features = ["serde"], optional = true }
uuid = { version = "1.4.0", features = ["v4", "serde"], optional = true }
tokio-stream = { version = "0.1.14", optional = true }
tonic = { version = "0.11", features = ["tls", "tls-roots", "tls-webpki-roots"], optional = true}
tonic = { version = "0.11", optional = true}
tonic-web = { version = "0.11", optional = true }
tower-http = { version = "0.4.4", features = ["trace", "set-header", "util"], optional = true }
http = { version = "0.2", optional = true }
Expand All @@ -53,7 +53,7 @@ tempfile = { version = "3.7.0" }
rand = "0.8.5"

[features]
default = ["core", "replication", "remote"]
default = ["core", "replication", "remote", "tls"]
core = [
"libsql-sys",
"dep:bitflags",
Expand Down Expand Up @@ -88,7 +88,6 @@ replication = [
"dep:tonic",
"dep:tonic-web",
"dep:tower-http",
"dep:hyper-rustls",
"dep:futures",
"dep:libsql_replication",
]
Expand All @@ -109,22 +108,26 @@ remote = [
"hrana",
"dep:tower",
"dep:hyper",
"dep:hyper",
"dep:http",
"dep:tokio",
"dep:futures",
"dep:bitflags",
"dep:hyper-rustls",
]
wasm = ["hrana"]
cloudflare = [
"wasm",
"dep:worker"
]
encryption = ["core", "libsql-sys/encryption", "dep:bytes"]
tls = ["dep:hyper-rustls"]

[[bench]]
name = "benchmark"
harness = false

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.cargo-udeps.ignore]
normal = ["hyper-rustls"]
13 changes: 12 additions & 1 deletion libsql/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,10 @@ impl Database {
}
}

#[cfg(any(feature = "replication", feature = "remote"))]
#[cfg(any(
all(feature = "tls", feature = "replication"),
all(feature = "tls", feature = "remote")
))]
fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>> {
let mut http = hyper::client::HttpConnector::new();
http.enforce_http(false);
Expand All @@ -633,6 +636,14 @@ fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnect
.wrap_connector(http))
}

#[cfg(any(
all(not(feature = "tls"), feature = "replication"),
all(not(feature = "tls"), feature = "remote")
))]
fn connector() -> Result<hyper::client::HttpConnector> {
panic!("The `tls` feature is disabled, you must provide your own http connector");
}

impl std::fmt::Debug for Database {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Database").finish()
Expand Down
24 changes: 24 additions & 0 deletions libsql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,32 @@
//! that will allow you to sync you remote database locally.
//! - `remote` this feature flag only includes HTTP code that will allow you to run queries against
//! a remote database.
//! - `tls` this feature flag disables the builtin TLS connector and instead requires that you pass
//! your own connector for any of the features that require HTTP.
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(
all(
any(
not(feature = "remote"),
not(feature = "replication"),
not(feature = "core")
),
feature = "tls"
),
allow(unused_imports)
)]
#![cfg_attr(
all(
any(
not(feature = "remote"),
not(feature = "replication"),
not(feature = "core")
),
feature = "tls"
),
allow(dead_code)
)]

#[macro_use]
mod macros;
Expand Down

0 comments on commit 2fc60b8

Please sign in to comment.