Skip to content

Commit

Permalink
build: patch ttrpc-compiler output to not error with rust 1.81 clippy
Browse files Browse the repository at this point in the history
Fixes the following and few other errors like this:

error: lint `box_pointers` has been removed: it does not detect other kinds
of allocations, and existed only for historical reasons
Error:  --> attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent_ttrpc.rs:7:10
  |
7 | #![allow(box_pointers)]
  |          ^^^^^^^^^^^^
  |
  = note: `-D renamed-and-removed-lints` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]`

Signed-off-by: Mikko Ylinen <[email protected]>
  • Loading branch information
mythi committed Sep 7, 2024
1 parent bd9a78d commit ce95702
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 23 deletions.
28 changes: 28 additions & 0 deletions api-server-rest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ fn main() -> std::io::Result<()> {
];
let protobuf_customized = ProtobufCustomize::default().gen_mod_rs(false);

use std::fs::File;
use std::io::{Read, Write};

fn replace_text_in_file(file_name: &str, from: &str, to: &str) -> Result<(), std::io::Error> {
let mut src = File::open(file_name)?;
let mut contents = String::new();
src.read_to_string(&mut contents).unwrap();
drop(src);

let new_contents = contents.replace(from, to);

let mut dst = File::create(file_name)?;
dst.write_all(new_contents.as_bytes())?;

Ok(())
}

Codegen::new()
.out_dir("src/ttrpc_proto")
.inputs(&protos)
Expand All @@ -101,6 +118,17 @@ fn main() -> std::io::Result<()> {
.run()
.expect("Generate ttrpc protocol code failed.");

// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file(
"src/ttrpc_proto/attestation_agent_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
replace_text_in_file(
"src/ttrpc_proto/confidential_data_hub_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
generate_openapi_document().expect("Generate restful OpenAPI yaml failed.");

Ok(())
Expand Down
1 change: 0 additions & 1 deletion api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
5 changes: 5 additions & 0 deletions attestation-agent/kbs_protocol/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"client: client",
"client",
)?;
replace_text_in_file(
"src/token_provider/aa/attestation_agent_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
2 changes: 2 additions & 0 deletions confidential-data-hub/hub/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ fn main() {

// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file("src/bin/protos/api_ttrpc.rs", "client: client", "client");
replace_text_in_file("src/bin/protos/api_ttrpc.rs", "#![allow(box_pointers)]\n", "");
replace_text_in_file("src/bin/protos/keyprovider_ttrpc.rs", "#![allow(box_pointers)]\n", "");
}

#[cfg(feature = "bin")]
Expand Down
1 change: 0 additions & 1 deletion confidential-data-hub/hub/src/bin/protos/api_ttrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
60 changes: 44 additions & 16 deletions image-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,53 @@
// SPDX-License-Identifier: Apache-2.0
//

use anyhow::*;

fn main() -> Result<()> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "tonic-build")]
tonic_build::compile_protos("./protos/getresource.proto").context("tonic build")?;
tonic_build::compile_protos("./protos/getresource.proto").expect("tonic build");

#[cfg(feature = "ttrpc-codegen")]
ttrpc_codegen::Codegen::new()
.out_dir("./src/resource/kbs/ttrpc_proto")
.input("./protos/getresource.proto")
.include("./protos")
.rust_protobuf()
.customize(ttrpc_codegen::Customize {
async_all: true,
..Default::default()
})
.rust_protobuf_customize(ttrpc_codegen::ProtobufCustomize::default().gen_mod_rs(false))
.run()
.context("ttrpc build")?;
{
use std::fs::File;
use std::io::{Read, Write};

fn replace_text_in_file(
file_name: &str,
from: &str,
to: &str,
) -> Result<(), std::io::Error> {
let mut src = File::open(file_name)?;
let mut contents = String::new();
src.read_to_string(&mut contents).unwrap();
drop(src);

let new_contents = contents.replace(from, to);

let mut dst = File::create(file_name)?;
dst.write_all(new_contents.as_bytes())?;

Ok(())
}

ttrpc_codegen::Codegen::new()
.out_dir("./src/resource/kbs/ttrpc_proto")
.input("./protos/getresource.proto")
.include("./protos")
.rust_protobuf()
.customize(ttrpc_codegen::Customize {
async_all: true,
..Default::default()
})
.rust_protobuf_customize(ttrpc_codegen::ProtobufCustomize::default().gen_mod_rs(false))
.run()
.expect("ttrpc build");

// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file(
"src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
}

Ok(())
}
1 change: 0 additions & 1 deletion image-rs/src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down
5 changes: 5 additions & 0 deletions ocicrypt-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"client: client",
"client",
)?;
replace_text_in_file(
"src/utils/ttrpc/keyprovider_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
}

Ok(())
Expand Down
1 change: 0 additions & 1 deletion ocicrypt-rs/src/utils/ttrpc/keyprovider_ttrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down

0 comments on commit ce95702

Please sign in to comment.