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

Ability to specify the output name for a bin target different from the crate name #1706

Open
crumblingstatue opened this Issue Jun 11, 2015 · 15 comments

Comments

Projects
None yet
@crumblingstatue

crumblingstatue commented Jun 11, 2015

As far as I know, the only way to name the output of a bin target is through the name attribute of a bin section.

This, however, sets both the crate name and the output name.

It seems too restricting that the output name of an executable should be a valid crate name.
For example, it cannot contain spaces. Cargo also warns if it's uppercase, because crate names are lowercase by convention.

Rustc with the -o FILENAME option allows to set any arbitrary filename for the output.

If there is already a way to do this with cargo, it should be better documented, as I couldn't find it.

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Jun 11, 2015

I think this can be solved with cargo rustc (a relatively new subcommand), so I'm going to classify this as a docs bug.

@crumblingstatue

This comment has been minimized.

crumblingstatue commented Jun 11, 2015

How does cargo rustc solve this problem?

What I'm thinking of is the ability to specify the output name of the executable in Cargo.toml, so everyone who compiles it gets that executable name.

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Jun 11, 2015

Yes cargo rustc would not allow you to encode the value in Cargo.toml, cargo does not currently allow that level of configuration.

@ebkalderon

This comment has been minimized.

ebkalderon commented Jan 5, 2016

I would like to express interest in this feature as well.

@cutewalker

This comment has been minimized.

cutewalker commented Jul 11, 2016

yes, +1 for this feature

@VelocityRa

This comment has been minimized.

VelocityRa commented Jul 29, 2016

One whole year and still nothing...

@vityafx

This comment has been minimized.

vityafx commented Nov 14, 2016

+1 for this feature.

@Lakier15

This comment has been minimized.

Lakier15 commented Feb 1, 2017

+1 for this feature

@Boscop

This comment has been minimized.

Boscop commented Apr 9, 2018

Yes, please :)

@matklad

This comment has been minimized.

Member

matklad commented May 6, 2018

@brettcannon binary can have a name different from the name of he package, you can see it in Cargo toml in a [[bin]] section with the name key

@brettcannon

This comment has been minimized.

brettcannon commented May 6, 2018

@matklad yep, and I deleted my comment as it was incorrect; sorry about the noise; misunderstanding on my part when looking for a solution for my problem. (And feel free to hide this comment.)

@tzaeru

This comment has been minimized.

tzaeru commented May 16, 2018

+1.

I wouldn't want to change my pretty

[[bin]]
name = "server"
path = "src/server/main.rs"

to

[[bin]]
name = "SoundAnalyzerServer.exe"
path = "src/server/main.rs"
@manhnt9

This comment has been minimized.

manhnt9 commented Sep 25, 2018

+1 for this too

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Nov 15, 2018

This should in theory be a pretty easy issue to knock out if anyone's interested in implementing it! I'll try to leave some instructions here and if anyone has any questions please feel free to just let me know!

I think a basic design for this will probably look like a new key in the [[bin]] section:

[[bin]]
name = "some-valid-crate-name"
filestem = "invalid.crate.name but valid-ish file $name" 

Basically the filestem key (or something similarly named) would control the file that rustc actually literally emits, but is probably orthogonal from the crate name. As mentioned in the OP we'd implement this with the -o flag passed to rustc.

Some things to note for the implementation here:

  • Deserialization happens via this struct, which would need to grow a new optional field for this key.
  • Cargo's internal data structure is here. The TOML configuration would need to make its way to this internal data structure.
  • This will want to start off as an unstable feature. There's some documentation about adding features here to Cargo, and the call to require would happen wherever the internal Target is configured if the TOML key is Some
  • The actual -o flag would go somewhere around here where unit.target is the Target structure for Cargo, and cx.files().out_dir(unit) is the folder where the output file should go.
  • We'll probably want to only allow this on [[bin]] and [[example]] targets to start off. Configuring the file stem of a [lib] target should likely be an error
  • After that, a few simple tests for this new feature should suffice!
@m-ou-se

This comment has been minimized.

m-ou-se commented Nov 29, 2018

We'll probably want to only allow this on [[bin]] and [[example]] targets to start off. Configuring the file stem of a [lib] target should likely be an error

I need this feature for a [lib]. My use case: I write plugins for other software in Rust, which are technically shared libraries (crate-type = ["dylib"]: .so files, as I'm workig on Linux), but should be named something.plugin instead of libsomething.so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment