I have a workspace project with multiple packages. The two important ones are:
flowc
- which is a lib and a binaryflowstdlib
flowc
is a kind of compiler that I build as part of the project.
flowstdlib
has a build script, that uses the flowc
built binary to build that package (generate "code", files etc), so I need the flowc
compiler ready when flowstdlib
is to be built.
In cargo.toml
of flowstdlib
I define flowc
as a build dependency:
[build-dependencies]
flowc = {path = "../flowc", version = "0.31.0" }`
(I've tried making it also a dependency, but no change)
in the build.rs
of flowstdlib
I look for it in the path, and if not found in the ../target/debug/flowc
location:
let flowc = if Path::new(env!("CARGO_MANIFEST_DIR")).join("../target/debug/flowc").exists() {
"../target/debug/flowc"
} else if Simpath::new("PATH").find_type("flowc", FileType::File).is_ok() {
"flowc"
} else {
""
};
When I run the build, it looks like it's trying to build multiple packages at the same time in parallel:
Compiling flowstdlib v0.31.0 (/Users/andrew/workspace/flow/flowstdlib)
Compiling flowsamples v0.31.1 (/Users/andrew/workspace/flow/samples)
warning: Could not find `flowc` in $PATH or `target/debug`, so cannot build flowstdlib
error: failed to run custom build command for `flowsamples v0.31.1 (/Users/andrew/workspace/flow/samples)`
and the flowstdlib
build fails as flowc
binary is not built yet.
Since the build continues and eventually finishes building flowc
, if I re-run the build, it will work the second time around (as flowc
binary is now found).
So:
- it looks like a
build-dependency
does wait for the depended-on binary to be built (maybe it waits for the library to be built, hard to tell)
Question
How I can make the build of flowstdlib
wait for the completion of the flowc
binary?
(without forcing a non-parallel build)
Pending the RFC landing, my workaround is to split the build into two commands (I'm using a Makefile to invoke them currently):