I need different features for tonic-build, but it seems that cargo only recognizes the not(target_arch = "wasm32") branch. cargo tree --target=wasm32-unknown-unknown shows the same build-dependencies features as the x86 target.
Cargo’s documentation doesn’t seem to specify, but I imagine that it’s not working as you intend because the target in question is the host — the platform that the build script is being built for. You will have to enable features suitable for both cases, and use env("TARGET") to check what the main compilation target is.
No, I meant that your build-dependencies must include whatever dependencies, and features of those dependencies, are needed to be able to build in both cases, without attempting to make them conditional.
tonic-build is used to generate code for RPC protocols that will be compiled to the final target. But the default feature transport (which is needed in x86) of tonic-build will generate code that cannot compile in wasm32. That's why I need to turn off the default features of tonic-build in wasm32.
If so, then that is a flaw in the design of tonic-build. Features should be “additive” — enabling a feature should never make a library unable to be used in ways that would work with the feature disabled.
The only practical workaround I can offer is that you can make two packages — one dedicated to wasm32 and one not.