Emscripten: Error no input files when piping input

Created on 13 Sep 2019  路  6Comments  路  Source: emscripten-core/emscripten

GCC and co allow for piping input through stdin, normally with gcc -. emcc complains about no input files.
This makes it a bit harder to use emcc as a drop-in replacement.

emcc --version
emcc (Emscripten gcc/clang-like replacement) 1.38.44 (commit 77b5df4005f2e5d23cf2c2040f0784efe114be35)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
echo "\#include <string>" | emcc -x c++ -dM -E -
shared:ERROR: no input files
note that input files without a known suffix are ignored, make sure your input files end with one of: ('.c', '.C', '.i', '.cpp', '.cxx', '.cc', '.c++', '.CPP', '.CXX', '.CC', '.C++', '.ii', '.m', '.mi', '.mm', '.mii', '/dev/null', '.bc', '.o', '.obj', '.lo', '.dylib', '.so', '.a', '.ll', '.h', '.hxx', '.hpp', '.hh', '.H', '.HXX', '.HPP', '.HH')

whereas gcc

echo "\#include <string>" | gcc -x c++ -dM -E -
#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __cpp_attributes 200809
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __FLT128_MAX_10_EXP__ 4932
#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
#define __GCC_IEC_559_COMPLEX 2
#define __cpp_aggregate_nsdmi 201304

If I roundtrip through a file:

echo "\#include <string>" > temp.h && emcc -x c++ -dM -E temp.h

emcc provides me the expected output.

cc: @keno

good first bug help wanted

Most helpful comment

I think it should be possible/simpler to do without a tempfile by simply passing the - along to clang.

All 6 comments

A agree. We should fix this.

Hi, want to check this out. Can you provide me initials to get started?

That would be great @masihtamsoy!

I think all the relevant code for this is in emcc.py. That's a fairly large file, but in run() we have all the argument parsing etc. Search for "newargs" for example to see the arguments. And the comment with "find input files" is right before we scan for the input files among the arguments.

One way to solve this might be to check if stdin has contents, and if so to create a temp file with those, and add it to the input files. However, there may be a nicer python way, may be worth doing some searching online for how other python programs handle such things.

Thanks @kripken , working on it.

Hi @kripken, was bit occupied. Did some research,

  1. I will be using if聽not聽sys.stdin.isatty(): to check stdin has content
  2. In order to create temp file, I will be using tempfile lib. stdin content can be of any language, should we categorise content before defining suffix for temp file? Or is there any other way?
  3. Where would be a good place to close temp file created above?

Let me know your opinion.

I think it should be possible/simpler to do without a tempfile by simply passing the - along to clang.

Was this page helpful?
0 / 5 - 0 ratings