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
Implement a different syntax for contrib ports #24260
@sbc100 I have started investigating these changes.
The fact that ports are loaded when the system starts (and not on demand) makes this quite challenging: fetching the port (= zip file aka artifact) currently happens when the port is being used, the rest is just static data (like dependencies, options, etc...). But with this new design a remote port only contains information to fetch the artifact and the actual port is inside that artifact.
I don't think we want to download the remote artifact (even if it happens only once) if the port is never used just so that we can build the list of ports up front...
At some point (way back when), I had a design where ports would be loaded on demand and that was dropped because the "cost" was deemed negligible. I feel like we need to implement something like that. I am not entirely sure how to merge the 2 concepts otherwise...
It would be very nice to have first class support for things like this, though earlier I think we had a "hack" in mind that would just load the port and effectively re-export it. I've tested this locally by dropping it into emscripten/tools/ports/contrib and it works:
# Copyright 2025 The Emscripten Authors. All rights reserved.# Emscripten is available under two separate licenses, the MIT license and the# University of Illinois/NCSA Open Source License. Both these licenses can be# found in the LICENSE file.# Contrib port wrapper for emdawnwebgpu, Dawn's implementation of webgpu.h# for Emscripten (on top of the WebGPU JS API).# To use this: --use-port=contrib.emdawnwebgpu-remoteimportimportlib.utilimportosimportsysURL='https://github.com/google/dawn/releases'DESCRIPTION="emdawnwebgpu, Dawn's implementation of webgpu.h for Emscripten"LICENSE='mixed licenses, see license files'_port_name='emdawnwebgpu'_url='https://github.com/google/dawn/releases/download/v20250512.200721/emdawnwebgpu_pkg-v20250512.200721.zip'_hash='cc073a592a5d101c2e114c017bf5b4c0927330dc823d8b151d71c5a646f94f00f0f9eb9a8b4274d6960a2ff7ac84e762a0ac2add475ece616aed00e724942e3d'_loaded=Nonedef_error_handler(message):
raiseException(message)
def_load(ports):
global_loadedif_loadedisNone:
ports.fetch_project(_port_name, _url, _hash)
path=os.path.join(ports.get_dir(), _port_name, 'emdawnwebgpu_pkg', 'emdawnwebgpu.port.py')
# Incantation to load the module from a filenamespec=importlib.util.spec_from_file_location('port_emdawnwebgpu', path)
mod=importlib.util.module_from_spec(spec)
sys.modules['port_emdawnwebgpu'] =modspec.loader.exec_module(mod)
_loaded=mod# Assume handle_options has already been called (if there are options).if_optionsisnotNone:
_loaded.handle_options(_options, _error_handler)
return_loaded# Need to re-export these options for --use-port to accept them.# (There are no hooks that run before this that would let us download the port.)OPTIONS= {
'cpp_bindings':
'Add the include path for <webgpu/webgpu_cpp.h> C++ bindings. Default: true.',
'opt_level':
"Optimization (-O) level for the bindings' Wasm layer. Default: choose based on -sASSERTIONS.",
}
# We assume handle_options has been called before other hooks (if there are any# options) to override the initial _options._options= {}
defhandle_options(options, error_handler):
global_options_options=optionsif_loadedisnotNone:
_loaded.handle_options(_options, _error_handler)
defprocess_args(ports):
return_load(ports).process_args(ports)
deflinker_setup(ports, settings):
return_load(ports).linker_setup(ports, settings)
defget(ports, settings, shared):
return_load(ports).get(ports, settings, shared)
defclear(ports, settings, shared):
return_load(ports).clear(ports, settings, shared)
WDYT of adding something like this to Emscripten now so we can get -sUSE_WEBGPU deprecated? I want to deprecate it ASAP so people know they need to migrate (and avoid building things on top of the old thing, continuing to file bugs about missing features, etc.).
I published a non hacky version of emdawn. I just don't see why, since we are looking for a temporary solution, don't we go with a non hacky version.
But in the end I have no say in this matter.
That being said I would appreciate you providing guidance on the work that I have already done (PR #24303 ) and if I should continue working on it or not. I offered my help but if you don't need it, please say so, so I stop wasting my time.
Obviously a non-hacky version is better, and if we can land #24303 first that would be great!
I think @kainino0x is just asking if we need to block the emdawn release on #24303 or if we can allow them to happen in either order (which seems better, especially if emdawn is trying to get feedback sooner rather then later).
I published a non hacky version of emdawn. I just don't see why, since we are looking for a temporary solution, don't we go with a non hacky version.
Fair. I was actually just looking back at that because I wanted to see how you did the tag/hash thing.
What do you think of landing your port in Emscripten so we can deprecate USE_WEBGPU? I had a concern I hadn't really thought through, TBH, that if people need to use an emdawnwebgpu release that is not compatible with the built-in port file, they would have to download a release instead. But it's not really that much to ask them to do that. And besides, it probably won't happen that often, I was just nervous about this because I know there are bugs in emdawnwebgpu that we need to fix. But bugfixes shouldn't break it. (And anyway the hack I came up with is not really that stable either.)
Once #24303 is done then we can upgrade it to use that system and it should be more stable.
@kainino0x I am fine landing a port similar to the one I wrote. The port I wrote is a remix of the one you wrote. And I feel like the one that we should check-in in Emscripten should be a remix of my remix: one that uses your option names and implementation (cpp_bindings and opt_level) since when #24303 land, it will refer to these options... I have a different implementation for optimization level to match the other port I created (ImGui) and it is different from your implementation.
As far as #24303 is concerned, the work is mostly done but I am stuck at the moment and I am awaiting feedback/guidance in order to wrap it up: the code is essentially doing what you are doing in your "hacked" solution in a generic fashion => as soon as the port is required it gets fetched and replaces the port skeleton. There is a problem with the cachedir not being initialized soon enough and I have no clue how to fix this. Honestly I don't think we are far to be able to complete this work. I just need help from @sbc100 to move forward.
To follow up on this I think I may have found a solution on my own (of course unclear if that will be approved), but now with PR #24303, the external port, defined like this totally works:
//contrib/emdawn.pyTAG='v20250509.171557'EXTERNAL_PORT=f'https://github.com/google/dawn/releases/download/{TAG}/emdawnwebgpu_pkg-{TAG}.zip'SHA512='4b66bf0f64b9616a6420abdad636b3ecefab892dde8f67cd941147bfddf7920f5523ff10160c9a563ef377a0f88b2dfc033527591b2d0753d531de5cbbabde59'PORT_FILE='emdawnwebgpu_pkg/emdawnwebgpu.port.py'# contrib port information (required)URL='https://dawn.googlesource.com/dawn'DESCRIPTION='Dawn is an open-source and cross-platform implementation of the WebGPU standard'LICENSE='BSD 3-Clause License'
> ./emcc --use-port=contrib.emdawn:help
ports:INFO: retrieving port: contrib.emdawn from https://github.com/google/dawn/releases/download/v20250509.171557/emdawnwebgpu_pkg-v20250509.171557.zip
ports:INFO: unpacking port: contrib.emdawn
cache:INFO: deleting cached file: /usr/local/emsdk/emscripten/main/cache/sysroot/lib/wasm32-emscripten/lib_emdawnwebgpu-cb451621-O0.a
contrib.emdawn (--use-port=contrib.emdawn; mixed licenses, see license files)
Dawn is an open-source and cross-platform implementation of the WebGPU standard
Options:
* cpp_bindings: Add the include path for <webgpu/webgpu_cpp.h> C++ bindings. Default: true.
* opt_level: Optimization (-O) level for the bindings' Wasm layer. Default: choose based on -sASSERTIONS.
More info: https://dawn.googlesource.com/dawn
> ./emcc --use-port=contrib.emdawn test/hello_world.c -o /tmp/build/index.js
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/lib_emdawnwebgpu-cb451621-O0.a... (this will be cached in "/usr/local/emsdk/emscripten/main/cache/sysroot/lib/wasm32-emscripten/lib_emdawnwebgpu-cb451621-O0.a" for subsequent builds)
system_libs:INFO: compiled 1 inputs in 0.88s
cache:INFO: - ok
Regarding opt_level specifically. I explained in an earlier post somewhere why I don't think it should be needed. Instead we can just do what do for all our libraries do use a debug variant when -sASSERTIONS (or -O0 which implies it) is used.
Trying to support all different opt levels leads to a testing matrix explosion that I think its best to avoid unless necessary. Adding extra flavors of a library always in my experience leads to bugs where we didn't test a particular flavor combination. e.g. "I can't use the -0z version dawn with the debug version of libc"
Bit of a tangent (especially if #24303 gets landed soon) but...
Regarding opt_level specifically. I explained in an earlier post somewhere why I don't think it should be needed. Instead we can just do what do for all our libraries do use a debug variant when -sASSERTIONS (or -O0 which implies it) is used.
The package only supports opt_level=0/2 right now for that reason. I kept it as opt_level to make it trivial for people to modify to add other optimization levels if they want, though this will be complicated a little by a fix I'm making to set NDEBUG (which I forgot to do before), so was considering just making it a boolean assertions=auto/true/false.
It still needs to be an option if we want it to be possible to build both versions with embuilder (which seems to always set ASSERTIONS=1) - however if we want to fix this in embuilder instead, I would be fine removing the port option entirely; it would be nice to simplify it.
It still needs to be an option if we want it to be possible to build both versions with embuilder (which seems to always set ASSERTIONS=1) - however if we want to fix this in embuilder instead, I would be fine removing the port option entirely; it would be nice to simplify it.
Good point. We should add way to build debug flavored libraries using embuilder.
Activity
ypujante commentedon May 6, 2025
@sbc100 I have started investigating these changes.
The fact that ports are loaded when the system starts (and not on demand) makes this quite challenging: fetching the port (= zip file aka artifact) currently happens when the port is being used, the rest is just static data (like dependencies, options, etc...). But with this new design a remote port only contains information to fetch the artifact and the actual port is inside that artifact.
I don't think we want to download the remote artifact (even if it happens only once) if the port is never used just so that we can build the list of ports up front...
At some point (way back when), I had a design where ports would be loaded on demand and that was dropped because the "cost" was deemed negligible. I feel like we need to implement something like that. I am not entirely sure how to merge the 2 concepts otherwise...
Certainly open for guidance/feedback
kainino0x commentedon May 13, 2025
It would be very nice to have first class support for things like this, though earlier I think we had a "hack" in mind that would just load the port and effectively re-export it. I've tested this locally by dropping it into
emscripten/tools/ports/contriband it works:WDYT of adding something like this to Emscripten now so we can get
-sUSE_WEBGPUdeprecated? I want to deprecate it ASAP so people know they need to migrate (and avoid building things on top of the old thing, continuing to file bugs about missing features, etc.).sbc100 commentedon May 13, 2025
If that hack works I don't see why we it shouldn't land that way first. You could even add a FIXME referring back to this bug,.
ypujante commentedon May 13, 2025
I published a non hacky version of emdawn. I just don't see why, since we are looking for a temporary solution, don't we go with a non hacky version.
But in the end I have no say in this matter.
That being said I would appreciate you providing guidance on the work that I have already done (PR #24303 ) and if I should continue working on it or not. I offered my help but if you don't need it, please say so, so I stop wasting my time.
sbc100 commentedon May 13, 2025
Obviously a non-hacky version is better, and if we can land #24303 first that would be great!
I think @kainino0x is just asking if we need to block the emdawn release on #24303 or if we can allow them to happen in either order (which seems better, especially if emdawn is trying to get feedback sooner rather then later).
kainino0x commentedon May 14, 2025
Fair. I was actually just looking back at that because I wanted to see how you did the tag/hash thing.
What do you think of landing your port in Emscripten so we can deprecate
USE_WEBGPU? I had a concern I hadn't really thought through, TBH, that if people need to use an emdawnwebgpu release that is not compatible with the built-in port file, they would have to download a release instead. But it's not really that much to ask them to do that. And besides, it probably won't happen that often, I was just nervous about this because I know there are bugs in emdawnwebgpu that we need to fix. But bugfixes shouldn't break it. (And anyway the hack I came up with is not really that stable either.)Once #24303 is done then we can upgrade it to use that system and it should be more stable.
ypujante commentedon May 14, 2025
@kainino0x I am fine landing a port similar to the one I wrote. The port I wrote is a remix of the one you wrote. And I feel like the one that we should check-in in Emscripten should be a remix of my remix: one that uses your option names and implementation (
cpp_bindingsandopt_level) since when #24303 land, it will refer to these options... I have a different implementation for optimization level to match the other port I created (ImGui) and it is different from your implementation.As far as #24303 is concerned, the work is mostly done but I am stuck at the moment and I am awaiting feedback/guidance in order to wrap it up: the code is essentially doing what you are doing in your "hacked" solution in a generic fashion => as soon as the port is required it gets fetched and replaces the port skeleton. There is a problem with the cachedir not being initialized soon enough and I have no clue how to fix this. Honestly I don't think we are far to be able to complete this work. I just need help from @sbc100 to move forward.
ypujante commentedon May 14, 2025
To follow up on this I think I may have found a solution on my own (of course unclear if that will be approved), but now with PR #24303, the external port, defined like this totally works:
sbc100 commentedon May 14, 2025
Regarding
opt_levelspecifically. I explained in an earlier post somewhere why I don't think it should be needed. Instead we can just do what do for all our libraries do use a debug variant when-sASSERTIONS(or-O0which implies it) is used.Trying to support all different opt levels leads to a testing matrix explosion that I think its best to avoid unless necessary. Adding extra flavors of a library always in my experience leads to bugs where we didn't test a particular flavor combination. e.g. "I can't use the -0z version dawn with the debug version of libc"
kainino0x commentedon May 14, 2025
Bit of a tangent (especially if #24303 gets landed soon) but...
The package only supports
opt_level=0/2right now for that reason. I kept it asopt_levelto make it trivial for people to modify to add other optimization levels if they want, though this will be complicated a little by a fix I'm making to setNDEBUG(which I forgot to do before), so was considering just making it a booleanassertions=auto/true/false.It still needs to be an option if we want it to be possible to build both versions with
embuilder(which seems to always set ASSERTIONS=1) - however if we want to fix this inembuilderinstead, I would be fine removing the port option entirely; it would be nice to simplify it.sbc100 commentedon May 14, 2025
Good point. We should add way to build debug flavored libraries using embuilder.
ypujante commentedon May 20, 2025
Implemented with #24303.