Skip to content

Build fails in Cargo workspace #12

@flxo

Description

@flxo

Hi,

when using cmd_lib in a crate that is part of a cargo workspace it get's confused because of a path relative CARGO_MANIFEST_DIR in source_text.rs.

 let __st_file: Vec<char> = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", file!()))

I check version 0.8.3 and latest HEAD.

For reproducing create a cargo workspace with a containing crate that uses cmd lib (I used one if the examples.

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:8:5
   |
8  | /     run_cmd!{
9  | |         cd $dir;
10 | |         pwd;
11 | |         sleep $gap;
12 | |         cd $f;
13 | |     }
   | |_____^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:17:5
   |
17 |     run_fun!(date +%Y)
   |     ^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:22:5
   |
22 |     run_cmd!(ls /tmp/nofile || true; echo "continue")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:23:5
   |
23 |     run_cmd!(cd /tmp; ls | wc -l;)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:24:5
   |
24 |     run_cmd!(pwd)?;
   |     ^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:27:5
   |
27 |     run_cmd!(echo $name)?;
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:28:5
   |
28 |     run_cmd!(|name| echo "hello, $name")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:29:5
   |
29 |     run_cmd!(du -ah . | sort -hr | head -n 5 | wc -w)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:31:18
   |
31 |     let result = run_fun!(du -ah . | sort -hr | head -n 5)?;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:8:5
   |
8  | /     run_cmd!{
9  | |         cd $dir;
10 | |         pwd;
11 | |         sleep $gap;
12 | |         cd $f;
13 | |     }
   | |_____^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:17:5
   |
17 |     run_fun!(date +%Y)
   |     ^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:22:5
   |
22 |     run_cmd!(ls /tmp/nofile || true; echo "continue")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:23:5
   |
23 |     run_cmd!(cd /tmp; ls | wc -l;)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:24:5
   |
24 |     run_cmd!(pwd)?;
   |     ^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:27:5
   |
27 |     run_cmd!(echo $name)?;
   |     ^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:28:5
   |
28 |     run_cmd!(|name| echo "hello, $name")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:29:5
   |
29 |     run_cmd!(du -ah . | sort -hr | head -n 5 | wc -w)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:31:18
   |
31 |     let result = run_fun!(du -ah . | sort -hr | head -n 5)?;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 18 previous errors

For more information about this error, try `rustc --explain E0433`.
error: could not compile `cmd_lib_workspace`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions