Hash appended to a target file name: is it regression or a feature?


Cargo/rustc behavior has changed from 1.14 to 1.15 when compiling libraries within workspaces.
E.g. compare the output for 1.14:

$ cargo build --release
Compiling safe_app v0.1.0
$ ls ../target/release/deps/

And there’s also libsafe_app.so in target/release.

Now, after I’ve switched my toolchain to 1.15, a hash is appended to output file names:

$ cargo build --release
Compiling safe_app v0.1.0
$ ls ../target/release/deps/

Besides, there’s nothing in the target/release/ directory.

Is that an intended behavior or a new feature (perhaps this one?) or a regression bug introduced in 1.15?



I believe that binary names produced by cargo are not stable and subject to change. If you execute cargo build --message-format=json you will get JSON messages on the stdout describing what was build where.


I’ve tried and it doesn’t seem to output anything helpful. Basically, just messages like

   "package_id":"safe_app 0.1.0 (path+file:///home/...)",
      "message":"library: util",

which is analogous to

Compiling safe_app v0.1.0 (file:///home/...)

However, if you run with cargo build --verbose, it does output a hash appended to the target, like -C extra-filename=-a7b7cff85ac8d04b but not in the JSON format.


And I think this is almost definitely a bug because for non-workspace projects the output library is copied to target/release/ with a clear name like libsafe_app.so.

Can anyone confirm this before I file an issue to rust-lang/cargo?


I think it’s better to open an issue and ask @alexcrichton

But it does seem that workspaces should influence target directory: all crates in the workspace share the same target directory, and different packages in the workspace can have artifacts with the same name, so putting everything directly in target/release does not seem possible.

JSON seems to work for me:

λ cargo --version
cargo 0.16.0-nightly (6e0c18c 2017-01-27)

λ cargo new --bin hello
     Created binary (application) `hello` project

λ cd hello/

~/trash/hello master*
λ cargo build --message-format=json
   Compiling hello v0.1.0 (file:///home/user/trash/hello)
{"features":[],"filenames":["/home/user/trash/hello/target/debug/deps/hello-42b407695ccd6842"],"package_id":"hello 0.1.0 (path+file:///home/user/trash/hello)","profile":{"debug_assertions":true,"debuginfo":true,"opt_level":"0","test":false},"reason":"compiler-artifact","target":{"kind":["bin"],"name":"hello","src_path":"/home/user/trash/hello/src/main.rs"}}
    Finished debug [unoptimized + debuginfo] target(s) in 0.37 secs

note the filenames key. But I only get this message if I do a fresh build…


Raised issue: https://github.com/rust-lang/cargo/issues/3698

Thanks for your comments and help @matklad!