-
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
--crate-type does not override lib properties on manifest #6160
Comments
This seems to come from this line: cargo/src/cargo/core/compiler/build_context/target_info.rs Lines 85 to 90 in ce455cd
Am I heading to the right direction? |
This commit contains changes on the generated lib template to build cross-platform libs. With this changes, I was able to setup a [Travis] build with GitHub [Releases] of a cross-platform lib. It is not possible yet to build a different crate type only using command line args. It requires a modification on `Cargo.toml` to include new types of library outputs. I've already opened an issue on [cargo](rust-lang/cargo#6160) to see what should be the case here. Meanwhile, lib authors must change `Cargo.toml` and include the extra `crate-type` attribute with all the libs. Sadly, this also means that `LTO` optimisation is not available if the lib uses `lib` or `rlib` attributes. To avoid modifying the `Cargo.toml`, the sugestion would be that on a future PR we could add to the deploy script a modification on the `Cargo.toml` manifest to include the corresponding crate-type, and only such crate type for that target. This means we would be able to bring LTO and output smaller libs. Realated to: - yoshuawuyts#11 [Travis]: https://travis-ci.org/bltavares/rust-over-jna-example/builds/439439854 [Releases]: https://github.com/bltavares/rust-over-jna-example/releases/tag/initial
This commit contains changes on the generated lib template to build cross-platform libs. With this changes, I was able to setup a [Travis] build with GitHub [Releases] of a cross-platform lib. It is not possible yet to build a different crate type only using command line args. It requires a modification on `Cargo.toml` to include new types of library outputs. I've already opened an issue on [cargo](rust-lang/cargo#6160) to see what should be the case here. Meanwhile, lib authors must change `Cargo.toml` and include the extra `crate-type` attribute with all the libs. Sadly, this also means that `LTO` optimisation is not available if the lib uses `lib` or `rlib` attributes. To avoid modifying the `Cargo.toml`, the sugestion would be that on a future PR we could add to the deploy script a modification on the `Cargo.toml` manifest to include the corresponding crate-type, and only such crate type for that target. This means we would be able to bring LTO and output smaller libs. Realated to: - yoshuawuyts#11 [Travis]: https://travis-ci.org/bltavares/rust-over-jna-example/builds/439439854 [Releases]: https://github.com/bltavares/rust-over-jna-example/releases/tag/initial Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
Thanks for the report! Unfortunately though We could improve the error message here though for sure! |
@alexcrichton thanks for replying. In regard of the expected behavior for the flags. Should a lib that have not defined a crate-type produce both the Nowaday, both type of creates are produced. I would expect that the flags override whatever is defined on This also means that it is also not possible to pass What is the expected behavior of the CLI flag? |
@bltavares it's unfortunately basically not expected for manual specification of |
I think it was a mismatch of expectations more than the error message. From Rust Docs:
This looks to be applied to Should I focus on a workaround editing the |
Unfortunately there's not really a great way forward for something like this, but if editing |
Given how hard this would be, I would be ok to close this issue, even tho the error message is confusing. Would it be ok if I open a PR on Cargo with a note on the docs regarding this behavior? |
Ok sounds good to me! And certainly yeah, PRs improving docs are always appreciated! |
This commit contains changes on the generated lib template to build cross-platform libs. With this changes, I was able to setup a [Travis] build with GitHub [Releases] of a cross-platform lib. It is not possible yet to build a different crate type only using command line args. It requires a modification on `Cargo.toml` to include new types of library outputs. I've already opened an issue on [cargo](rust-lang/cargo#6160) to see what should be the case here. Meanwhile, lib authors must change `Cargo.toml` and include the extra `crate-type` attribute with all the libs. Sadly, this also means that `LTO` optimisation is not available if the lib uses `lib` or `rlib` attributes. To avoid modifying the `Cargo.toml`, the sugestion would be that on a future PR we could add to the deploy script a modification on the `Cargo.toml` manifest to include the corresponding crate-type, and only such crate type for that target. This means we would be able to bring LTO and output smaller libs. Realated to: - yoshuawuyts#11 [Travis]: https://travis-ci.org/bltavares/rust-over-jna-example/builds/439439854 [Releases]: https://github.com/bltavares/rust-over-jna-example/releases/tag/initial Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
s command `cargo` subcommand is exclusively intended to be used to help with [working arround](rust-lang/rust#51009) how crate types are defined, in order to help with cross-platform builds. It is currently [not possible](rust-lang/cargo#6160) to define a single `crate-type` override on `cargo build`, which causes libs intended to be used on other languages to compile more than one type of crate. This commit adds a dependency on this [new CLI app](https://github.com/bltavares/cargo-crate-type) to be able to workaround the limitations of Cargo. We are now able to enable the `-C lto` optimization again, as we will only compile a single type of artifact Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
* Improve lib template on Travis This commit contains changes on the generated lib template to build cross-platform libs. With this changes, I was able to setup a [Travis] build with GitHub [Releases] of a cross-platform lib. It is not possible yet to build a different crate type only using command line args. It requires a modification on `Cargo.toml` to include new types of library outputs. I've already opened an issue on [cargo](rust-lang/cargo#6160) to see what should be the case here. Meanwhile, lib authors must change `Cargo.toml` and include the extra `crate-type` attribute with all the libs. Sadly, this also means that `LTO` optimisation is not available if the lib uses `lib` or `rlib` attributes. To avoid modifying the `Cargo.toml`, the sugestion would be that on a future PR we could add to the deploy script a modification on the `Cargo.toml` manifest to include the corresponding crate-type, and only such crate type for that target. This means we would be able to bring LTO and output smaller libs. Realated to: - #11 [Travis]: https://travis-ci.org/bltavares/rust-over-jna-example/builds/439439854 [Releases]: https://github.com/bltavares/rust-over-jna-example/releases/tag/initial Signed-off-by: Bruno Tavares <connect+github@bltavares.com> * Define the type of artifact to be produced by cargo. s command `cargo` subcommand is exclusively intended to be used to help with [working arround](rust-lang/rust#51009) how crate types are defined, in order to help with cross-platform builds. It is currently [not possible](rust-lang/cargo#6160) to define a single `crate-type` override on `cargo build`, which causes libs intended to be used on other languages to compile more than one type of crate. This commit adds a dependency on this [new CLI app](https://github.com/bltavares/cargo-crate-type) to be able to workaround the limitations of Cargo. We are now able to enable the `-C lto` optimization again, as we will only compile a single type of artifact Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
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 and it would be really nice if we could contain all the cross-platform bits on the build script.The
Cargo.toml
was a default--lib
project:When 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, nolibexample.a
was produced tho.During the experiments, passing in an invalid crate type as
RUSTFLAGS
seems to show that cargo is passing multiple--crate-type
options down torustc
:Should the
--crate-type
override what is defined on cargo manifest? Is this something to add on thecargo rustc
argument list instead of the other side of--
?This would help a lot to output different targets, such as C libs and wasm.
There are related issues:
The text was updated successfully, but these errors were encountered: