Marwes / schemafy

Crate for generating rust types from a json schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build fails if rustfmt is not installed

adeschamps opened this issue · comments

Building schemafy without rustfmt installed results in an error:

   Compiling schemafy v0.4.5-alpha.0 (/home/anthony/git/schemafy)
error: failed to run custom build command for `schemafy v0.4.5-alpha.0 (/home/anthony/git/schemafy)`
process didn't exit successfully: `/home/anthony/git/schemafy/target/debug/build/schemafy-4f7c26bda0bcdbc9/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=src/schema.json

--- stderr
error: 'rustfmt' is not installed for the toolchain '1.34.0-x86_64-unknown-linux-gnu'
To install, run `rustup component add rustfmt --toolchain 1.34.0-x86_64-unknown-linux-gnu`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: StringError("")', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

If it's okay to have the build succeed even if rustfmt fails, then I think that all that needs to be done is remove the ? from the following, and possibly replace it with let _ = format(command, &output) in order to silence the warning from an unused Result.

schemafy/src/lib.rs

Lines 623 to 626 in 1d0ae91

Ok(match self.rustfmt_cmd {
Some(command) => format(command, &output)?,
None => output,
})

Alternatively, we could try to detect whether rustfmt is installed in build.rs and then only run it if it's present. Whichever you'd prefer, I'm happy to open a PR.

Thanks for reporting! I made some changes to make this crate into a procedural macro instead with #22 which also removes the rustfmt dependency (regenerating the internal schema is done on demand when developing).