-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
I noticed that cargo build
has two subcommands, both added this year. I believe this accurately describes their behavior:
--target-dir
: Replaces$PWD/target
with this directory (e.g. a debug build will be built intotarget-dir/debug
). Stable flag, added in April 2018. Add target directory parameter --target-dir #5393 In addition to CARGO_TARGET_DIR env var, support --target-dir command line option #5308. Mimicks the behavior ofCARGO_TARGET_DIR
--out-dir
: Things will be built into$PWD/target
as normal, but copies some of the artifacts into the directory specified byout-dir
(not a profile specific subdirectory). Unstable flag, added in March 2018. cargo build --out-dir #5203 Ability to specify output artifact name #4875. Mimicks the behavior ofOUT_DIR
.
(I'm not 100% certain I've accurately described their behavior in relationship to the profile specific subdirectories.)
--out-dir is still unstable, but --target-dir was instantly stabilized (by mistake, I believe).
I can't help but notice that these two flags do very similar things! They also seem to have been designed for very similar purposes (build integration, the meson project is mentioned specifically in both of them).
I'm not certain I agree that either of them should have been added as flags (an argument is made that flags are better than env vars, and while I agree in principle for user oriented APIs, I don't think that build system integration is a user oriented API in the relevant sense), but I'm definitely suspicious of having both of these very similar flags provided. Since target-dir is stable, I'm not sure if there's an available avenue to unify these flags other than just only providing target-dir.
cc @rust-lang/cargo