diff --git a/Cargo.toml b/Cargo.toml index 73a7a3a39..7f1e46f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index a9a5ce98f..40ea9cad8 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -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" @@ -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", diff --git a/crates/lib/src/client.rs b/crates/lib/src/client.rs index bc3abfd24..3726ac679 100644 --- a/crates/lib/src/client.rs +++ b/crates/lib/src/client.rs @@ -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, @@ -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>; +#[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 @@ -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)) } } diff --git a/crates/lib/src/qpu/api.rs b/crates/lib/src/qpu/api.rs index 89522d502..aba2d9642 100644 --- a/crates/lib/src/qpu/api.rs +++ b/crates/lib/src/qpu/api.rs @@ -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, @@ -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( diff --git a/crates/python/Cargo.toml b/crates/python/Cargo.toml index 0282fcd6d..eb2b38067 100644 --- a/crates/python/Cargo.toml +++ b/crates/python/Cargo.toml @@ -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 diff --git a/deny.toml b/deny.toml index 1aa302597..0f0840c11 100644 --- a/deny.toml +++ b/deny.toml @@ -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"]