I have a workspace with two crates; one builds a wasm library, and the other builds a http server (for using the wasm client lib). wasm-pack
is used to build the wasm library and generate its bindgen js file.
I'd like the http server crate to automatically build/generate the wasm library, and perform some post-processing on it. The naive solution to this is to call wasm-pack
on the wasm library crate from the http server's build script, and then have the build script do the post-processing. However, calling cargo build
from a build script on another crate that shares the same target-dir
causes a deadlock.
A primary reason I want to build the wasm library from the http server's build script is because I want the wasm library to be written to the http server's OUT_DIR
.
I need to find a way to build the wasm library at an alternative location that doesn't cause a deadlock. I can think of a few ways to do this, none make me happy, but some are more soul-crushing than others:
- Have the developer pass an environment variable to the alternative location. (This is the sort of thing I've been working hard to avoid since I started using
cargo
for project management, so it would be particularly painful to do this). - Use some de-facto standard location for temporary storage, like
$TMP
or$TEMP
. I don't like this either; Rust build directories can be massive, and it's kind of rude to dump massive amounts of data in tmp. - Based on the http server's
OUT_DIR
, traverse up the parent directories until an sibling target directory can be constructed that will avoid locking issues. The annoying thing with this is that the only guarantee cargo seems to provide with regards to the target directory, from a crate's build script's perspective, is thatOUT_DIR
is safe to use, but it doesn't say anything about it's specific location (read: depth) intarget-dir
.
Not to mention that for all of these cargo clean
won't clean the alternative target-dir
.
Looking for ideas on how to solve this, in particular if there are any prior art solutions that are not frowned upon [too much].