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/
libsafe_app.so
libsafe_app.rlib
libsafe_app.a

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/
libsafe_app-98e60e5e55f57beb.so
libsafe_app-98e60e5e55f57beb.a
libsafe_app-98e60e5e55f57beb.rlib

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?

Thanks!

1 Like

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.

1 Like

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

{
   "reason":"compiler-message",
   "package_id":"safe_app 0.1.0 (path+file:///home/...)",
   "target":{
      "kind":["rlib","cdylib","staticlib"],
      "name":"safe_app",
      "src_path":"/home/..."
   },
   "message":{
      "children":[],
      "code":null,
      "level":"note",
      "message":"library: util",
      "rendered":null,
      "spans":[]
   }
}

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:

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

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

~/trash
λ 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...

1 Like

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

Thanks for your comments and help @matklad!