Skip to content

Commit

Permalink
Fallback to modifying src with build script to fix publishing
Browse files Browse the repository at this point in the history
Because of a bug(?) in cargo preventing subcommands like publish from
reading env variables set by the build script there isn't an effective way
currently to communicate the location of generated source files to pass to
include!()

This is potentially related to rust-lang/cargo#10094
  • Loading branch information
fmeef committed Dec 4, 2023
1 parent c2e1216 commit bf3cecd
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/target
**/*.rs.bk
out/*.rs
src/gen_types.rs
src/gen_methods.rs
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "botapi"
version = "0.0.30"
version = "0.0.34"
edition = "2021"
authors = [ "Alex Ballmer <gnu3ra@riseup.net" ]
description = "A mildly competent autogenerated telegram bot api wrapper"
Expand Down Expand Up @@ -31,5 +31,5 @@ tokio-test = "0.4.3"
ordered-float = { version = "4.1.1", features = ["serde"] }

[build-dependencies]
tggen = { path = "./generate", version = "0.0.30" }
tggen = { path = "./generate", version = "0.0.34" }
anyhow = "1.0.75"
6 changes: 4 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ fn main() -> Result<()> {
let gen = Generate::new(json)?;
let types = gen.generate_types()?;
let methods = gen.generate_methods()?;
let methods_path = std::env::var("OUT_DIR").unwrap() + "/gen_methods.rs";
let types_path = std::env::var("OUT_DIR").unwrap() + "/gen_types.rs";
let out_dir = "./src";
let methods_path = out_dir.to_owned() + "/gen_methods.rs";
let types_path = out_dir.to_owned() + "/gen_types.rs";
println!("cargo:rustc-env=BOT_GEN_DIR={}", out_dir);
fs::write(&types_path, types)?;

fs::write(&methods_path, methods)?;
Expand Down
2 changes: 1 addition & 1 deletion generate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tggen"
version = "0.0.30"
version = "0.0.34"
edition = "2021"
authors = [ "Alex Ballmer <gnu3ra@riseup.net" ]
description = "A mildly competent autogenerated telegram bot api wrapper (helper crate)"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub mod ext;
#[allow(unused_imports, rustdoc::bare_urls)]
/// Autogenerated REST api methods
pub mod gen_methods {
include!(concat!(env!("OUT_DIR"), "/gen_methods.rs"));
include!("gen_methods.rs");
}
///Autogenerated REST api types from json
#[allow(rustdoc::bare_urls)]
pub mod gen_types {
include!(concat!(env!("OUT_DIR"), "/gen_types.rs"));
include!("gen_types.rs");
}

0 comments on commit bf3cecd

Please sign in to comment.