Skip to content

Commit

Permalink
Make grpc-web an opt-in feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Mar 6, 2024
1 parent 2e91685 commit ad69b0a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.dependencies]
qcs-api = "0.2.1"
qcs-api-client-common = { git = "https://github.com/rigetti/qcs-api-client-rust", branch = "grpc-web" }
qcs-api-client-grpc = { git = "https://github.com/rigetti/qcs-api-client-rust", branch = "grpc-web", features = ["grpc-web"] }
qcs-api-client-grpc = { git = "https://github.com/rigetti/qcs-api-client-rust", branch = "grpc-web" }
qcs-api-client-openapi = { git = "https://github.com/rigetti/qcs-api-client-rust", branch = "grpc-web" }
serde_json = "1.0.86"
thiserror = "1.0.37"
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tracing = ["dep:tracing", "qcs-api-client-common/tracing", "qcs-api-client-grpc/
tracing-config = ["tracing", "qcs-api-client-common/tracing-config", "qcs-api-client-grpc/tracing-config", "qcs-api-client-openapi/tracing-config"]
otel-tracing = ["tracing-config", "qcs-api-client-grpc/otel-tracing", "qcs-api-client-openapi/otel-tracing"]
libquil = ["dep:libquil-sys"]
grpc-web = ["qcs-api-client-grpc/grpc-web"]

[dependencies]
cached = "0.44.0"
Expand All @@ -27,7 +28,7 @@ num = { version = "0.4.0", features = ["serde"] }
qcs-api.workspace = true
qcs-api-client-common.workspace = true
qcs-api-client-openapi.workspace = true
qcs-api-client-grpc.workspace = true
qcs-api-client-grpc = { workspace = true, optional = true }
quil-rs.workspace = true
reqwest = { version = "0.11.20", default-features = false, features = [
"rustls-tls",
Expand Down
15 changes: 13 additions & 2 deletions crates/lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use std::time::Duration;

use qcs_api_client_common::configuration::{ClientConfiguration, RefreshError};
#[cfg(feature = "grpc-web")]
use qcs_api_client_grpc::channel::{wrap_channel_with_grpc_web, GrpcWebType};
use qcs_api_client_grpc::{
channel::{
get_channel, parse_uri, wrap_channel_with, wrap_channel_with_retry, wrap_channel_with_grpc_web, GrpcWebType, RefreshService,
get_channel, parse_uri, wrap_channel_with, wrap_channel_with_retry, RefreshService,
RetryService,
},
services::translation::translation_client::TranslationClient,
Expand All @@ -20,6 +22,13 @@ pub use qcs_api_client_common::configuration::LoadError;
pub use qcs_api_client_grpc::channel::Error as GrpcError;
pub use qcs_api_client_openapi::apis::Error as OpenApiError;

#[cfg(not(feature = "grpc-web"))]
/// A type alias for the underlying gRPC connection used by all gRPC clients within this library.
/// It is public so that users can create gRPC clients with different APIs using a "raw" connection
/// initialized by this library. This ensures that the exact Tonic version used for such clients
/// matches what this library uses.
pub type GrpcConnection = RetryService<RefreshService<Channel, ClientConfiguration>>;
#[cfg(feature = "grpc-web")]
/// A type alias for the underlying gRPC connection used by all gRPC clients within this library.
/// It is public so that users can create gRPC clients with different APIs using a "raw" connection
/// initialized by this library. This ensures that the exact Tonic version used for such clients
Expand Down Expand Up @@ -92,7 +101,9 @@ impl Qcs {
let uri = parse_uri(translation_grpc_endpoint)?;
let channel = get_channel(uri)?;
let service =
wrap_channel_with_grpc_web(wrap_channel_with_retry(wrap_channel_with(channel, self.get_config().clone())));
wrap_channel_with_retry(wrap_channel_with(channel, self.get_config().clone()));
#[cfg(feature = "grpc-web")]
let service = wrap_channel_with_grpc_web(service);
Ok(TranslationClient::new(service))
}
}
Expand Down
13 changes: 8 additions & 5 deletions crates/lib/src/qpu/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use std::{fmt, time::Duration};
use cached::proc_macro::cached;
use derive_builder::Builder;
use qcs_api_client_common::configuration::RefreshError;
#[cfg(feature = "grpc-web")]
use qcs_api_client_grpc::channel::wrap_channel_with_grpc_web;
pub use qcs_api_client_grpc::channel::Error as GrpcError;
use qcs_api_client_grpc::{
channel::{parse_uri, wrap_channel_with, wrap_channel_with_grpc_web, wrap_channel_with_retry},
channel::{parse_uri, wrap_channel_with, wrap_channel_with_retry},
get_channel_with_timeout,
models::controller::{
controller_job_execution_result, data_value::Value, ControllerJobExecutionResult,
Expand Down Expand Up @@ -529,10 +531,11 @@ impl ExecutionOptions {
let uri = parse_uri(address).map_err(QpuApiError::GrpcError)?;
let channel = get_channel_with_timeout(uri, self.timeout())
.map_err(|err| QpuApiError::GrpcError(err.into()))?;
Ok(wrap_channel_with_grpc_web(wrap_channel_with_retry(wrap_channel_with(
channel,
client.get_config().clone(),
))))
let channel =
wrap_channel_with_retry(wrap_channel_with(channel, client.get_config().clone()));
#[cfg(feature = "grpc-web")]
let channel = wrap_channel_with_grpc_web(channel);
Ok(channel)
}

async fn get_gateway_address(
Expand Down
2 changes: 1 addition & 1 deletion crates/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
async-trait = "0.1.73"
qcs = { path = "../lib", features = ["tracing"] }
qcs = { path = "../lib", features = ["tracing", "grpc-web"] }
qcs-api.workspace = true
qcs-api-client-common.workspace = true
qcs-api-client-grpc.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ unknown-registry = "deny"
# Lint level for what to happen when a crate from a git repository that is not
# in the allow list is encountered
unknown-git = "deny"
allow-git = ["https://github.com/rigetti/quil-rs", "https://github.com/rigetti/qcs-sdk-rust"]
allow-git = ["https://github.com/rigetti/quil-rs", "https://github.com/rigetti/qcs-api-client-rust"]
# List of URLs for allowed crate registries. Defaults to the crates.io index
# if not specified. If it is specified but empty, no registries are allowed.
allow-registry = ["https://github.com/rust-lang/crates.io-index"]

0 comments on commit ad69b0a

Please sign in to comment.