You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: one EXPORTS setting to rule them all #8380
Background: Right now to keep alive & export a compiled function one would use EXPORTED_FUNCTIONS, while to ensure a JS library function exists one would use DEFAULT_LIBRARY_FUNCS_TO_INCLUDE, and there is EXPORTED_RUNTIME_METHODS for exporting parts of the JS runtime. This is needlessly complex, and confusing since a C API may be implemented in either compiled code or a JS library, and currently you need to know which in order to properly include and export it.
Proposal:
A new EXPORTS setting, which receives a list of things to ensure exist and are exported in the final output. These can be in compiled code, the JS library, or the JS runtime - the user doesn't need to know.
Deprecate all the other relevant options (but still support them for backwards compatibility for a long time at least), namely EXPORTED_FUNCTIONS, DEFAULT_LIBRARY_FUNCS_TO_INCLUDE, EXPORTED_RUNTIME_METHODS.
No _ prefixing, like EXPORTED_RUNTIME_METHODS etc., and unlike EXPORTED_FUNCTIONS. This moves us further along the path to get us rid of the old prefixing annoyance.
For example, -s EXPORTS=['main', 'emscripten_main_loop', 'AsciiToString'] would export a compiled function, a JS library function, and a runtime function, respectively (and note the lack of _ prefixes).
Sounds good, assuming the distinction isn't needs by any of our users.
@curiousdannii, I share your concern regarding maintaining backwards compat. For this kind of thing I'd like to see an eventual path to completely removal. In stages such as:
Disable the features in STRICT mode, and recommend that devs used STRICT whenever possible to stay up-to-date.
After N months, or N emscripten revisions show a warning when using the deprecated feature.
After another N, turn the warning into a hard error and remove all the supporting code
Reacted by Dannii Willis, Tim Lander and Alon Zakai
IIUC it does sort of repurpose the meaning of what an "export" is. We've been thinking of it in the sense of being exported from the compiled module, whereas the others would be actually imported into wasm but "exported" from the Module object. Mostly users don't care about that distinction so this is probably a good idea (although, what about user-written JS library code?). Maybe at least for our own sanity, in code/comments (and maybe documentation) we should have more precise nomenclature, e.g. "Module exports" or something to mean exports from the emscripten package (EXPORTS as proposed here), "wasm exports/imports" to mean exports from the wasm module, and... something else?
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
I believe is comes from windows and/or macOS where the C ABI includes a leading underscore on all C symbols. I guess whoever worked on this originally was probably a windows and/or macOS user.
I thought it had more to do with the fact that back in the asm.js days there was the potential of naming conflicts between the asm-compiled part and the JS wrapper part...
I thought it had more to do with the fact that back in the asm.js days there was the potential of naming conflicts between the asm-compiled part and the JS wrapper part...
Not as far as I know. I don't see how the potential for naming conflict was any different back then. Native and JS symbols still occupy the same name space today. I think it just came from the fact that C compiler symbols on macOS/windows have/had leading underscores. IIUC it just seemed natural for native symbols to be named like that when @kripken and @juj were first working on fastcomp.
Well if there was naming conflict, should we just prefix our library function with something like EM_
There are two types of JS library symbols:
Symbols that we want to be in the same namespace as C symbols, and which implement C APIs. In this case we want the JS symbol to have the same name as the C symbol. These symbols are directly callable from C. In the JS library files these are the ones that don't have the $ prefix.
Symbols that are not designed to be called from C but are just JS utility function. In the JS library files these are the ones that have the $ prefix. (you can't link your C code against these).
In addition to these JS library symbols we also two other types of symbols in the JS world:
Emscripten runtime symbols, not part of the JS library, and not callable from native code (you can't link your C code against thse).
Builtin JS symbols such as window or document (you can't link your C code against these).
The only time we need to worry about symbol collision is if user explicitly exports a C symbol that happens to have the same name as a symbol of type (2), (3) or (4) above. I don't think this is going to be very common to be honest, and we don't have the ability to rename symbols of type (4) at all, so I'm inclined not to worry about it, and issue warnings/errors to users who try to export colliding symbols.
Historically the reason we had prefixing had a few reasons that include the ones mentioned. The very first Emscripten translated LLVM IR text into JS, and I needed to handle name collisions between %foo (a local) and @foo (a function name), so % and @ each got translated into something (_ and $). And this seemed natural because various assembly notations have _ prefixes too. So it was both because of name conflicts and convention.
Activity
curiousdannii commentedon Apr 2, 2019
Would the exported functions also lack the
_? And if you useEMSCRIPTEN_KEEPALIVEcould that also export without the_?(I think this would be cleaner, but it does make backwards compatibility harder or bloatier.)
jgravelle-google commentedon Apr 2, 2019
sgtm, from a UX perspective at least
sbc100 commentedon Apr 2, 2019
Sounds good, assuming the distinction isn't needs by any of our users.
@curiousdannii, I share your concern regarding maintaining backwards compat. For this kind of thing I'd like to see an eventual path to completely removal. In stages such as:
dschuff commentedon Apr 3, 2019
IIUC it does sort of repurpose the meaning of what an "export" is. We've been thinking of it in the sense of being exported from the compiled module, whereas the others would be actually imported into wasm but "exported" from the
Moduleobject. Mostly users don't care about that distinction so this is probably a good idea (although, what about user-written JS library code?). Maybe at least for our own sanity, in code/comments (and maybe documentation) we should have more precise nomenclature, e.g. "Module exports" or something to mean exports from the emscripten package (EXPORTSas proposed here), "wasm exports/imports" to mean exports from the wasm module, and... something else?stale commentedon Apr 2, 2020
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
curiousdannii commentedon Apr 2, 2020
This still sounds like a good improvement if the details can be worked out.
kripken commentedon Apr 6, 2020
@curiousdannii Agreed, yeah. I think this has to wait on removing fastcomp first, after that this will be much easier to do.
stale commentedon Jun 4, 2021
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
curiousdannii commentedon Jun 4, 2021
This would still be nice to have.
Rename internal USER_EXPORTED_FUNCTIONS setting. NFC
Rename internal USER_EXPORTED_FUNCTIONS setting. NFC (#21868)
13 remaining items
msqr1 commentedon May 3, 2024
Why were exports prefixed in the first place?
sbc100 commentedon May 3, 2024
I believe is comes from windows and/or macOS where the C ABI includes a leading underscore on all C symbols. I guess whoever worked on this originally was probably a windows and/or macOS user.
See https://stackoverflow.com/questions/1034852/adding-leading-underscores-to-assembly-symbols-with-gcc-on-win32
dschuff commentedon May 3, 2024
I thought it had more to do with the fact that back in the asm.js days there was the potential of naming conflicts between the asm-compiled part and the JS wrapper part...
sbc100 commentedon May 3, 2024
Not as far as I know. I don't see how the potential for naming conflict was any different back then. Native and JS symbols still occupy the same name space today. I think it just came from the fact that C compiler symbols on macOS/windows have/had leading underscores. IIUC it just seemed natural for native symbols to be named like that when @kripken and @juj were first working on fastcomp.
msqr1 commentedon May 3, 2024
Well if there was naming conflict, should we just prefix our library function with something like
EM_sbc100 commentedon May 3, 2024
There are two types of JS library symbols:
$prefix.$prefix. (you can't link your C code against these).In addition to these JS library symbols we also two other types of symbols in the JS world:
windowordocument(you can't link your C code against these).The only time we need to worry about symbol collision is if user explicitly exports a C symbol that happens to have the same name as a symbol of type (2), (3) or (4) above. I don't think this is going to be very common to be honest, and we don't have the ability to rename symbols of type (4) at all, so I'm inclined not to worry about it, and issue warnings/errors to users who try to export colliding symbols.
kripken commentedon May 6, 2024
Historically the reason we had prefixing had a few reasons that include the ones mentioned. The very first Emscripten translated LLVM IR text into JS, and I needed to handle name collisions between
%foo(a local) and@foo(a function name), so%and@each got translated into something (_and$). And this seemed natural because various assembly notations have_prefixes too. So it was both because of name conflicts and convention.msqr1 commentedon Jun 17, 2024
What is our progress on this? @sbc100
Add new simple export mechanism
sbc100 commentedon Nov 21, 2024
I just uploaded the a draft PR: #22977
Add new simple export mechanism
Add new simple export mechanism
Add new simple export mechanism
Add new simple export mechanism
Add new simple export mechanism