You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
[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-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 geterror: linking with
ccfailed: 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:
The text was updated successfully, but these errors were encountered: