-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[emcc.py] Simplify passing arguments to clang in compile-only mode #23454
Conversation
1951eba
to
6ea0733
Compare
shared.exec_process(cmd) | ||
assert False, 'exec_process does not return' | ||
|
||
# In COMPILE_AND_LINK we need to compile source files too, but we also need to | ||
# filter out the link flags | ||
assert state.mode == Mode.COMPILE_AND_LINK | ||
assert not options.dash_c | ||
compile_args, input_files = split_linker_flags(options, state, newargs) | ||
compile_args = filter_out_link_flags(compile_args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow up I hope to combine these two functions, but it makes this PR easier to follow if I leave them separate for now.
This change avoids removing the `-o` flag and the input files when only compiling. We delay the splitting out of the linker flags and the input files until we know actually do to do linking. This effect of this is that the compile-only phase is now much simpler because it doesn't need to re-inject the input files and the `-o` flag. This also as the effect of keeping the order of those flags preserved with respect to other command line flags when calling clang to do compilation.
6ea0733
to
e100988
Compare
self.run_process([EMCC, '-c', 'cxxfoo.h', '-x', 'c++-header']) | ||
self.run_process([EMCC, '-c', 'cxxfoo.h', '-x', 'c++']) | ||
self.run_process([EMCC, '-x', 'c++-header', '-c', 'cxxfoo.h']) | ||
self.run_process([EMCC, '-x', 'c++', '-c', 'cxxfoo.h']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because emcc now passes these arguments though in the correct order:
Before it was re-ordering to put the source file at the end or emcc -c cxxfoo.h -x c++-header
was becoming emcc -x c++-header -c cxxfoo.h
.
Becuase -x
(filetype) only effects the files that follow it this inadvertent / mistaken behaviour was fixing the command line hiding what should have been an error/warning from clang:
$ clang -c cxxfoo.h -x c++-header
clang: warning: '-x c++-header' after last input file has no effect [-Wunused-command-line-argument]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words this was more of a bug in the test that emcc was ignored by emcc because it happened to re-order the command line flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks... I didn't realize -x
affects files after it. I thought it was global...
As a followup to emscripten-core#23454 we no longer need to distinguish between the some of these compiler modes. Specifically PCH and PREPROCESS_ONLY are not subsumed by COMPILE_ONLY since all these modes simply exec clang and exit.
As a followup to emscripten-core#23454 we no longer need to distinguish between the some of these compiler modes. Specifically PCH and PREPROCESS_ONLY are not subsumed by COMPILE_ONLY since all these modes simply exec clang and exit.
This change avoids removing the
-o
flag and the input files when only compiling. We delay the splitting out of the linker flags and the input files until we know actually do to do linking.This effect of this is that the compile-only phase is now much simply because it doesn't need to re-inject the input files and the
-o
flag.This also as the effect of keeping the order of those flags preserved with respect to other command line flags when calling clang to do compilation.