From ce95702fae56bddf82feac0883822bcb7e989efc Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Fri, 6 Sep 2024 22:37:30 +0300 Subject: [PATCH] build: patch ttrpc-compiler output to not error with rust 1.81 clippy 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 --- api-server-rest/build.rs | 28 +++++++++ .../ttrpc_proto/attestation_agent_ttrpc.rs | 1 - .../confidential_data_hub_ttrpc.rs | 1 - attestation-agent/kbs_protocol/build.rs | 5 ++ .../aa/attestation_agent_ttrpc.rs | 1 - confidential-data-hub/hub/build.rs | 2 + .../hub/src/bin/protos/api_ttrpc.rs | 1 - .../hub/src/bin/protos/keyprovider_ttrpc.rs | 1 - image-rs/build.rs | 60 ++++++++++++++----- .../kbs/ttrpc_proto/getresource_ttrpc.rs | 1 - ocicrypt-rs/build.rs | 5 ++ .../src/utils/ttrpc/keyprovider_ttrpc.rs | 1 - 12 files changed, 84 insertions(+), 23 deletions(-) diff --git a/api-server-rest/build.rs b/api-server-rest/build.rs index 7d9b6afee..781cbc9a4 100644 --- a/api-server-rest/build.rs +++ b/api-server-rest/build.rs @@ -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) @@ -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(()) diff --git a/api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs b/api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs index 60544380d..675e8561d 100644 --- a/api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs +++ b/api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs @@ -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)] diff --git a/api-server-rest/src/ttrpc_proto/confidential_data_hub_ttrpc.rs b/api-server-rest/src/ttrpc_proto/confidential_data_hub_ttrpc.rs index cb05c103c..07012c55a 100644 --- a/api-server-rest/src/ttrpc_proto/confidential_data_hub_ttrpc.rs +++ b/api-server-rest/src/ttrpc_proto/confidential_data_hub_ttrpc.rs @@ -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)] diff --git a/attestation-agent/kbs_protocol/build.rs b/attestation-agent/kbs_protocol/build.rs index 5bb896da4..704457c90 100644 --- a/attestation-agent/kbs_protocol/build.rs +++ b/attestation-agent/kbs_protocol/build.rs @@ -46,6 +46,11 @@ fn main() -> Result<(), Box> { "client: client", "client", )?; + replace_text_in_file( + "src/token_provider/aa/attestation_agent_ttrpc.rs", + "#![allow(box_pointers)]\n", + "", + )?; } Ok(()) diff --git a/attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent_ttrpc.rs b/attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent_ttrpc.rs index bd1035f9d..a2ff57e23 100644 --- a/attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent_ttrpc.rs +++ b/attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent_ttrpc.rs @@ -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)] diff --git a/confidential-data-hub/hub/build.rs b/confidential-data-hub/hub/build.rs index 7e8404875..502cf3059 100644 --- a/confidential-data-hub/hub/build.rs +++ b/confidential-data-hub/hub/build.rs @@ -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")] diff --git a/confidential-data-hub/hub/src/bin/protos/api_ttrpc.rs b/confidential-data-hub/hub/src/bin/protos/api_ttrpc.rs index a4eeab810..7142428e3 100644 --- a/confidential-data-hub/hub/src/bin/protos/api_ttrpc.rs +++ b/confidential-data-hub/hub/src/bin/protos/api_ttrpc.rs @@ -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)] diff --git a/confidential-data-hub/hub/src/bin/protos/keyprovider_ttrpc.rs b/confidential-data-hub/hub/src/bin/protos/keyprovider_ttrpc.rs index 52b823b60..059b79f72 100644 --- a/confidential-data-hub/hub/src/bin/protos/keyprovider_ttrpc.rs +++ b/confidential-data-hub/hub/src/bin/protos/keyprovider_ttrpc.rs @@ -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)] diff --git a/image-rs/build.rs b/image-rs/build.rs index 2d4bfcac1..e07ba4dd0 100644 --- a/image-rs/build.rs +++ b/image-rs/build.rs @@ -3,25 +3,53 @@ // SPDX-License-Identifier: Apache-2.0 // -use anyhow::*; - -fn main() -> Result<()> { +fn main() -> Result<(), Box> { #[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(()) } diff --git a/image-rs/src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs b/image-rs/src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs index f412ded9b..5e8aebecf 100644 --- a/image-rs/src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs +++ b/image-rs/src/resource/kbs/ttrpc_proto/getresource_ttrpc.rs @@ -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)] diff --git a/ocicrypt-rs/build.rs b/ocicrypt-rs/build.rs index 477a4dbe4..17febfb8d 100644 --- a/ocicrypt-rs/build.rs +++ b/ocicrypt-rs/build.rs @@ -50,6 +50,11 @@ fn main() -> Result<(), Box> { "client: client", "client", )?; + replace_text_in_file( + "src/utils/ttrpc/keyprovider_ttrpc.rs", + "#![allow(box_pointers)]\n", + "", + )?; } Ok(()) diff --git a/ocicrypt-rs/src/utils/ttrpc/keyprovider_ttrpc.rs b/ocicrypt-rs/src/utils/ttrpc/keyprovider_ttrpc.rs index e485751fd..9a68b073e 100644 --- a/ocicrypt-rs/src/utils/ttrpc/keyprovider_ttrpc.rs +++ b/ocicrypt-rs/src/utils/ttrpc/keyprovider_ttrpc.rs @@ -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)]