Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCan't pass flags to the compiler #60
Comments
This comment has been minimized.
This comment has been minimized.
|
There will be toooooons of these eventually, yes. |
This comment has been minimized.
This comment has been minimized.
npryce
commented
Jul 4, 2014
|
Until this is implemented, cargo cannot be used for cross compilation. |
This comment has been minimized.
This comment has been minimized.
olsonjeffery
commented
Jul 5, 2014
|
+1 for passing flags to the compiler as a critical feature |
This comment has been minimized.
This comment has been minimized.
FWIW, I've forked cargo to always pass the "-O" flag to rustc. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
#140 has added |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Jul 18, 2014
|
+1 for passing flags like |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Jul 18, 2014
|
And |
alexcrichton
referenced this issue
Aug 3, 2014
Closed
Cannot pass flags to rustc from cargo build. #313
alexcrichton
changed the title
Can't pass flags to the compiler / no optimization possible
Can't pass flags to the compiler
Aug 3, 2014
This comment has been minimized.
This comment has been minimized.
xldenis
commented
Aug 4, 2014
|
@alexchandel you seem to be able to do this, right? |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
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 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. |
This comment has been minimized.
This comment has been minimized.
thehydroimpulse
commented
Aug 6, 2014
|
Being able to output object files and such would be super awesome! |
This comment has been minimized.
This comment has been minimized.
bfops
commented
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. |
This comment has been minimized.
This comment has been minimized.
olsonjeffery
commented
Aug 9, 2014
|
|
This comment has been minimized.
This comment has been minimized.
|
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. We certainly plan on allowing more flavorful configuration that is possible today through profiles, but it will likely not just be "pass these flags through to the compiler". |
This comment has been minimized.
This comment has been minimized.
npryce
commented
Aug 10, 2014
|
@bfops - putting compiler flags into the TOML file won't work. Compiler flags have to be passed to Cargo from outside. For example, when cross-compiling a single program for different targets I need to pass different command-line flags (target triple, location of linker, etc.) for each target. |
This comment has been minimized.
This comment has been minimized.
npryce
commented
Aug 10, 2014
|
@alexcrichton - I think you should always allow the user to "break glass in case of emergency". At the moment, I cannot use Cargo as a build tool. So, for anyone doing cross compilation, it's useless. If you disallow passing flags to the rustc compiler you essentially couple the release cycles of Cargo and rustc, because Cargo will have to be changed to expose any new capabilities of rustc. But if you're going to couple Cargo and Rustc releases, you may as well pass compiler flags through, because Cargo can have built-in knowledge of the flags accepted by the rustc version it's coupled to, and be able to detect and reject invalid flags. |
This comment has been minimized.
This comment has been minimized.
bfops
commented
Aug 10, 2014
|
@npryce - I agree, flags in the TOML file isn't comprehensive. Once I'm done my exams, I'll try to continue development on my fork if another one hasn't taken off yet. Pull requests are always welcome too! I'm not sure I entirely understand your use case, sorry. With the current set-up, you'd have to have different targets for windows builds, linux builds, etc. Each target can have its own flags. But yes, right now in my fork they have to be baked into the TOML file. If arguments are specified on the command line (e.g. via |
This comment has been minimized.
This comment has been minimized.
npryce
commented
Aug 11, 2014
|
@bfops In my case, I'm cross-compiling from Ubuntu x86 to Raspbian on the Raspberry Pi, but there are lots of different single-board Linux computers (Beaglebone, etc.) that my programs could run on. Each target typically has its own toolchain -- C compiler, linker, C stdlib, etc. When using Rust, the C compiler is not used, but the linker and C stdlib is. At the moment I use Make for the build. I have a make include file per target (e.g. targets/raspi.mk) that defines the rustc flags for that target. My main makefile includes targets/$(target).mk. And I can pass the target to the make command: How Cargo should work, I don't know. Maybe the project's top-level cargo file should have a way of defining compiler arguments per target and be told the target as a command-line parameter. Or, just say that Cargo will never be flexible enough for all uses and don't support cross-compilation at all. Let Cargo do dependency resolution well and make it easy to invoke from an existing build tool like Make. |
This comment has been minimized.
This comment has been minimized.
bfops
commented
Aug 12, 2014
|
@npryce My current cargo fork allows specifying rustc command line flags on a per-target basis, the remaining step would be to make the target a command-line parameter, which seems like a good feature either way. I'll look into it. |
This comment has been minimized.
This comment has been minimized.
|
I'm going to close this issue as-is, as I don't think that it's particularly actionable any more. Support for per-project profiles recently landed which is how cargo plans to support customizing the build of a project. Right now profiles are pretty bare, only supporting If you currently have a use case which cargo isn't supporting, then please feel free to open a bug about it! Specific problems are greatly appreciated, and the general idea is that build-related options (like most of those in So in summary:
|
alexcrichton
closed this
Sep 4, 2014
This comment has been minimized.
This comment has been minimized.
|
#595 is an example of a subcommand which may help here, I'm curious about opinions on it! |
alexcrichton
referenced this issue
Oct 21, 2014
Closed
Allow supplying arbitrary arguments to rust via the cargo's command line #731
This comment has been minimized.
This comment has been minimized.
buster
commented
Dec 10, 2014
|
Currently i have a little rust program, that i would like to be compiled dynamically linked, because the resulting binary becomes huge if not. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
buster
commented
Dec 10, 2014
|
@steveklabnik , actually i want to build a binary with "-C prefer-dynamic"... |
This comment has been minimized.
This comment has been minimized.
prdoyle
commented
Feb 12, 2015
|
+1 for "-C prefer-dynamic". Anybody figured out the right way to do that yet? 550 KB "hello world" is a dealbreaker for me. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Feb 14, 2015
|
Ugh, I need a |
This comment has been minimized.
This comment has been minimized.
prdoyle
commented
Feb 14, 2015
|
Sure, I get that it will be amortized, but it would be nice if Rust could be used for small programs too, even if they allocate some memory. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Feb 15, 2015
|
@prdoyle jemalloc could definitely use some optimization. I can't imagine how all 500kB could be necessary for a single malloc. Though many heap allocations could be optimized out. Yet on most platforms Rust programs are dynamically linked to the system library (glibc/libSystem/kernel32/etc), which uses 5-10MB of process memory. If we had our own system library, then a 500kB runtime wouldn't be so bad. Especially since with static linking & LTO, most programs would use a fraction of that. |
This comment has been minimized.
This comment has been minimized.
MarkSwanson
commented
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. |
This comment has been minimized.
This comment has been minimized.
|
One can get LTO by customising the relevant |
sondrele
referenced this issue
May 13, 2015
Open
Maybe refere to github issues for `cargo rustc` #16
This comment has been minimized.
This comment has been minimized.
maxlapshin
commented
May 25, 2015
|
This is very nice, but: erszcz/erlang-rust-nif#3 |
This comment has been minimized.
This comment has been minimized.
|
@maxlapshin would |
This comment has been minimized.
This comment has been minimized.
zjjott
commented
Jun 19, 2015
|
Holy cargo....
I just want to know,a project like servo,how to use cargo for minimize version using |
drewcrawford
referenced this issue
Jan 7, 2016
Closed
Add additional compiler/linker options in Package.swift #107
This comment has been minimized.
This comment has been minimized.
PeteX
commented
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:
or
Hope this helps someone! |
mulkieran
referenced this issue
Dec 1, 2016
Closed
We would like CI to fail if the compiler generates warnings #159
This comment has been minimized.
This comment has been minimized.
mulkieran
commented
Dec 2, 2016
|
@PeteX It helped me, thanks! |
This comment has been minimized.
This comment has been minimized.
learnopengles
commented
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. |
This comment has been minimized.
This comment has been minimized.
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 This becomes frustrating because IDEs no longer work with projects forced to use Really, even the ability to override this in Edit: My bad, it's possible to do this in the config already |
mahkoh commentedJun 25, 2014
Updated description
Arbitrary flags cannot be passed through to the compiler.
Original Description
-O has to be the default.