Build Script to compile another crate for different target


I'm writing a server which needs to distribute a library written in Rust, compiled into JavaScript with Cargo. Because the server and the library both wraps the same parser, I figured it would make sense to do this in a build script for the server so that the JavaScript library could be updated and prepared for distribution automatically.

So I wrote a small build script which calls the Cargo library to compile the JavaScript library. But the problem seems to be that this call to Cargo runs as a separate process and therefore has to wait for the parent compile process to finish. Which of course leads to a lock.

My question is essentially if there is a way to tell Cargo to build and depend on a crate built for another target?

I'm working on a project that I think has a similar goal than what you are going after. I'm working on a full stack rust web framework. The user will have one front end crate that targets emscripten, one server crate and a common library between the two.

Unfortunately I couldn't find a way to easily do this in with cargo. I've written a utility that sits on top of cargo that helps orchestrate these builds. If you want, I'll update here with a link to source when its in a semi-usable state.

1 Like