[Disclaimer: I am new to Rust]
While experimenting with rustc on Linux I realized that the compiler is able to read input from standard input, while it seems unable to write to standard output if I provide - as output name, for instance with:
$ rustc --emit llvm-ir -o - test.rs
This creates a file named - instead of printing generated output to the console.
While this is not obvious why someone would like to send output to standard output, it may be occasionally useful to pipe it to another program (the example I have in mind: piping llvm-ir output into llc). Also this is, for example, the behavior adopted by clang.
In case it can help, the short research I made through the repository makes me believe that input / output filenames are handled here in rust/src/librustc_driver/lib.rs, in functions make_input() and make_output() respectively. If I am correct, it shows the difference between input (handling the -) and output (not supporting it).
Would using - for standard output with -o option be worth considering? Or is there a good reason not to do so?
It seems that with $ rustc -o - test.rs only, compilation fails (I get error: linking with cc failed: exit code: 1 […] = note: cc: error: unrecognized command line option ‘-.0.o’), could that explain why - is not handled in the same way for output as for input?
Just in case:
$ rustc --version --verbose
rustc 1.15.0-dev (5a0248068 2016-11-30)
binary: rustc
commit-hash: 5a0248068c693c64f74623e9a6f7504b900df8a6
commit-date: 2016-11-30
host: x86_64-unknown-linux-gnu
release: 1.15.0-dev
LLVM version: 3.9
[Disclaimer: I am new to Rust]
While experimenting with rustc on Linux I realized that the compiler is able to read input from standard input, while it seems unable to write to standard output if I provide
-as output name, for instance with:This creates a file named
-instead of printing generated output to the console.While this is not obvious why someone would like to send output to standard output, it may be occasionally useful to pipe it to another program (the example I have in mind: piping llvm-ir output into llc). Also this is, for example, the behavior adopted by clang.
In case it can help, the short research I made through the repository makes me believe that input / output filenames are handled here in
rust/src/librustc_driver/lib.rs, in functionsmake_input()andmake_output()respectively. If I am correct, it shows the difference between input (handling the-) and output (not supporting it).Would using
-for standard output with-ooption be worth considering? Or is there a good reason not to do so?It seems that with
$ rustc -o - test.rsonly, compilation fails (I geterror: linking withccfailed: exit code: 1 […] = note: cc: error: unrecognized command line option ‘-.0.o’), could that explain why-is not handled in the same way for output as for input?Just in case: