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

[emcc.py] Simplify passing arguments to clang in compile-only mode #23454

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 18, 2025

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.

@sbc100 sbc100 force-pushed the delay_input_file_parsing branch 3 times, most recently from 1951eba to 6ea0733 Compare January 18, 2025 00:56
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)
Copy link
Collaborator Author

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.
@sbc100 sbc100 force-pushed the delay_input_file_parsing branch from 6ea0733 to e100988 Compare January 21, 2025 17:09
@sbc100 sbc100 requested review from kripken and dschuff January 21, 2025 17:17
@sbc100 sbc100 changed the title [emcc.py] Simplify passing arguments to clang in compile only mode [emcc.py] Simplify passing arguments to clang in compile-only mode Jan 21, 2025
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'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the test?

Copy link
Collaborator Author

@sbc100 sbc100 Jan 21, 2025

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]

Copy link
Collaborator Author

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.

Copy link
Member

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...

@sbc100 sbc100 requested a review from kripken January 21, 2025 22:36
@sbc100 sbc100 merged commit 6a5925a into emscripten-core:main Jan 22, 2025
29 checks passed
@sbc100 sbc100 deleted the delay_input_file_parsing branch January 22, 2025 00:53
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 22, 2025
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.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 22, 2025
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.
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

Successfully merging this pull request may close these issues.

2 participants