Skip to content

Commit 87608c1

Browse files
authored
fix(stageleft_tool): handle custom lib.path in project manifest (#40)
1 parent 186157e commit 87608c1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

stageleft_tool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ syn = { version = "2.0.46", features = ["parsing", "extra-traits", "visit"] }
1818
proc-macro2 = "1.0.74"
1919
sha2 = "0.10.0"
2020
prettyplease = "0.2.0"
21-
toml_edit = "0.22.24"
21+
toml_edit = { version = "0.22.24", features = ["parse"] }
2222
proc-macro-crate = "3.3"
2323

2424
[dev-dependencies]

stageleft_tool/src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,21 @@ pub fn gen_staged_trybuild(
525525
pub fn gen_staged_pub() {
526526
let out_dir = env::var_os("OUT_DIR").unwrap();
527527

528-
let flow_lib_pub = gen_staged_mod(Path::new("src/lib.rs"), parse_quote!(crate), None);
528+
let raw_toml_manifest =
529+
fs::read_to_string(Path::new("Cargo.toml")).unwrap().parse::<DocumentMut>().unwrap();
530+
531+
let maybe_custom_lib_path = raw_toml_manifest
532+
.get("lib")
533+
.and_then(|lib| lib.get("path"))
534+
.and_then(|path| path.as_str());
535+
536+
let flow_lib_pub = gen_staged_mod(
537+
maybe_custom_lib_path
538+
.map(Path::new)
539+
.unwrap_or_else(|| Path::new("src/lib.rs")),
540+
parse_quote!(crate),
541+
None,
542+
);
529543

530544
fs::write(
531545
Path::new(&out_dir).join("lib_pub.rs"),
@@ -559,8 +573,6 @@ pub fn gen_staged_deps() {
559573
prettyplease::unparse(&parse_quote!(#deps_file)),
560574
)
561575
.unwrap();
562-
563-
println!("cargo::rerun-if-changed=Cargo.toml");
564576
}
565577

566578
#[macro_export]
@@ -572,6 +584,7 @@ macro_rules! gen_final {
572584
println!("cargo::rustc-check-cfg=cfg(feature, values(\"stageleft_macro_entrypoint\"))");
573585
println!("cargo::rustc-cfg=stageleft_runtime");
574586

587+
println!("cargo::rerun-if-changed=Cargo.toml");
575588
println!("cargo::rerun-if-changed=build.rs");
576589
println!("cargo::rerun-if-env-changed=STAGELEFT_TRYBUILD_BUILD_STAGED");
577590

0 commit comments

Comments
 (0)