Skip to content

Commit 5cdcda5

Browse files
committed
Move generated file ttrpc.rs to OUT_DIR
Got: cargo publish --dry-run error: failed to verify package tarball Caused by: Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of OUT_DIR. Added: /home/tim/project/ttrpc-rust/target/package/ttrpc-0.4.0/src/ttrpc.rs This commit will resolve this issue. Signed-off-by: Tim Zhang <[email protected]>
1 parent e32f9d9 commit 5cdcda5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path::PathBuf;
4+
15
fn main() {
6+
let out_dir = env::var("OUT_DIR").unwrap();
7+
let path: PathBuf = [out_dir.clone(), "mod.rs".to_string()].iter().collect();
8+
fs::write(path, "pub mod ttrpc;").unwrap();
9+
210
protobuf_codegen_pure::Codegen::new()
3-
.out_dir("src")
11+
.out_dir(out_dir)
412
.inputs(&["src/ttrpc.proto"])
513
.include("src")
614
.run()

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ pub mod error;
2020
#[macro_use]
2121
pub mod common;
2222
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
23-
pub mod ttrpc;
23+
pub mod compiled {
24+
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
25+
}
26+
pub use compiled::ttrpc;
2427

2528
pub use crate::common::MessageHeader;
2629
pub use crate::error::{get_status, Error, Result};

0 commit comments

Comments
 (0)