Skip to content
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

Fix building multiple binaries that do not have path spacified in Cargo.toml #3609

Merged
merged 4 commits into from
Feb 2, 2017

Conversation

jmatraszek
Copy link
Contributor

When multiple binaries are specified in Cargo.toml, the binaries that do not have path specified are build from src/main.rs. Discovered here: rust-lang-nursery/thanks#40 (comment).

This was caused by setting for a binary a main layout here https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml.rs#L478, which caused normalize to not fallback to default binary path here https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml.rs#L1149 (as bin.path was always Some("/path/to/main.rs").

Added a test and fixed this by not using layout.main(), so right now for bins without path specified we fallback to default path inferred from bin's name (e.g. src/bin/foo.rs), test if the file exists and only if it doesn't -- fallback to src/main.rs.

I do not have any knowledge about Cargo's design, so I am not sure if this is the proper place to test for file existence.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@jmatraszek
Copy link
Contributor Author

Ups, seems that I have broken the build. Unfortunately, I am not able to make cross-compilation test to work on my machine, so I am not able to run the tests locally. Are there any guide for running cargo test (especially those that include cross-compilation)?

@alexcrichton
Copy link
Member

@jmatraszek looks great to me, thanks for the PR! The test failures look like it's just overly-pedantic path matching in the test, so you should be able to just relax the assertions with some well-placed [..] to fix them.

Otherwise to run cross-compilation tests locally if you're using rustup you can just install the targets through rustup:

rustup target add i686-unknown-linux-gnu

@jmatraszek
Copy link
Contributor Author

Hi @alexcrichton,
Tried adding a target using rustup, but couldn't even compile cargo as there were some problems with libraries on my machine. Used cross to cross-compile and reproduced the error. It seems this was caused by wrong manifest being generated for the test project (it did not include the actual binary source file, so the fallback to main.rs kicked in). Fixed this by adding an empty foo.rs file to the project in test.

BTW. Running tests by cross test --target i686-unknown-linux-gnu fails because the dependencies get updated (according to SemVer rule), but it seems that hamcrest had some API breaking changes in between 1.1.1 and 1.1.3 (https://gist.github.com/jmatraszek/bfaab45ae0d7aef0145af56ef770231a). Fixed this to run the tests by specifying hamcrest = "= 1.1.1" in Cargo.toml (haven't committed this though, used this just to run the tests).

@alexcrichton
Copy link
Member

@bors: r+

Ok well let's see what Travis says

@bors
Copy link
Contributor

bors commented Feb 1, 2017

📌 Commit d95983f has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 2, 2017

⌛ Testing commit d95983f with merge 2b63c4f...

bors added a commit that referenced this pull request Feb 2, 2017
Fix building multiple binaries that do not have path spacified in Cargo.toml

When multiple binaries are specified in Cargo.toml, the binaries that do not have `path` specified are build from `src/main.rs`. Discovered here: rust-lang-nursery/thanks#40 (comment).

This was caused by setting for a binary a main layout here https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml.rs#L478, which caused `normalize` to not fallback to default binary path here https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml.rs#L1149 (as `bin.path` was always `Some("/path/to/main.rs")`.

Added a test and fixed this by not using `layout.main()`, so right now for bins without `path` specified we fallback to default path inferred from bin's name (e.g. `src/bin/foo.rs`), test if the file exists and only if it doesn't -- fallback to `src/main.rs`.

I do not have any knowledge about Cargo's design, so I am not sure if this is the proper place to test for file existence.
@bors
Copy link
Contributor

bors commented Feb 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 2b63c4f to master...

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.

5 participants