Marwes / schemafy

Crate for generating rust types from a json schema
MIT License
242 stars 51 forks source link

Build fails if rustfmt is not installed #20

Closed adeschamps closed 5 years ago

adeschamps commented 5 years ago

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.

https://github.com/Marwes/schemafy/blob/1d0ae918a0e781e82a5d7768f63a05880228534f/src/lib.rs#L623-L626

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.

Marwes commented 5 years ago

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).