Compiling rustc with non-standard flags


How can I compile rust with non-standard compile flags?

The build system by using feels very opaque. Is there a document somewhere how everything is put together and how to change the compile flags (which is what I am after)?


Perhaps the rustc guide can be helpful?


Hmm… I don’t think we have anything about the internals of… may be a good thing to add.


I believe rustc’s build does respect the RUSTFLAGS environment variable.


The closest thing I find in the guide is: and yet there’s no mention of different compiler flags.


So, if you want to compile, say with -Oz, would you do RUSTFLAGS=-Oz python build? I assume this is the counterpart to CFLAGS. Is there a counterpart to LDFLAGS?


@pmatos I’m curious what your use case is. Why do you want to compile with non-standard flags?


CFLAGS, CXXFLAGS, and LDFLAGS might still get used by some C/C++ components, but for the linker as invoked by rustc, I think you can stuff it in RUSTFLAGS="-Clink-arg=-foo -Clink-arg=-bar ...". Also remember that cc is used as the linker for most targets, so if you want to add a direct ld option, it would be like -Clink-arg=-Wl,option.