{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/cargo/issues/6160","repository_url":"https://api.github.com/repos/rust-lang/cargo","labels_url":"https://api.github.com/repos/rust-lang/cargo/issues/6160/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/cargo/issues/6160/comments","events_url":"https://api.github.com/repos/rust-lang/cargo/issues/6160/events","html_url":"https://github.com/rust-lang/cargo/issues/6160","id":368611865,"node_id":"MDU6SXNzdWUzNjg2MTE4NjU=","number":6160,"title":"--crate-type does not override lib properties on manifest","user":{"login":"bltavares","id":109474,"node_id":"MDQ6VXNlcjEwOTQ3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/109474?v=4","gravatar_id":"","url":"https://api.github.com/users/bltavares","html_url":"https://github.com/bltavares","followers_url":"https://api.github.com/users/bltavares/followers","following_url":"https://api.github.com/users/bltavares/following{/other_user}","gists_url":"https://api.github.com/users/bltavares/gists{/gist_id}","starred_url":"https://api.github.com/users/bltavares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bltavares/subscriptions","organizations_url":"https://api.github.com/users/bltavares/orgs","repos_url":"https://api.github.com/users/bltavares/repos","events_url":"https://api.github.com/users/bltavares/events{/privacy}","received_events_url":"https://api.github.com/users/bltavares/received_events","type":"User","site_admin":false},"labels":[{"id":166054475,"node_id":"MDU6TGFiZWwxNjYwNTQ0NzU=","url":"https://api.github.com/repos/rust-lang/cargo/labels/A-errors","name":"A-errors","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-10-10T11:04:00Z","updated_at":"2018-10-11T13:47:16Z","closed_at":null,"author_association":"NONE","body":"I've faced this recently, and I was surprised by the `--crate-type` flag behavior. I'm trying to work on a cross-platform library building script to be added on projects on [crossgen](https://github.com/yoshuawuyts/crossgen/issues/11) and it would be really nice if we could contain all the cross-platform bits on the build script.\r\n\r\nThe `Cargo.toml` was a default `--lib` project:\r\n\r\n```toml\r\n[project]\r\nname = \"example\"\r\nversion = \"0.0.1\"\r\n\r\n[lib]\r\n\r\n[dependencies]\r\n```\r\n\r\nWhen compiling with `cargo rustc --lib --release -- --crate-type staticlib` I expected this to take over the manifest and add the extra output type. To my surprise, no `libexample.a` was produced tho.\r\n\r\nDuring the experiments, passing in an invalid crate type as `RUSTFLAGS` seems to show that cargo is passing multiple `--crate-type` options down to `rustc`:\r\n\r\n```\r\n$  RUSTFLAGS=\"--crate-type example\" cargo rustc --lib --release\r\nerror: failed to run `rustc` to learn about target-specific information\r\n\r\nCaused by:\r\n  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type example --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)\r\n--- stderr\r\nerror: unknown crate type: `example`\r\n```\r\n\r\nShould the `--crate-type` override what is defined on cargo manifest? Is this something to add on the `cargo rustc` argument list instead of the other side of `--`?\r\n\r\nThis would help a lot to output different targets, such as C libs and wasm.\r\n\r\nThere are related issues:\r\n- https://github.com/rust-lang/cargo/issues/4881\r\n- https://github.com/rust-lang/rust/issues/51009"},"comment":{"url":"https://api.github.com/repos/rust-lang/cargo/issues/comments/428961728","html_url":"https://github.com/rust-lang/cargo/issues/6160#issuecomment-428961728","issue_url":"https://api.github.com/repos/rust-lang/cargo/issues/6160","id":428961728,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODk2MTcyOA==","user":{"login":"bltavares","id":109474,"node_id":"MDQ6VXNlcjEwOTQ3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/109474?v=4","gravatar_id":"","url":"https://api.github.com/users/bltavares","html_url":"https://github.com/bltavares","followers_url":"https://api.github.com/users/bltavares/followers","following_url":"https://api.github.com/users/bltavares/following{/other_user}","gists_url":"https://api.github.com/users/bltavares/gists{/gist_id}","starred_url":"https://api.github.com/users/bltavares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bltavares/subscriptions","organizations_url":"https://api.github.com/users/bltavares/orgs","repos_url":"https://api.github.com/users/bltavares/repos","events_url":"https://api.github.com/users/bltavares/events{/privacy}","received_events_url":"https://api.github.com/users/bltavares/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T13:47:16Z","updated_at":"2018-10-11T13:47:16Z","author_association":"NONE","body":"I think it was a mismatch of expectations more than the error message.\r\n\r\nFrom [Rust Docs](https://doc.rust-lang.org/reference/linkage.html):\r\n>  If one or more command line flags are specified, all crate_type attributes will be ignored in favor of only building the artifacts specified by command line.\r\n\r\nThis looks to be applied to `rustc` only (if I understood it correctly), while I had the expectation to also be applied to `cargo rustc`.\r\n\r\nShould I focus on a workaround editing the `Cargo.toml` to change the `crate-type` attribute on those build phases instead of making `--crate-type` a flag which cargo knows about?"}}
{"actor":{"display_login":"bltavares"}}