Skip to content

Can't pass flags to the compiler #60

Closed
@mahkoh

Description

@mahkoh

Updated description

Arbitrary flags cannot be passed through to the compiler.

Original Description

-O has to be the default.

Activity

steveklabnik

steveklabnik commented on Jun 25, 2014

@steveklabnik
Member

There will be toooooons of these eventually, yes.

npryce

npryce commented on Jul 4, 2014

@npryce

Until this is implemented, cargo cannot be used for cross compilation.

olsonjeffery

olsonjeffery commented on Jul 5, 2014

@olsonjeffery

+1 for passing flags to the compiler as a critical feature

japaric

japaric commented on Jul 6, 2014

@japaric
Member

-O has to be the default.

FWIW, I've forked cargo to always pass the "-O" flag to rustc.

huonw

huonw commented on Jul 6, 2014

@huonw
Member

-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).

alexcrichton

alexcrichton commented on Jul 7, 2014

@alexcrichton
Member

#140 has added cargo build --release to build with optimizations

alexchandel

alexchandel commented on Jul 18, 2014

@alexchandel

+1 for passing flags like --opt-level=3, -Z lto and --emit=obj via command line or manifest file.

alexchandel

alexchandel commented on Jul 18, 2014

@alexchandel

And -Z no-landing-pads.

changed the title [-]Can't pass flags to the compiler / no optimization possible[/-] [+]Can't pass flags to the compiler[/+] on Aug 3, 2014
xldenis

xldenis commented on Aug 4, 2014

@xldenis

@alexchandel you seem to be able to do this, right?

alexchandel

alexchandel commented on Aug 4, 2014

@alexchandel

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

thehydroimpulse commented on Aug 6, 2014

@thehydroimpulse

Being able to output object files and such would be super awesome!

bfops

bfops commented on Aug 9, 2014

@bfops

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

extra_rustc_args = ["--foo", "bar"]

to your Cargo.toml. No support yet for passing directly from the command line.

olsonjeffery

olsonjeffery commented on Aug 9, 2014

@olsonjeffery

👍 to arbitrary rustc flags

18 remaining items

MarkSwanson

MarkSwanson commented on Mar 4, 2015

@MarkSwanson

+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

huonw commented on Mar 4, 2015

@huonw
Member
maxlapshin

maxlapshin commented on May 25, 2015

@maxlapshin

This is very nice, but: erszcz/erlang-rust-nif#3
cargo cannot compile under MacOS X without adding specific flags.

alexcrichton

alexcrichton commented on May 26, 2015

@alexcrichton
Member

@maxlapshin would cargo rustc suffice for your use case?

zjjott

zjjott commented on Jun 19, 2015

@zjjott

Holy cargo....

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?

PeteX

PeteX commented on Nov 20, 2016

@PeteX

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

mulkieran commented on Dec 2, 2016

@mulkieran

@PeteX It helped me, thanks!

learnopengles

learnopengles commented on Jan 11, 2017

@learnopengles

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

Manishearth commented on Apr 4, 2018

@Manishearth
Member

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

added a commit that references this issue on Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @maxlapshin@olsonjeffery@steveklabnik@npryce@alexcrichton

        Issue actions

          Can't pass flags to the compiler · Issue #60 · rust-lang/cargo