Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
fix(sdk): without phantom data
Browse files Browse the repository at this point in the history
  • Loading branch information
kjuulh committed Feb 19, 2023
1 parent 94336d0 commit 02006d4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() -> eyre::Result<()> {
}
}

fn release(client: Arc<Query>, subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
let src_dir = client.host().directory(
".".into(),
Some(HostDirectoryOpts {
Expand Down
23 changes: 16 additions & 7 deletions crates/dagger-codegen/src/rust/templates/object_tmpl.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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
Expand All @@ -81,20 +82,28 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
fn render_optional_field_args(
funcs: &CommonFunctions,
args: &Vec<&FullTypeFieldsArgs>,
) -> Option<rust::Tokens> {
) -> 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<FullTypeFields>) -> Option<rust::Tokens> {
Expand Down
1 change: 0 additions & 1 deletion crates/dagger-sdk/examples/build-the-application/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None,
marker: std::marker::PhantomData,
}),
);

Expand Down
1 change: 0 additions & 1 deletion crates/dagger-sdk/examples/multi-stage-build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

Expand Down
1 change: 0 additions & 1 deletion crates/dagger-sdk/examples/publish-the-application/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

Expand Down
1 change: 0 additions & 1 deletion crates/dagger-sdk/examples/test-the-application/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

Expand Down
22 changes: 11 additions & 11 deletions crates/dagger-sdk/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct ContainerExecOpts<'a> {
pub experimental_privileged_nesting: Option<bool>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerExportOpts<'a> {
pub struct ContainerExportOpts {
#[builder(setter(into, strip_option))]
pub platform_variants: Option<Vec<ContainerId>>,
}
Expand All @@ -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<Vec<ContainerId>>,
}
Expand Down Expand Up @@ -105,12 +105,12 @@ pub struct ContainerWithExecOpts<'a> {
pub experimental_privileged_nesting: Option<bool>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerWithFileOpts<'a> {
pub struct ContainerWithFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerWithMountedCacheOpts<'a> {
pub struct ContainerWithMountedCacheOpts {
#[builder(setter(into, strip_option))]
pub source: Option<DirectoryId>,
#[builder(setter(into, strip_option))]
Expand Down Expand Up @@ -777,17 +777,17 @@ pub struct DirectoryWithDirectoryOpts<'a> {
pub include: Option<Vec<&'a str>>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithFileOpts<'a> {
pub struct DirectoryWithFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithNewDirectoryOpts<'a> {
pub struct DirectoryWithNewDirectoryOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithNewFileOpts<'a> {
pub struct DirectoryWithNewFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
Expand Down Expand Up @@ -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<ContainerId>,
#[builder(setter(into, strip_option))]
pub platform: Option<Platform>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct QueryDirectoryOpts<'a> {
pub struct QueryDirectoryOpts {
#[builder(setter(into, strip_option))]
pub id: Option<DirectoryId>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct QueryGitOpts<'a> {
pub struct QueryGitOpts {
#[builder(setter(into, strip_option))]
pub keep_git_dir: Option<bool>,
}
Expand All @@ -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<SocketId>,
}
Expand Down

0 comments on commit 02006d4

Please sign in to comment.