Skip to content

Make --crate-file-name obey --crate-type #13489

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

Closed
wants to merge 1 commit into from
Closed

Make --crate-file-name obey --crate-type #13489

wants to merge 1 commit into from

Conversation

JustAPerson
Copy link
Contributor

Before, the --crate-file-name flag only checked crate attributes for
possible crate types. Now, if any type is specified by one or more
--crate-type flags, only the filenames for those types will be
emitted, and any types specified by crate attributes will be ignored.

@alexcrichton
Copy link
Member

I'm a little confused by this description, Here's what I get today:

$ cat foo.rs
#![crate_type = "dylib"]

fn main() {}
$ rustc --crate-file-name foo.rs --crate-type=rlib 
libfoo-aab0fa9e-0.0.dylib
libfoo-aab0fa9e-0.0.rlib

This makes me think that crate-file-name is reading both the compiler flags and the attributes (hence I'm confused about the first sentence of the PR description).

What's the intended behavior you're looking for here? I wouldn't want --crate-file-name to only look at the compiler flags when the rest of the compiler looks at both. Having compiler flags override attributes was brought up in #11573.

@JustAPerson
Copy link
Contributor Author

Oh my. I am mistaken there. I was adding some debugging statements to the relevant code and when I tested it with both flags + attributes I thought I only saw the filenames from the attributes. I think I accidentally just used a flag for a crate type that was already specified by attribute. Sorry about that :(

My intent is the same as issue #11573. I was motivated to attempt this because when writing a Makefile for a project, I noticed that after updating a library it began to build twice unnecessarily. A new crate_type attribute had been added, and now --crate-file-name returned two names, causing make to generate two dependencies where there had previously only been one. I at first filtered only the filename I wanted, but later remembered the --crate-type and wanted to see if that would solve my problem. I had the same expectations expressed in that issue.

@alexcrichton
Copy link
Member

I do agree that implementing #11573 would make makefiles a little easier, and would make compilation probably a little more intuitive.

Fixing the bug would likely involve modifying collect_crate_types and then updating the relevant documentation about linkage. For now though, I don't think that we want to modify just crate-file-name and not compilation, so I'm going to close this.

Feel free to reopen if you're willing to take a stab at #11573 though!

@JustAPerson
Copy link
Contributor Author

I have modified both collect_crate_types and the relevant documentation. This addresses both my original concern and #11573.

You can see my changes here:
https://github.com/JustAPerson/rust/compare/crate-file-name
(the diff is slightly more complicated than necessary due to indenting some of the code).

I don't think that I can reopen this pull request myself, and it appears that GitHub is not registering the new commits to my branch here because this is closed. At your discretion, I can either update the original post for this pull request once reopened or create a new one.

@alexcrichton alexcrichton reopened this Apr 13, 2014
@alexcrichton
Copy link
Member

That looks good to me! Can you add a test for this change as well? You'd probably want to add a run-make test in the src/test/run-make directory.

Before, normal compilation and the --crate-file-name flag would
generate output based on both #![crate_type] attributes and
--crate-type flags. Now, if one or more flag is specified by command
line, only those will be used.

Closes #11573.
@JustAPerson
Copy link
Contributor Author

@alexcrichton,
Hiya, I've added a run-make test now. Sorry for the delay!

bors added a commit that referenced this pull request Apr 15, 2014
Before, the `--crate-file-name` flag only checked crate attributes for
possible crate types. Now, if any type is specified by one or more
`--crate-type` flags, only the filenames for those types will be
emitted, and any types specified by crate attributes will be ignored.
@bors bors closed this Apr 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants