-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow certain command line settings to be additive #19938
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
Open
sbc100
wants to merge
1
commit into
main
Choose a base branch
from
appending_settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems a little risky to me, as we have some settings that we want people to be able to replace/shrink, like
INCOMING_MODULE_JS_API
. How about this notation instead?That is,
+=
appends rather than assigns/replaces.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 don't think anyone ever wants one command line argument to replace/shrink the same argument already specified on the same line.
In the case of
INCOMING_MODULE_JS_API
we want the command line arg to replace the default set, but if one library wants to set-sINCOMING_MODULE_JS_API=foo
and another sets-sINCOMING_MODULE_JS_API=bar
I'm pretty sure we always want them to be additive with the result beingfoo,bar
.The way I have set it up is that this happens on a per-setting basis so it doesn't have to apply to all of them.
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 what you mean.
INCOMING_MODULE_JS_API
wouldn't be used from a library anyhow, I guess, that's a global setting for an application, so you wouldn't apply this to that setting. While it does make sense for exported functions, so you'd apply it there. Which I see is what this PR does.Still, what do you think about using
+=
notation? I think that is less ambiguous. As a side benefit, it would avoid any backwards compatibility risk whatsoever.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 just can think of a situation where you wouldn't want
+=
to be the default, and it add more complexity to the command line parser. If we ever find an option where we don't want it to be the default perhaps we could add it then?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.
Well, what worries me is that this is a breaking change. I do see your point that this is the more natural behavior, but it can break user's builds if they had the same flag twice. Build systems are weird and sometimes that duplication happens (in Binaryen for whatever reason there is more than one
-Ox
flag, for example...).Less concerning but still a little odd is that some settings would have this behavior and others wouldn't. And we already have some settings that are additive in their name, like
EXTRA_*
. So this feels like it could be more consistent with those somehow, but I'm not sure how. PerhapsEXTRA_EXPORTED_FUNCTIONS
would be additive, for example?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.
It's a source of bugs when using bazel:
cc_library
sets some flags for it's functionality (say, requestsccall
). The other library /cc_binary
wants to access filesystem, so adds FS. And for some reason it doesn't work and there is no warning why it's happening. To find the problem I literary had to understand how emcc flags and build system works, and even then there is no solution. (Actually, there is one: abuse EXTRA_EXPORTED_FUNCTIONS because while the flag is deprecated, it's passed through and appended in the end. But my colleague uses it too in his library, so no way for me to set custom flags at all).But I agree that it's a breaking change, so my proposal is to add a warning that overriding is happening and perhaps offer a flag to turn additive functionality on. Something like this:
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.
Adding in #21464
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 not? It seems quite natural to have a library (say using inline JS) declare what module.js API functions it uses... and then to propagate that up. In a Bazel world, libraries are responsible for declaring their dependencies, and a used API feels like a dependency.
I don't know of any prior art of command-line flags behaving like this. It definitely does not feel ergonomic.
While I agree some folks may be relying on this behavior, I'd argue that the old behavior was unnatural. Yes, some flags (like
-O
) only expect a single value, and last value wins. But anything that takes a list really ought to accumulate. (It would be weird if, e.g.-l
didn't accumulate for instance).Maybe allow a synthetic, implicit prefix for each list flag, like
ADD_
e.g.ADD_EXPORTED_FUNCTIONS
.If it's a list, it also supports this thing. Then at least build systems that want to leverage this can.
Uh oh!
There was an error while loading. Please reload this page.
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.
Normally its not user code that reads things from
INCOMING_MODULE_JS_API
but emscripten's own code JS code. Its not really something that was designed to be extensible.The usage for
INCOMING_MODULE_JS_API
is really about what the HTML surrounding the program is going to provide. Normally a library doesn't know that, only the person building the final binary. The person in charge of linking the program would ask themselves "am I going to ever provide such as paramater to the program".. if the answer is no, then then there is no need to add that to theINCOMING_MODULE_JS_API
list. Adding something to that list, but never supplying it at runtime is just a waste of code.I can imagine there might be exceptions.. but that seems like the rule to me.