Skip to content

Commit 1630d1f

Browse files
ahornbyfacebook-github-bot
authored andcommitted
autocargo/thrift: add support for rust_extra_srcs to fix mononoke OSS cargo build
Summary: Add support for rust_extra_srcs to autocargo and rust shed thrift wrapper. Copy extra sources to the cargo thrift build location so that the include!() can find them Mononoke started using them in D63977688, which is causing [github CI Cargo based builds to fail](https://github.com/facebook/sapling/actions/runs/11329919951/job/31506538796) with `error[E0583]: file not found for module 'extra_thrift'` Mononoke cargo build was also broken on missing scs_errors and scs_methods crate used from async_requests, hence the autocargo mapping update to include it in following diff D64541433 Reviewed By: andreacampi Differential Revision: D64541434 fbshipit-source-id: 118508175e4168b15e4c99dd63a6eaa34ac10c5e
1 parent 3b6a64b commit 1630d1f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • shed/thrift_compiler/src

shed/thrift_compiler/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub struct Config {
7777
clients_crate: Option<String>,
7878
options: Option<String>,
7979
include_srcs: Vec<PathBuf>,
80+
extra_srcs: Vec<PathBuf>,
8081
}
8182

8283
impl Config {
@@ -96,6 +97,7 @@ impl Config {
9697
clients_crate: None,
9798
options: None,
9899
include_srcs: vec![],
100+
extra_srcs: vec![],
99101
})
100102
}
101103

@@ -165,6 +167,13 @@ impl Config {
165167
self
166168
}
167169

170+
/// Set extra srcs to be copied into the generated crate.
171+
pub fn extra_srcs(&mut self, value: impl IntoIterator<Item = impl AsRef<Path>>) -> &mut Self {
172+
self.extra_srcs
173+
.extend(value.into_iter().map(|path| path.as_ref().to_owned()));
174+
self
175+
}
176+
168177
/// Transform a relative path so leading "../"'s are replaced with "_t".
169178
pub fn remap_to_out_dir(&self, path: &Path) -> PathBuf {
170179
let mut rem = path;
@@ -200,6 +209,15 @@ impl Config {
200209
}
201210
}
202211

212+
for extra_src in &self.extra_srcs {
213+
println!("cargo:rerun-if-changed={}", extra_src.to_string_lossy());
214+
if let GenContext::Types = self.gen_context {
215+
let out_path = self.remap_to_out_dir(extra_src);
216+
fs::create_dir_all(out.join(out_path.parent().unwrap()))?;
217+
fs::copy(extra_src, out.join(out_path))?;
218+
}
219+
}
220+
203221
if let [(_name, file)] = &input[..] {
204222
match self.gen_context {
205223
GenContext::Types => {

0 commit comments

Comments
 (0)