Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write compiler output to standard output if option -o - is provided #38118

Closed
Qeole opened this issue Dec 1, 2016 · 3 comments
Closed

Write compiler output to standard output if option -o - is provided #38118

Qeole opened this issue Dec 1, 2016 · 3 comments

Comments

@Qeole
Copy link

Qeole commented Dec 1, 2016

[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
@djzin
Copy link
Contributor

djzin commented Dec 2, 2016

You can use /dev/stdout instead of - but then rustc fails with "Assertion `FD >= 0 && "File not yet open!"' failed."

@Stebalien
Copy link
Contributor

It also wants to write a temporary .o file so ... | rustc - -o >(cat) doesn't work either.

@Mark-Simulacrum
Copy link
Member

Closing in favor of #26719.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants