Add WATT support to cqrs-codegen (#3) #5
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3
cqrs-codegen
would build WATT-version of macro.cargo <command> --no-default-features --features no-watt
(or similar options inCargo.toml
, though command-line arguments won't work for crates inside workspaces, as--no-default-features
is ignored for workspaces;--features
also works in surprising ways in workspaces).cqrs-codegen/src/codegen.wasm
if it's present or build it, if it's absent andcqrs-codegen/impl
dir is available.cqrs-codegen/.watch-cqrs-codegen-impl
file, and thenbuild.rs
will try to be clever about rebuildingcodegen.wasm
, e.g., rebuild it, if sources incqrs-codegen/impl/src
changed.Problems and solutions
synstructure
can not be build forwasm32-unknown-unknown
targetsynstructure
in a fork and temporarily switchedcqrs-codegen
to itsynstructure
(though, it needs some further work)Single crate can't be used as a proc-macro-crate and some other crate-type at the same time
I.e., it's impossible for a crate to be a proc-macro-crate and also produce WASM binaries required for WATT. At least, not without some radical hacks.
Extracted
cqrs-codegen-impl
crate (located incqrs-codegen/impl
).Building WASM binaries for WATT requires using special WATT version of
proc_macro2
It also requires to use cargo
[patch]
section to patchproc_macro2
forsyn
andquote
as well. Which may be problematic in some cases, cause...In workspaces
[patch]
sections are only allowed in workspace root crate (and ignored everywhere else)However, setting required
[patch]
forproc_macro2
in workspace root is also problematic, cause...[patch]
sections patch dependencies for all dependencies as well and even for proc-macro dependenciesI.e., when patched, all proc-macro dependencies used in a crate/workspace would use this WATT version of
proc_macro2
, which is very likely to break stuff.The following workaround was found for the three problems above:
If an empty
[workspace]
section added toCargo.toml
of some member-of-workspace-crate, then when running cargo from this crate's root cargo won't treat it as part of workspace.So, to build
cqrs-codegen-impl
for WATT we can:cd <cqrs-codegen-impl-dir>
[workspace]
section toCargo.toml
cargo build --target wasm32-unknown-unknown --features watt
Cargo.toml
This solution was codified in
build.rs
forcqrs-codegen
crate, however, during work onbuild.rs
another smaller problem occured.It's impossible to recursively run cargo from
build.rs
As recursive cargo invocation would lock waiting for
target
directory to be released (which is locked by first cargo invocation, waiting forbuild.rs
to finish, i.e., deadlock).This can be circumvented by specifying separate
target
directory for recursive cargo calls.As, in our case, we are building
cqrs-codegen-impl
for other target and also with patched version ofproc_macro2
, it's not a problem at all (and, maybe, even desirable).