#Script-ey or CLI-ey things that can still run when main project won't compile

8 messages · Page 1 of 1 (latest)

opal dove
#

I have e.g. a codegen task that (say) creates a file generated.rs. This is partly in Rust and it also calls out to an external command.

I tried having a cli binary and adding a codegen subcommand with clap etc. but my problem is that, when my codegen is misconfigured, generated.rs may have compiler errors that prevent the whole project from compiling, and thus I can't re-run my codegen command to fix the problem.

I've moved to a completely external script using rust-script, but of course this means I can't re-use code easily from the project, and (at least my) IDE support for rust-script is pretty poor.

Is there a better way to do this? Maybe this is a case for workspaces? Although I've not used them before.

worthy dagger
#

maybe generating in build.rs then using include! ?

#

or using a proc macro ig

opal dove
#

yeah I considered these but in reality it's generating types from my DB and I kind of like controlling when the gen happens manually, since otherwise running the DB becomes a dep for building the project... although maybe doing that does give tighter guarantees that the types are matching up with the DB state at all times

rustic bronze
#

a workspace will solve this problem

#

define your cli in a separate package, in the same workspace, which does not depend on the package that uses the generated code