-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Comments
I think this can be solved with |
How does What I'm thinking of is the ability to specify the output name of the executable in |
Yes |
I would like to express interest in this feature as well. |
yes, +1 for this feature |
One whole year and still nothing... |
+1 for this feature. |
+1 for this feature |
Yes, please :) |
@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 |
@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.) |
+1. I wouldn't want to change my pretty
to
|
+1 for this too |
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]]
name = "some-valid-crate-name"
filestem = "invalid.crate.name but valid-ish file $name" Basically the Some things to note for the implementation here:
|
I need this feature for a |
Hello @alexcrichton. I want to make certain I understand what you have in mind. Your suggestion, |
One could argue that these plugins should not be |
Note that I was also just spitballing, we could also switch it to using |
I would also like to +1 this with the possibility of allowing feature based filenames. So something like |
I spent some time working on @alexcrichton's suggestions and implemented most of the data plumbing, but I ran into some issues. Basically, the |
Nowadays it's probably best to use the
I think that'll work better in conjunction with all the other outputs we're getting from rustc right now. |
Maybe it can work, but not under test.
build.gradle
// …..
// Build with cargo
tasks.create(name: "cargo-build-${arch}-${buildType}", type: Exec, description: "Building core for ${arch}", dependsOn: "cargo-output-dir-${arch}-${buildType}") {
doFirst { println("\n============================== Start Compile Native Lib ==============================\n") }
workingDir rustBasePath
environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=${project.ext.cargo_target_directory}/${target}/${buildType}/libabc.so")
if (buildType.equalsIgnoreCase("release")) {
commandLine 'cargo', 'build', "--color=always", "--target=${target}", '--release'
} else {
commandLine 'cargo', 'build', "--color=always", "--target=${target}"
}
doLast { println("\n============================== Finish Compile Native Lib ==============================\n") }
}
// …..
|
@alexcrichton Maybe |
Sounds like a great idea to me! |
@dherman the most common case for that is that debuginfo on mac and windows is in a separate file. So you get I also have vague recollections that emscripting used to spit out I don't have exact details about how that works? Ie, how rustc's |
This makes me wonder if letting users override the full filename might be a bad idea, since there may not be a single file. It might be that @alexcrichton's idea of (For my use case, it's got me leaning towards doing the final copying for myself, and just wrapping |
I personally feel that both make sense. I think that if you asked for a specific filename on Emscripten and rustc doesn't support that then it should error, but naming a shared library on Linux something arbitrary I don't think should be blocked because Windows has PDB files that need to be named something (for example). Basically I still fill that both are probably warranted. |
Sounds like a good idea, it would be very convenient when the crate name is quite long. |
Would love to see the ability to specify the name of the inferred main.rs binary target. Just a note, you can:
and the main bin will not longer be auto-discovered and
for aesthetics. |
While I agree that it would be nice for aesthetics and/or convenience, personally I want this feature so that I can produce executables that have names not allowed by the current scheme (e.g. |
Just tested and you can also:
The name applies to the auto-discovered main target (no duplicate binary target is created). |
Unfortunately if the name isn't in snake case (or kebab case) you'll get a warning ( |
We used to have application binaries called foo.cli and foo.gui and unfortunately we can't switch to rust because this issue breaks backwards compatibility. All in all it's kinda silly that applications have a crate name tho, it's not like that's ever gonna be exposed anywhere, and it's not like there are macros to get the crate name at compile-time or anything. Why not just set the crate name the same for all applications, and/or remove the concept of crate name from rust applications? |
You can actually get the crate name at compile time. And crate names for application aren't « silly » as you say, they are necessary for crates.io (for both installation and searching.). |
This isn't true (entirely), I have the following and I do not get any errors when calling [package]
name = "krate_name"
[[bin]]
name = "krate-name"
path = "src/bin/krate_name.rs" It seems to also support kebab-case. |
Yeah I forgot about that, edited. The warning explicitly says snake case, so I guess that's an oversight. Snake case is preferred over kebab case IIRC. |
Hi everyone,
@alexcrichton @ehuss please correct me if I'm wrong about the above requirements. @rustbot claim |
Ability to specify the output name for a bin target different from the crate name Hi, I have opened this to close the following issue #1706 . I have decided to start by writing a test to outline what behavior is expected from `Cargo`. As of now, this test fails (for obvious reasons). I will now start writing the code needed to pass this test. This is my first time contributing to cargo. Please, feel free to let me know if there are any protocols/processes that need to be followed. I'm a newbie at this. Closes issue #1706
Such a good suggestion. I'm writing a plugin atm and I have a post-install script that renames the resulting "lib", since it's prefixed with |
As far as I know, the only way to name the output of a bin target is through the
name
attribute of abin
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.
The text was updated successfully, but these errors were encountered: