You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-O should probably be the default for dependencies since they are compiled rarely, but it would be nice for cargo build to default to the fastest option for the main code (i.e. no -O).
Thankfully, Cargo doesn't crash when passed extra unrecognized flags. For libraries, I partially hack around this issue by calling rustc afterwards on the last thing cargo builds.
Please add some target and emission specifications. The lib.crate-types key is completely ignored, AS IS #![crate_type = "staticlib"].
Cargo isn't the last step in many build cycles, and the inability to output object files or to compile static libraries is a huge inconvenience.
It should be noted that the design of cargo is currently to explicitly not allow arbitrary flags. It is very easy to have compilations go awry very quickly,
I just want to know,a project like servo,how to use cargo for minimize version using prefer-dynamic args?
I found this bug and got confused, so I thought I'd add a note for the benefit of other visitors. As of November 2016 it's perfectly possible to pass arbitrary flags to rustc. If you want to use dynamic libraries, for example, you can do either:
cargo rustc -- -C prefer-dynamic
or
RUSTFLAGS='-C prefer-dynamic' cargo build
Hope this helps someone!
sanmai-NL, Storyyeller, prdoyle, ldr709, norru and 10 more
There also seems to be flags like CARGO_TARGET_{target-triple in all caps and with "-" replaced by "_"}_LINKER which are still needed if, for example, you want to cross-compile the tests.
It should be noted that the design of cargo is currently to explicitly not allow arbitrary flags. It is very easy to have compilations go awry very quickly, and packages specifying flags for themselves is likely a decision that should not be up to the author but rather the builder.
I think this is a good argument for published dependencies, but less so for toplevel Cargo.tomls. We already have profiles for this, and ideally they'd be able to specify more. You can always override things via .cargo/config or editing the Cargo.toml.
This becomes frustrating because IDEs no longer work with projects forced to use RUSTFLAGS as part of their build process (e.g. Servo) since their build process is more than cargo build. At best they don't work, at worst they clobber builds to boot.
Really, even the ability to override this in .cargo/config ONLY would be quite useful. But it sounds very much like a profile thing.
Edit: My bad, it's possible to do this in the config already
Activity
steveklabnik commentedon Jun 25, 2014
There will be toooooons of these eventually, yes.
npryce commentedon Jul 4, 2014
Until this is implemented, cargo cannot be used for cross compilation.
olsonjeffery commentedon Jul 5, 2014
+1 for passing flags to the compiler as a critical feature
japaric commentedon Jul 6, 2014
FWIW, I've forked cargo to always pass the "-O" flag to rustc.
huonw commentedon Jul 6, 2014
-O
should probably be the default for dependencies since they are compiled rarely, but it would be nice forcargo build
to default to the fastest option for the main code (i.e. no-O
).alexcrichton commentedon Jul 7, 2014
#140 has added
cargo build --release
to build with optimizationsalexchandel commentedon Jul 18, 2014
+1 for passing flags like
--opt-level=3
,-Z lto
and--emit=obj
via command line or manifest file.alexchandel commentedon Jul 18, 2014
And
-Z no-landing-pads
.[-]Can't pass flags to the compiler / no optimization possible[/-][+]Can't pass flags to the compiler[/+]xldenis commentedon Aug 4, 2014
@alexchandel you seem to be able to do this, right?
alexchandel commentedon Aug 4, 2014
Thankfully, Cargo doesn't crash when passed extra unrecognized flags. For libraries, I partially hack around this issue by calling rustc afterwards on the last thing cargo builds.
Please add some target and emission specifications. The
lib.crate-types
key is completely ignored, AS IS#![crate_type = "staticlib"]
.Cargo isn't the last step in many build cycles, and the inability to output object files or to compile static libraries is a huge inconvenience.
thehydroimpulse commentedon Aug 6, 2014
Being able to output object files and such would be super awesome!
bfops commentedon Aug 9, 2014
I tried hacking together a fix for this at https://github.com/bfops/cargo. If people are willing to test for me, you can add
to your Cargo.toml. No support yet for passing directly from the command line.
olsonjeffery commentedon Aug 9, 2014
👍 to arbitrary rustc flags
18 remaining items
MarkSwanson commentedon Mar 4, 2015
+1 for LTO; we're thinking of building small shared objects in rust and deploying them inside Linux containers that have tight memory restrictions.
huonw commentedon Mar 4, 2015
One can get LTO by customising the relevant
profile
.cargo rustc
sondrele/thesis#16maxlapshin commentedon May 25, 2015
This is very nice, but: erszcz/erlang-rust-nif#3
cargo cannot compile under MacOS X without adding specific flags.
alexcrichton commentedon May 26, 2015
@maxlapshin would
cargo rustc
suffice for your use case?zjjott commentedon Jun 19, 2015
Holy cargo....
I just want to know,a project like servo,how to use cargo for minimize version using
prefer-dynamic
args?PeteX commentedon Nov 20, 2016
I found this bug and got confused, so I thought I'd add a note for the benefit of other visitors. As of November 2016 it's perfectly possible to pass arbitrary flags to rustc. If you want to use dynamic libraries, for example, you can do either:
cargo rustc -- -C prefer-dynamic
or
RUSTFLAGS='-C prefer-dynamic' cargo build
Hope this helps someone!
mulkieran commentedon Dec 2, 2016
@PeteX It helped me, thanks!
learnopengles commentedon Jan 11, 2017
There also seems to be flags like CARGO_TARGET_{target-triple in all caps and with "-" replaced by "_"}_LINKER which are still needed if, for example, you want to cross-compile the tests.
Manishearth commentedon Apr 4, 2018
I think this is a good argument for published dependencies, but less so for toplevel Cargo.tomls. We already have profiles for this, and ideally they'd be able to specify more. You can always override things via
.cargo/config
or editing the Cargo.toml.This becomes frustrating because IDEs no longer work with projects forced to use
RUSTFLAGS
as part of their build process (e.g. Servo) since their build process is more thancargo build
. At best they don't work, at worst they clobber builds to boot.Really, even the ability to override this in
.cargo/config
ONLY would be quite useful. But it sounds very much like a profile thing.Edit: My bad, it's possible to do this in the config already
Merge rust-lang#60