From b25b350d909710bfe1e9712e2716b005905bef2e Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 19 Feb 2023 17:29:59 +0100 Subject: [PATCH] fix(sdk): without phantom data --- ci/src/main.rs | 2 +- .../src/rust/templates/object_tmpl.rs | 23 +++++++++++++------ .../examples/build-the-application/main.rs | 1 - .../examples/multi-stage-build/main.rs | 1 - .../examples/publish-the-application/main.rs | 1 - .../examples/test-the-application/main.rs | 1 - crates/dagger-sdk/src/gen.rs | 22 +++++++++--------- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/ci/src/main.rs b/ci/src/main.rs index 9d2cdd3..d7f02fc 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -28,7 +28,7 @@ fn main() -> eyre::Result<()> { } } -fn release(client: Arc, subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { +fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { let src_dir = client.host().directory( ".".into(), Some(HostDirectoryOpts { diff --git a/crates/dagger-codegen/src/rust/templates/object_tmpl.rs b/crates/dagger-codegen/src/rust/templates/object_tmpl.rs index 78c96c3..f3230aa 100644 --- a/crates/dagger-codegen/src/rust/templates/object_tmpl.rs +++ b/crates/dagger-codegen/src/rust/templates/object_tmpl.rs @@ -1,6 +1,7 @@ use dagger_core::introspection::{FullType, FullTypeFields, FullTypeFieldsArgs}; use genco::prelude::rust; use genco::quote; +use itertools::Itertools; use crate::functions::{type_ref_is_optional, CommonFunctions}; use crate::rust::functions::{ @@ -64,10 +65,10 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio let builder = rust::import("derive_builder", "Builder"); let phantom_data = rust::import("std::marker", "PhantomData"); - if let Some(fields) = fields { + if let Some((fields, contains_lifetime)) = fields { Some(quote! { #[derive($builder, Debug, PartialEq)] - pub struct $output_type<'a> { + pub struct $output_type$(if contains_lifetime => <'a>) { //#[builder(default, setter(skip))] //pub marker: $(phantom_data)<&'a ()>, $fields @@ -81,20 +82,28 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio fn render_optional_field_args( funcs: &CommonFunctions, args: &Vec<&FullTypeFieldsArgs>, -) -> Option { +) -> Option<(rust::Tokens, bool)> { if args.len() == 0 { return None; } + let mut contains_lifetime = false; let rendered_args = args.into_iter().map(|a| &a.input_value).map(|a| { + let type_ = funcs.format_immutable_input_type(&a.type_); + if type_.contains("str") { + contains_lifetime = true; + } quote! { #[builder(setter(into, strip_option))] - pub $(format_struct_name(&a.name)): Option<$(funcs.format_immutable_input_type(&a.type_))>, + pub $(format_struct_name(&a.name)): Option<$(type_)>, } }); - Some(quote! { - $(for arg in rendered_args join ($['\r']) => $arg) - }) + Some(( + quote! { + $(for arg in rendered_args join ($['\r']) => $arg) + }, + contains_lifetime, + )) } fn render_functions(funcs: &CommonFunctions, fields: &Vec) -> Option { diff --git a/crates/dagger-sdk/examples/build-the-application/main.rs b/crates/dagger-sdk/examples/build-the-application/main.rs index 9affe8d..523c25d 100644 --- a/crates/dagger-sdk/examples/build-the-application/main.rs +++ b/crates/dagger-sdk/examples/build-the-application/main.rs @@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> { Some(HostDirectoryOpts { exclude: Some(vec!["node_modules".into(), "ci/".into()]), include: None, - marker: std::marker::PhantomData, }), ); diff --git a/crates/dagger-sdk/examples/multi-stage-build/main.rs b/crates/dagger-sdk/examples/multi-stage-build/main.rs index d9debcc..3c3c0f6 100644 --- a/crates/dagger-sdk/examples/multi-stage-build/main.rs +++ b/crates/dagger-sdk/examples/multi-stage-build/main.rs @@ -9,7 +9,6 @@ fn main() -> eyre::Result<()> { Some(HostDirectoryOpts { exclude: Some(vec!["node_modules", "ci/"]), include: None, - marker: std::marker::PhantomData, }), ); diff --git a/crates/dagger-sdk/examples/publish-the-application/main.rs b/crates/dagger-sdk/examples/publish-the-application/main.rs index bf35044..1b76100 100644 --- a/crates/dagger-sdk/examples/publish-the-application/main.rs +++ b/crates/dagger-sdk/examples/publish-the-application/main.rs @@ -10,7 +10,6 @@ fn main() -> eyre::Result<()> { Some(HostDirectoryOpts { exclude: Some(vec!["node_modules", "ci/"]), include: None, - marker: std::marker::PhantomData, }), ); diff --git a/crates/dagger-sdk/examples/test-the-application/main.rs b/crates/dagger-sdk/examples/test-the-application/main.rs index b3a57e1..fe3328c 100644 --- a/crates/dagger-sdk/examples/test-the-application/main.rs +++ b/crates/dagger-sdk/examples/test-the-application/main.rs @@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> { Some(HostDirectoryOpts { exclude: Some(vec!["node_modules", "ci/"]), include: None, - marker: std::marker::PhantomData, }), ); diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index f304ac2..f4b8031 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -67,7 +67,7 @@ pub struct ContainerExecOpts<'a> { pub experimental_privileged_nesting: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct ContainerExportOpts<'a> { +pub struct ContainerExportOpts { #[builder(setter(into, strip_option))] pub platform_variants: Option>, } @@ -77,7 +77,7 @@ pub struct ContainerPipelineOpts<'a> { pub description: Option<&'a str>, } #[derive(Builder, Debug, PartialEq)] -pub struct ContainerPublishOpts<'a> { +pub struct ContainerPublishOpts { #[builder(setter(into, strip_option))] pub platform_variants: Option>, } @@ -105,12 +105,12 @@ pub struct ContainerWithExecOpts<'a> { pub experimental_privileged_nesting: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct ContainerWithFileOpts<'a> { +pub struct ContainerWithFileOpts { #[builder(setter(into, strip_option))] pub permissions: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct ContainerWithMountedCacheOpts<'a> { +pub struct ContainerWithMountedCacheOpts { #[builder(setter(into, strip_option))] pub source: Option, #[builder(setter(into, strip_option))] @@ -777,17 +777,17 @@ pub struct DirectoryWithDirectoryOpts<'a> { pub include: Option>, } #[derive(Builder, Debug, PartialEq)] -pub struct DirectoryWithFileOpts<'a> { +pub struct DirectoryWithFileOpts { #[builder(setter(into, strip_option))] pub permissions: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct DirectoryWithNewDirectoryOpts<'a> { +pub struct DirectoryWithNewDirectoryOpts { #[builder(setter(into, strip_option))] pub permissions: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct DirectoryWithNewFileOpts<'a> { +pub struct DirectoryWithNewFileOpts { #[builder(setter(into, strip_option))] pub permissions: Option, } @@ -1360,19 +1360,19 @@ pub struct Query { } #[derive(Builder, Debug, PartialEq)] -pub struct QueryContainerOpts<'a> { +pub struct QueryContainerOpts { #[builder(setter(into, strip_option))] pub id: Option, #[builder(setter(into, strip_option))] pub platform: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct QueryDirectoryOpts<'a> { +pub struct QueryDirectoryOpts { #[builder(setter(into, strip_option))] pub id: Option, } #[derive(Builder, Debug, PartialEq)] -pub struct QueryGitOpts<'a> { +pub struct QueryGitOpts { #[builder(setter(into, strip_option))] pub keep_git_dir: Option, } @@ -1382,7 +1382,7 @@ pub struct QueryPipelineOpts<'a> { pub description: Option<&'a str>, } #[derive(Builder, Debug, PartialEq)] -pub struct QuerySocketOpts<'a> { +pub struct QuerySocketOpts { #[builder(setter(into, strip_option))] pub id: Option, }