emscripten
emscripten copied to clipboard
Add support for --closure-args in ports
If my understanding is correct using closure args is meant for when the closure compiler is invoke and it seems that it is only for optimization reason.
Part of the WebGPU effort, I noticed that @kainino0x uses the following --closure-args parameter in the instructions:
--closure-args=--externs=path/to/emdawnwebgpu_pkg/webgpu/src/webgpu-externs.js
The problem when packaging WebGPU as a port, is that the file webgpu-externs.js file ends up being inside the zip file that gets downloaded by the port. So the user cannot really add it after the fact (nor should it, as it is an implementation detail TBH).
The port file that we discussed here has a section like this:
def linker_setup(ports, settings):
if settings.USE_WEBGPU:
raise Exception('dawn may not be used with -sUSE_WEBGPU=1')
src_dir = get_source_path(ports)
settings.JS_LIBRARIES += [
os.path.join(src_dir, 'library_webgpu_enum_tables.js'),
os.path.join(src_dir, 'library_webgpu_generated_struct_info.js'),
os.path.join(src_dir, 'library_webgpu_generated_sig_info.js'),
os.path.join(src_dir, 'library_webgpu.js'),
]
# TODO(crbug.com/371024051): Emscripten needs a way for us to pass
# --closure-args too.
The JS_LIBRARIES that are inside the port can be added easily, but the closure-args cannot.
I am happy to work on this if you are ok with it and if you give me some guidance on the best/appropriate way to do this.
As a a side note, I understand that the issue with the port as written, is that we cannot use
--closure-args(which, unless I am wrong, is an optimization, so not really a showstopper for this experiment).
It's required if compiling with closure. If you don't pass the externs, then closure will produce incorrect code, because it minifies the symbols in calls to browser APIs. (instead of a.requestDevice() it'll minify to something like a.x())
I guess we should make a CLOSURE_ARGS internal setting (in settings_internal.js) and have the --closure-args add to that setting. Then you can extend settings.CLOSURE_ARGS here.
@sbc100 Sounds good. I will work on this then (although it might take me a bit as I am in a middle of something).
Is there a way from inside the port to know whether the closure compiler is requested, thus to inject the closure args only when necessary?
if <closure compiler requested>:
settings.CLOSURE_ARGS = '...'
I would just inject them unconditionally.
Implemented in #24192 and merged into main
Tested and working for Dawn! https://dawn-review.googlesource.com/c/dawn/+/239474