Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARGO_MAKE_CRATE_TARGET_DIRECTORY does not respect workspace #557

Closed
pheki opened this issue May 4, 2021 · 3 comments
Closed

CARGO_MAKE_CRATE_TARGET_DIRECTORY does not respect workspace #557

pheki opened this issue May 4, 2021 · 3 comments
Assignees
Labels

Comments

@pheki
Copy link

pheki commented May 4, 2021

Describe The Bug

If a crate is in a workspace, CARGO_MAKE_CRATE_TARGET_DIRECTORY will still be in the current directory instead of the root of the workspace

To Reproduce

  • Create workspace directory and add project to it:
$ mkdir workspace
$ cd workspace
$ cargo new project
  • Create virtual manifest for workspace, adding project to it
$ cat << EOF > Cargo.toml
[workspace]
members = ["project"]
EOF
  • Add Makefile to print CARGO_MAKE_CRATE_TARGET_DIRECTORY (remove the additional \ before $ if you're editing the file manually)
$ cd project
$ cat << EOF > Makefile.toml
[env]
TARGET_DIR = "abc"

[tasks.print-target-dir]
script = '''
echo Target Dir: \${CARGO_MAKE_CRATE_TARGET_DIRECTORY}
'''
EOF
  • Run print-target-dir task for project
$ cargo make print-target-dir

Output

$ cargo make print-target-dir
[cargo-make] INFO - cargo make 0.32.17
[cargo-make] INFO - Project: project
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: print-target-dir
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: print-target-dir
Target Dir: target
[cargo-make] INFO - Build Done in 0.03 seconds.

Found target: (equivalent to) /path/to/workspace/project/target
Expected target: /path/to/workspace/target

The expected target can be found by running cargo metadata, in key target_directory:

$ cargo metadata --format-version 1 --no-deps

(Possible) Solution

I would personally suggest using cargo metadata to get the target directory, instead of trying to guess it by manually looking at the environment.

@sagiegurari
Copy link
Owner

@pheki thanks a lot for the feedback :)

@ark0f worth to check suggestion from @pheki before pushing #554
i actually already trigger cargo metadata as part of the flow so we can use this info as suggeted.

@ark0f
Copy link
Contributor

ark0f commented May 4, 2021

@ark0f worth to check suggestion from @pheki before pushing #554

Really good suggestion, already in PR

@pheki
Copy link
Author

pheki commented May 4, 2021

Fixed by #554 (thanks!)

@pheki pheki closed this as completed May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants