Compiling rustc with non-standard flags


#1

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

The build system by using x.py 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)?


#2

Perhaps the rustc guide can be helpful? https://rust-lang.github.io/rustc-guide/about-this-guide.html


#3

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


#4

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


#5

The closest thing I find in the guide is: https://rust-lang.github.io/rustc-guide/how-to-build-and-run.html and yet there’s no mention of different compiler flags.


#6

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


#7

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


#8

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.