From 19f05833a8243acc94dce77cb26b70e34aaf7ea1 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Mon, 29 Jan 2024 16:09:37 -0800 Subject: [PATCH 01/27] added PORTS new settings - all official ports can be used with this setting --- .../tools_reference/settings_reference.rst | 27 ++++++++ src/settings.js | 24 ++++++++ test/test_browser.py | 4 ++ tools/ports/__init__.py | 61 +++++++++++-------- tools/ports/boost_headers.py | 2 +- tools/ports/bullet.py | 2 +- tools/ports/bzip2.py | 2 +- tools/ports/cocos2d.py | 2 +- tools/ports/freetype.py | 2 +- tools/ports/giflib.py | 2 +- tools/ports/harfbuzz.py | 2 +- tools/ports/icu.py | 2 +- tools/ports/libjpeg.py | 2 +- tools/ports/libmodplug.py | 2 +- tools/ports/libpng.py | 2 +- tools/ports/mpg123.py | 2 +- tools/ports/ogg.py | 2 +- tools/ports/regal.py | 2 +- tools/ports/sdl2.py | 2 +- tools/ports/sdl2_gfx.py | 2 +- tools/ports/sdl2_image.py | 2 +- tools/ports/sdl2_mixer.py | 2 +- tools/ports/sdl2_net.py | 2 +- tools/ports/sdl2_ttf.py | 2 +- tools/ports/sqlite3.py | 2 +- tools/ports/vorbis.py | 2 +- tools/ports/zlib.py | 2 +- tools/settings.py | 1 + 28 files changed, 113 insertions(+), 50 deletions(-) diff --git a/site/source/docs/tools_reference/settings_reference.rst b/site/source/docs/tools_reference/settings_reference.rst index 1c1048be5f9d9..f8bad6a12cad1 100644 --- a/site/source/docs/tools_reference/settings_reference.rst +++ b/site/source/docs/tools_reference/settings_reference.rst @@ -1700,6 +1700,15 @@ Specify the GLFW version that is being linked against. Only relevant, if you are linking against the GLFW library. Valid options are 2 for GLFW2 and 3 for GLFW3. +.. _ports: + +PORTS +===== + +Specify which ports to use. If there is only one port to use, it can be +specified this way -sPORTS=port. If multiple ports are need, you +specify it that way: -sPORTS=[port1,port2]. + .. _wasm: WASM @@ -1849,6 +1858,7 @@ Specify the SDL version that is being linked against. 2 is a port of the SDL C code on emscripten-ports When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL is not linked in. +Alternate syntax for using the port: -sPORTS=sdl2 .. note:: Applicable during both linking and compilation @@ -1894,6 +1904,7 @@ USE_ICU ======= 1 = use icu from emscripten-ports +Alternate syntax: -sPORTS=icu .. note:: Applicable during both linking and compilation @@ -1903,6 +1914,7 @@ USE_ZLIB ======== 1 = use zlib from emscripten-ports +Alternate syntax: -sPORTS=zlib .. note:: Applicable during both linking and compilation @@ -1912,6 +1924,7 @@ USE_BZIP2 ========= 1 = use bzip2 from emscripten-ports +Alternate syntax: -sPORTS=bzip2 .. note:: Applicable during both linking and compilation @@ -1921,6 +1934,7 @@ USE_GIFLIB ========== 1 = use giflib from emscripten-ports +Alternate syntax: -sPORTS=giflib .. note:: Applicable during both linking and compilation @@ -1930,6 +1944,7 @@ USE_LIBJPEG =========== 1 = use libjpeg from emscripten-ports +Alternate syntax: -sPORTS=libjpeg .. note:: Applicable during both linking and compilation @@ -1939,6 +1954,7 @@ USE_LIBPNG ========== 1 = use libpng from emscripten-ports +Alternate syntax: -sPORTS=libpng .. note:: Applicable during both linking and compilation @@ -1948,6 +1964,7 @@ USE_REGAL ========= 1 = use Regal from emscripten-ports +Alternate syntax: -sPORTS=regal .. note:: Applicable during both linking and compilation @@ -1957,6 +1974,7 @@ USE_BOOST_HEADERS ================= 1 = use Boost headers from emscripten-ports +Alternate syntax: -sPORTS=boost_headers .. note:: Applicable during both linking and compilation @@ -1966,6 +1984,7 @@ USE_BULLET ========== 1 = use bullet from emscripten-ports +Alternate syntax: -sPORTS=bullet .. note:: Applicable during both linking and compilation @@ -1975,6 +1994,7 @@ USE_VORBIS ========== 1 = use vorbis from emscripten-ports +Alternate syntax: -sPORTS=vorbis .. note:: Applicable during both linking and compilation @@ -1984,6 +2004,7 @@ USE_OGG ======= 1 = use ogg from emscripten-ports +Alternate syntax: -sPORTS=ogg .. note:: Applicable during both linking and compilation @@ -1993,6 +2014,7 @@ USE_MPG123 ========== 1 = use mpg123 from emscripten-ports +Alternate syntax: -sPORTS=mpg123 .. note:: Applicable during both linking and compilation @@ -2002,6 +2024,7 @@ USE_FREETYPE ============ 1 = use freetype from emscripten-ports +Alternate syntax: -sPORTS=freetype .. note:: Applicable during both linking and compilation @@ -2021,6 +2044,7 @@ USE_HARFBUZZ ============ 1 = use harfbuzz from harfbuzz upstream +Alternate syntax: -sPORTS=harfbuzz .. note:: Applicable during both linking and compilation @@ -2030,6 +2054,7 @@ USE_COCOS2D =========== 3 = use cocos2d v3 from emscripten-ports +Alternate syntax: -sPORTS=cocos2d .. note:: Applicable during both linking and compilation @@ -2039,6 +2064,7 @@ USE_MODPLUG =========== 1 = use libmodplug from emscripten-ports +Alternate syntax: -sPORTS=libmodplug .. note:: Applicable during both linking and compilation @@ -2063,6 +2089,7 @@ USE_SQLITE3 =========== 1 = use sqlite3 from emscripten-ports +Alternate syntax: -sPORTS=sqlite3 .. note:: Applicable during both linking and compilation diff --git a/src/settings.js b/src/settings.js index bb417e8cc564e..503fbc5679fa7 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1339,6 +1339,12 @@ var EMSCRIPTEN_TRACING = false; // [link] var USE_GLFW = 0; +// Specify which ports to use. If there is only one port to use, it can be +// specified this way -sPORTS=port. If multiple ports are need, you +// specify it that way: -sPORTS=[port1,port2]. +// [link] +var PORTS = []; + // Whether to use compile code to WebAssembly. Set this to 0 to compile to JS // instead of wasm. // @@ -1455,6 +1461,7 @@ var LEGALIZE_JS_FFI = true; // 2 is a port of the SDL C code on emscripten-ports // When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL // is not linked in. +// Alternate syntax for using the port: -sPORTS=sdl2 // [compile+link] var USE_SDL = 0; @@ -1475,54 +1482,67 @@ var USE_SDL_TTF = 1; var USE_SDL_NET = 1; // 1 = use icu from emscripten-ports +// Alternate syntax: -sPORTS=icu // [compile+link] var USE_ICU = false; // 1 = use zlib from emscripten-ports +// Alternate syntax: -sPORTS=zlib // [compile+link] var USE_ZLIB = false; // 1 = use bzip2 from emscripten-ports +// Alternate syntax: -sPORTS=bzip2 // [compile+link] var USE_BZIP2 = false; // 1 = use giflib from emscripten-ports +// Alternate syntax: -sPORTS=giflib // [compile+link] var USE_GIFLIB = false; // 1 = use libjpeg from emscripten-ports +// Alternate syntax: -sPORTS=libjpeg // [compile+link] var USE_LIBJPEG = false; // 1 = use libpng from emscripten-ports +// Alternate syntax: -sPORTS=libpng // [compile+link] var USE_LIBPNG = false; // 1 = use Regal from emscripten-ports +// Alternate syntax: -sPORTS=regal // [compile+link] var USE_REGAL = false; // 1 = use Boost headers from emscripten-ports +// Alternate syntax: -sPORTS=boost_headers // [compile+link] var USE_BOOST_HEADERS = false; // 1 = use bullet from emscripten-ports +// Alternate syntax: -sPORTS=bullet // [compile+link] var USE_BULLET = false; // 1 = use vorbis from emscripten-ports +// Alternate syntax: -sPORTS=vorbis // [compile+link] var USE_VORBIS = false; // 1 = use ogg from emscripten-ports +// Alternate syntax: -sPORTS=ogg // [compile+link] var USE_OGG = false; // 1 = use mpg123 from emscripten-ports +// Alternate syntax: -sPORTS=mpg123 // [compile+link] var USE_MPG123 = false; // 1 = use freetype from emscripten-ports +// Alternate syntax: -sPORTS=freetype // [compile+link] var USE_FREETYPE = false; @@ -1532,14 +1552,17 @@ var USE_FREETYPE = false; var USE_SDL_MIXER = 1; // 1 = use harfbuzz from harfbuzz upstream +// Alternate syntax: -sPORTS=harfbuzz // [compile+link] var USE_HARFBUZZ = false; // 3 = use cocos2d v3 from emscripten-ports +// Alternate syntax: -sPORTS=cocos2d // [compile+link] var USE_COCOS2D = 0; // 1 = use libmodplug from emscripten-ports +// Alternate syntax: -sPORTS=libmodplug // [compile+link] var USE_MODPLUG = false; @@ -1553,6 +1576,7 @@ var SDL2_IMAGE_FORMATS = []; var SDL2_MIXER_FORMATS = ["ogg"]; // 1 = use sqlite3 from emscripten-ports +// Alternate syntax: -sPORTS=sqlite3 // [compile+link] var USE_SQLITE3 = false; diff --git a/test/test_browser.py b/test/test_browser.py index 5182b42d66a3d..5bbb45bdd388d 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -3335,6 +3335,8 @@ def test_sdl2_fog_simple(self): shutil.copyfile(test_file('screenshot.png'), 'screenshot.png') self.btest('test_sdl2_fog_simple.c', reference='screenshot-fog-simple.png', args=['-sUSE_SDL=2', '-sUSE_SDL_IMAGE=2', '-O2', '--minify=0', '--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '--use-preload-plugins']) + self.btest('test_sdl2_fog_simple.c', reference='screenshot-fog-simple.png', + args=['-sPORTS=[sdl2,sdl2_image]', '-O2', '--minify=0', '--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '--use-preload-plugins']) @no_wasm64('SDL2 + wasm64') @requires_graphics_hardware @@ -3389,6 +3391,8 @@ def test_sdl2_ttf(self): shutil.copy2(test_file('freetype/LiberationSansBold.ttf'), self.get_dir()) self.btest('test_sdl2_ttf.c', reference='browser/test_sdl2_ttf.png', args=['-O2', '-sUSE_SDL=2', '-sUSE_SDL_TTF=2', '--embed-file', 'LiberationSansBold.ttf']) + self.btest('test_sdl2_ttf.c', reference='browser/test_sdl2_ttf.png', + args=['-O2', '-sPORTS=[sdl2,sdl2_ttf]', '--embed-file', 'LiberationSansBold.ttf']) @no_wasm64('SDL2 + wasm64') @requires_graphics_hardware diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 50b2c333e476a..34001b5cbf49d 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -31,39 +31,46 @@ logger = logging.getLogger('ports') +def load_port(name): + expected_attrs = ['get', 'clear', 'show', 'needed'] + port = __import__(name, globals(), level=1) + ports.append(port) + port.name = name + ports_by_name[port.name] = port + for a in expected_attrs: + assert hasattr(port, a), 'port %s is missing %s' % (port, a) + needed = port.needed + port.needed = lambda s: needed(s) or name in s.PORTS + if not hasattr(port, 'process_dependencies'): + port.process_dependencies = lambda x: 0 + if not hasattr(port, 'linker_setup'): + port.linker_setup = lambda x, y: 0 + if not hasattr(port, 'deps'): + port.deps = [] + if not hasattr(port, 'process_args'): + port.process_args = lambda x: [] + if not hasattr(port, 'variants'): + # port variants (default: no variants) + port.variants = {} + + for variant, extra_settings in port.variants.items(): + if variant in port_variants: + utils.exit_with_error('duplicate port variant: %s' % variant) + port_variants[variant] = (port.name, extra_settings) + + @ToolchainProfiler.profile() def read_ports(): - expected_attrs = ['get', 'clear', 'show', 'needed'] for filename in os.listdir(ports_dir): if not filename.endswith('.py') or filename == '__init__.py': continue filename = os.path.splitext(filename)[0] - port = __import__(filename, globals(), level=1) - ports.append(port) - port.name = filename - ports_by_name[port.name] = port - for a in expected_attrs: - assert hasattr(port, a), 'port %s is missing %s' % (port, a) - if not hasattr(port, 'process_dependencies'): - port.process_dependencies = lambda x: 0 - if not hasattr(port, 'linker_setup'): - port.linker_setup = lambda x, y: 0 - if not hasattr(port, 'deps'): - port.deps = [] - if not hasattr(port, 'process_args'): - port.process_args = lambda x: [] - if not hasattr(port, 'variants'): - # port variants (default: no variants) - port.variants = {} - - for variant, extra_settings in port.variants.items(): - if variant in port_variants: - utils.exit_with_error('duplicate port variant: %s' % variant) - port_variants[variant] = (port.name, extra_settings) - - for dep in port.deps: - if dep not in ports_by_name: - utils.exit_with_error('unknown dependency in port: %s' % dep) + load_port(filename) + + for port in ports: + for dep in port.deps: + if dep not in ports_by_name: + utils.exit_with_error('unknown dependency in port: %s' % dep) def get_all_files_under(dirname): diff --git a/tools/ports/boost_headers.py b/tools/ports/boost_headers.py index 087970563e07d..1bc60c2800a8e 100644 --- a/tools/ports/boost_headers.py +++ b/tools/ports/boost_headers.py @@ -44,4 +44,4 @@ def process_args(ports): def show(): - return 'Boost headers v1.70.0 (USE_BOOST_HEADERS=1; Boost license)' + return 'Boost headers v1.70.0 (-sUSE_BOOST_HEADERS=1 or -sPORTS=boost_headers; Boost license)' diff --git a/tools/ports/bullet.py b/tools/ports/bullet.py index 0f6dedc1ef9ea..dfabe347ec568 100644 --- a/tools/ports/bullet.py +++ b/tools/ports/bullet.py @@ -56,4 +56,4 @@ def process_args(ports): def show(): - return 'bullet (USE_BULLET=1; zlib license)' + return 'bullet (-sUSE_BULLET=1 or -sPORTS=bullet; zlib license)' diff --git a/tools/ports/bzip2.py b/tools/ports/bzip2.py index b1b7605563ed8..0eee9d13947aa 100644 --- a/tools/ports/bzip2.py +++ b/tools/ports/bzip2.py @@ -35,4 +35,4 @@ def clear(ports, settings, shared): def show(): - return 'bzip2 (USE_BZIP2=1; BSD license)' + return 'bzip2 (-sUSE_BZIP2=1 or -sPORTS=bzip2; BSD license)' diff --git a/tools/ports/cocos2d.py b/tools/ports/cocos2d.py index 6ffe7cb790872..b9c83f9694517 100644 --- a/tools/ports/cocos2d.py +++ b/tools/ports/cocos2d.py @@ -74,7 +74,7 @@ def process_args(ports): def show(): - return 'cocos2d' + return 'cocos2d (-sUSE_COCOS2D=3 or -sPORTS=cocos2d)' def make_source_list(cocos2d_root, cocos2dx_root): diff --git a/tools/ports/freetype.py b/tools/ports/freetype.py index d419bd53c6189..37c30eaebdc74 100644 --- a/tools/ports/freetype.py +++ b/tools/ports/freetype.py @@ -116,7 +116,7 @@ def process_args(ports): def show(): - return 'freetype (USE_FREETYPE=1; freetype license)' + return 'freetype (-sUSE_FREETYPE=1 or -sPORTS=freetype; freetype license)' ftconf_h = r'''/***************************************************************************/ diff --git a/tools/ports/giflib.py b/tools/ports/giflib.py index efc549ca543b1..adebcdffc531b 100644 --- a/tools/ports/giflib.py +++ b/tools/ports/giflib.py @@ -34,4 +34,4 @@ def clear(ports, settings, shared): def show(): - return 'giflib (USE_GIFLIB=1; MIT license)' + return 'giflib (-sUSE_GIFLIB=1 or -sPORTS=giflib; MIT license)' diff --git a/tools/ports/harfbuzz.py b/tools/ports/harfbuzz.py index 73d35c7d8a127..acab723a83940 100644 --- a/tools/ports/harfbuzz.py +++ b/tools/ports/harfbuzz.py @@ -152,4 +152,4 @@ def process_args(ports): def show(): - return 'harfbuzz (USE_HARFBUZZ=1; MIT license)' + return 'harfbuzz (-sUSE_HARFBUZZ=1 or -sPORTS=harfbuzz; MIT license)' diff --git a/tools/ports/icu.py b/tools/ports/icu.py index 9dfef378090db..25d9119e9f001 100644 --- a/tools/ports/icu.py +++ b/tools/ports/icu.py @@ -100,4 +100,4 @@ def clear(ports, settings, shared): def show(): - return 'icu (USE_ICU=1; Unicode License)' + return 'icu (-sUSE_ICU=1 or -sPORTS=icu; Unicode License)' diff --git a/tools/ports/libjpeg.py b/tools/ports/libjpeg.py index 291716a932362..c166ce0417323 100644 --- a/tools/ports/libjpeg.py +++ b/tools/ports/libjpeg.py @@ -38,7 +38,7 @@ def clear(ports, settings, shared): def show(): - return 'libjpeg (USE_LIBJPEG=1; BSD license)' + return 'libjpeg (-sUSE_LIBJPEG=1 or -sPORTS=libjpeg; BSD license)' jconfig_h = '''/* jconfig.h. Generated from jconfig.cfg by configure. */ diff --git a/tools/ports/libmodplug.py b/tools/ports/libmodplug.py index e1e67954fc8b9..24b363fd9c318 100644 --- a/tools/ports/libmodplug.py +++ b/tools/ports/libmodplug.py @@ -88,7 +88,7 @@ def clear(ports, settings, shared): def show(): - return 'libmodplug (USE_MODPLUG=1; public domain)' + return 'libmodplug (-sUSE_MODPLUG=1 or -sPORTS=libmodplug; public domain)' config_h = '''/* src/config.h. Generated from config.h.in by configure. */ diff --git a/tools/ports/libpng.py b/tools/ports/libpng.py index 24ac177d029e6..df115f5571a39 100644 --- a/tools/ports/libpng.py +++ b/tools/ports/libpng.py @@ -58,7 +58,7 @@ def process_dependencies(settings): def show(): - return 'libpng (-sUSE_LIBPNG; zlib license)' + return 'libpng (-sUSE_LIBPNG or -sPORTS=libpng; zlib license)' pnglibconf_h = r'''/* pnglibconf.h - library build configuration */ diff --git a/tools/ports/mpg123.py b/tools/ports/mpg123.py index b641b91969c12..65476765d54e5 100644 --- a/tools/ports/mpg123.py +++ b/tools/ports/mpg123.py @@ -81,7 +81,7 @@ def clear(ports, settings, shared): def show(): - return 'mpg123 (USE_MPG123=1; zlib license)' + return 'mpg123 (-sUSE_MPG123=1 or -sPORTS=mpg123; zlib license)' config_h = r'''/* src/config.h. Generated from config.h.in by configure. */ diff --git a/tools/ports/ogg.py b/tools/ports/ogg.py index 9eff54d289d81..47007ba1b7e04 100644 --- a/tools/ports/ogg.py +++ b/tools/ports/ogg.py @@ -30,7 +30,7 @@ def clear(ports, settings, shared): def show(): - return 'ogg (USE_OGG=1; zlib license)' + return 'ogg (-sUSE_OGG=1 or -sPORTS=ogg; zlib license)' config_types_h = '''\ diff --git a/tools/ports/regal.py b/tools/ports/regal.py index e699c4e72a94b..9652cb878b265 100644 --- a/tools/ports/regal.py +++ b/tools/ports/regal.py @@ -126,4 +126,4 @@ def linker_setup(ports, settings): def show(): - return 'regal (USE_REGAL=1; Regal license)' + return 'regal (-sUSE_REGAL=1 or -sPORTS=regal; Regal license)' diff --git a/tools/ports/sdl2.py b/tools/ports/sdl2.py index 3378084372e64..ee7f3d7c1d012 100644 --- a/tools/ports/sdl2.py +++ b/tools/ports/sdl2.py @@ -91,4 +91,4 @@ def process_args(ports): def show(): - return 'SDL2 (USE_SDL=2; zlib license)' + return 'SDL2 (-sUSE_SDL=2 or -sPORTS=sdl2; zlib license)' diff --git a/tools/ports/sdl2_gfx.py b/tools/ports/sdl2_gfx.py index 74b5aad3d4e25..14b8691866851 100644 --- a/tools/ports/sdl2_gfx.py +++ b/tools/ports/sdl2_gfx.py @@ -37,4 +37,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_gfx (zlib license)' + return 'SDL2_gfx (-sUSE_SDL_GFX=2 or -sPORTS=sdl2_gfx; zlib license)' diff --git a/tools/ports/sdl2_image.py b/tools/ports/sdl2_image.py index 90fb2834094d1..fad9842c2bd5f 100644 --- a/tools/ports/sdl2_image.py +++ b/tools/ports/sdl2_image.py @@ -73,4 +73,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_image (USE_SDL_IMAGE=2; zlib license)' + return 'SDL2_image (-sUSE_SDL_IMAGE=2 or -sPORTS=sdl2_image; zlib license)' diff --git a/tools/ports/sdl2_mixer.py b/tools/ports/sdl2_mixer.py index b759c3b43a2a2..968db1b7df27c 100644 --- a/tools/ports/sdl2_mixer.py +++ b/tools/ports/sdl2_mixer.py @@ -115,4 +115,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_mixer (USE_SDL_MIXER=2; zlib license)' + return 'SDL2_mixer (-sUSE_SDL_MIXER=2 or -sPORTS=sdl2_mixer; zlib license)' diff --git a/tools/ports/sdl2_net.py b/tools/ports/sdl2_net.py index ec62e1a2e55cd..988381ee7d68c 100644 --- a/tools/ports/sdl2_net.py +++ b/tools/ports/sdl2_net.py @@ -38,4 +38,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_net (zlib license)' + return 'SDL2_net (-sUSE_SDL_NET=2 or -sPORTS=sdl2_net; zlib license)' diff --git a/tools/ports/sdl2_ttf.py b/tools/ports/sdl2_ttf.py index db7674ff3f2c6..e7cffc61778d1 100644 --- a/tools/ports/sdl2_ttf.py +++ b/tools/ports/sdl2_ttf.py @@ -42,4 +42,4 @@ def process_args(ports): def show(): - return 'SDL2_ttf (-sUSE_SDL_TTF=2; zlib license)' + return 'SDL2_ttf (-sUSE_SDL_TTF=2 or -sPORTS=sdl2_ttf; zlib license)' diff --git a/tools/ports/sqlite3.py b/tools/ports/sqlite3.py index 8bc49dbe2861d..f22f32c1da806 100644 --- a/tools/ports/sqlite3.py +++ b/tools/ports/sqlite3.py @@ -78,4 +78,4 @@ def clear(ports, settings, shared): def show(): - return 'sqlite (USE_SQLITE3=1); public domain)' + return 'sqlite (-sUSE_SQLITE3=1 or -sPORTS=sqlite3); public domain)' diff --git a/tools/ports/vorbis.py b/tools/ports/vorbis.py index 0f95756c1394e..d12ef97650de4 100644 --- a/tools/ports/vorbis.py +++ b/tools/ports/vorbis.py @@ -37,4 +37,4 @@ def process_dependencies(settings): def show(): - return 'vorbis (-sUSE_VORBIS; zlib license)' + return 'vorbis (-sUSE_VORBIS or -sPORTS=vorbis; zlib license)' diff --git a/tools/ports/zlib.py b/tools/ports/zlib.py index d78fb7e0fb62e..d614541ddbc7b 100644 --- a/tools/ports/zlib.py +++ b/tools/ports/zlib.py @@ -34,7 +34,7 @@ def clear(ports, settings, shared): def show(): - return 'zlib (USE_ZLIB=1; zlib license)' + return 'zlib (-sUSE_ZLIB=1 or -sPORTS=zlib; zlib license)' zconf_h = r'''/* zconf.h -- configuration of the zlib compression library diff --git a/tools/settings.py b/tools/settings.py index 67d01f2b98859..75668a7dd7d42 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -52,6 +52,7 @@ 'SDL2_MIXER_FORMATS', 'SDL2_IMAGE_FORMATS', 'USE_SQLITE3', + 'PORTS' } # Subset of settings that apply only when generating JS From d135cd47269e456d1b1b05def593a515867f165c Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Tue, 30 Jan 2024 06:01:28 -0800 Subject: [PATCH 02/27] check for valid port name - added tests --- emcc.py | 2 ++ test/test_browser.py | 4 ---- test/test_other.py | 20 ++++++++++++++++++++ tools/ports/__init__.py | 15 ++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/emcc.py b/emcc.py index 8870027348fcf..b8c89fd55098f 100644 --- a/emcc.py +++ b/emcc.py @@ -287,6 +287,8 @@ def apply_user_settings(): if key == 'WASM_OBJECT_FILES': settings.LTO = 0 if value else 'full' + ports.check_ports_settings(settings) + def cxx_to_c_compiler(cxx): # Convert C++ compiler name into C compiler name diff --git a/test/test_browser.py b/test/test_browser.py index 5bbb45bdd388d..5182b42d66a3d 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -3335,8 +3335,6 @@ def test_sdl2_fog_simple(self): shutil.copyfile(test_file('screenshot.png'), 'screenshot.png') self.btest('test_sdl2_fog_simple.c', reference='screenshot-fog-simple.png', args=['-sUSE_SDL=2', '-sUSE_SDL_IMAGE=2', '-O2', '--minify=0', '--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '--use-preload-plugins']) - self.btest('test_sdl2_fog_simple.c', reference='screenshot-fog-simple.png', - args=['-sPORTS=[sdl2,sdl2_image]', '-O2', '--minify=0', '--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '--use-preload-plugins']) @no_wasm64('SDL2 + wasm64') @requires_graphics_hardware @@ -3391,8 +3389,6 @@ def test_sdl2_ttf(self): shutil.copy2(test_file('freetype/LiberationSansBold.ttf'), self.get_dir()) self.btest('test_sdl2_ttf.c', reference='browser/test_sdl2_ttf.png', args=['-O2', '-sUSE_SDL=2', '-sUSE_SDL_TTF=2', '--embed-file', 'LiberationSansBold.ttf']) - self.btest('test_sdl2_ttf.c', reference='browser/test_sdl2_ttf.png', - args=['-O2', '-sPORTS=[sdl2,sdl2_ttf]', '--embed-file', 'LiberationSansBold.ttf']) @no_wasm64('SDL2 + wasm64') @requires_graphics_hardware diff --git a/test/test_other.py b/test/test_other.py index 7191bc1120e82..36f7df166f9e8 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2250,20 +2250,25 @@ def test_sdl_scan_code_from_key(self): def test_sdl2_mixer_wav(self): self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sUSE_SDL_MIXER=2'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sPORTS=sdl2_mixer'], output_filename='a.out.js') def test_sdl2_linkable(self): # Ensure that SDL2 can be built with LINKABLE. This implies there are no undefined # symbols in the library (because LINKABLE includes the entire library). self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '-sUSE_SDL=2'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '-sPORTS=sdl2'], output_filename='a.out.js') def test_sdl2_gfx_linkable(self): # Same as above but for sdl2_gfx library self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '-sUSE_SDL_GFX=2'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '-sPORTS=sdl2_gfx'], output_filename='a.out.js') def test_libpng(self): shutil.copyfile(test_file('third_party/libpng/pngtest.png'), 'pngtest.png') self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test', emcc_args=['--embed-file', 'pngtest.png', '-sUSE_LIBPNG']) + self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test', + emcc_args=['--embed-file', 'pngtest.png', '-sPORTS=libpng']) @node_pthreads def test_libpng_with_pthreads(self): @@ -2284,23 +2289,34 @@ def test_giflib(self): 'GIF file terminated normally', emcc_args=['--embed-file', 'treescap.gif', '-sUSE_GIFLIB', '-sMAIN_MODULE'], args=['treescap.gif']) + self.do_runf('third_party/giflib/giftext.c', + 'GIF file terminated normally', + emcc_args=['--embed-file', 'treescap.gif', '-sPORTS=giflib'], + args=['treescap.gif']) def test_libjpeg(self): shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.jpg') self.do_runf('jpeg_test.c', 'Image is 600 by 450 with 3 components', emcc_args=['--embed-file', 'screenshot.jpg', '-sUSE_LIBJPEG'], args=['screenshot.jpg']) + self.do_runf('jpeg_test.c', 'Image is 600 by 450 with 3 components', + emcc_args=['--embed-file', 'screenshot.jpg', '-sPORTS=libjpeg'], + args=['screenshot.jpg']) def test_bullet(self): self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['-sUSE_BULLET']) + self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['-sPORTS=bullet']) def test_vorbis(self): # This will also test if ogg compiles, because vorbis depends on ogg self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['-sUSE_VORBIS']) + self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['-sPORTS=vorbis']) def test_bzip2(self): self.do_runf('bzip2_test.c', 'usage: unzcrash filename', emcc_args=['-sUSE_BZIP2', '-Wno-pointer-sign']) + self.do_runf('bzip2_test.c', 'usage: unzcrash filename', + emcc_args=['-sPORTS=bzip2', '-Wno-pointer-sign']) @with_both_sjlj def test_freetype(self): @@ -2328,6 +2344,8 @@ def test_freetype(self): # build test program with the font file embed in it self.do_runf('freetype_test.c', expectedOutput, emcc_args=['-sUSE_FREETYPE', '--embed-file', 'LiberationSansBold.ttf']) + self.do_runf('freetype_test.c', expectedOutput, + emcc_args=['-sPORTS=freetype', '--embed-file', 'LiberationSansBold.ttf']) def test_freetype_with_pthreads(self): # Verify that freetype supports compilation requiring pthreads @@ -2340,6 +2358,7 @@ def test_icu(self): def test_sdl2_ttf(self): # This is a compile-only to test to verify that sdl2-ttf (and freetype and harfbuzz) are buildable. self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sPORTS=sdl2_ttf'], output_filename='a.out.js') def test_link_memcpy(self): # memcpy can show up *after* optimizations, so after our opportunity to link in libc, so it must be special-cased @@ -11411,6 +11430,7 @@ def test_em_asm_invalid(self): def test_boost_graph(self): self.do_runf('test_boost_graph.cpp', emcc_args=['-std=c++14', '-sUSE_BOOST_HEADERS']) + self.do_runf('test_boost_graph.cpp', emcc_args=['-std=c++14', '-sPORTS=boost_headers']) def test_setjmp_em_asm(self): create_file('src.c', ''' diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 34001b5cbf49d..dbe866c4891fa 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -32,15 +32,18 @@ def load_port(name): - expected_attrs = ['get', 'clear', 'show', 'needed'] + expected_attrs = ['get', 'clear', 'show'] port = __import__(name, globals(), level=1) ports.append(port) port.name = name ports_by_name[port.name] = port for a in expected_attrs: assert hasattr(port, a), 'port %s is missing %s' % (port, a) - needed = port.needed - port.needed = lambda s: needed(s) or name in s.PORTS + if not hasattr(port, 'needed'): + port.needed = lambda s: name in s.PORTS + else: + needed = port.needed + port.needed = lambda s: needed(s) or name in s.PORTS if not hasattr(port, 'process_dependencies'): port.process_dependencies = lambda x: 0 if not hasattr(port, 'linker_setup'): @@ -368,6 +371,12 @@ def add_deps(node): add_deps(port) +def check_ports_settings(settings): + for name in settings.PORTS: + if name not in ports_by_name: + utils.exit_with_error(f'Invalid port name: {name}') + + def get_needed_ports(settings): # Start with directly needed ports, and transitively add dependencies needed = set(p for p in ports if p.needed(settings)) From 831c52339a976e6fc876ecf5892a573ba40db23b Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 07:15:28 -0800 Subject: [PATCH 03/27] use --use-port instead of -sPORTS --- emcc.py | 4 +- site/source/docs/tools_reference/emcc.rst | 8 ++++ .../tools_reference/settings_reference.rst | 45 ++++++++----------- src/settings.js | 42 ++++++++--------- src/settings_internal.js | 4 ++ test/test_other.py | 24 +++++----- tools/ports/__init__.py | 10 ++--- tools/ports/boost_headers.py | 2 +- tools/ports/bullet.py | 2 +- tools/ports/bzip2.py | 2 +- tools/ports/cocos2d.py | 2 +- tools/ports/freetype.py | 2 +- tools/ports/giflib.py | 2 +- tools/ports/harfbuzz.py | 2 +- tools/ports/icu.py | 2 +- tools/ports/libjpeg.py | 2 +- tools/ports/libmodplug.py | 2 +- tools/ports/libpng.py | 2 +- tools/ports/mpg123.py | 2 +- tools/ports/ogg.py | 2 +- tools/ports/regal.py | 2 +- tools/ports/sdl2.py | 2 +- tools/ports/sdl2_gfx.py | 2 +- tools/ports/sdl2_image.py | 2 +- tools/ports/sdl2_mixer.py | 2 +- tools/ports/sdl2_net.py | 2 +- tools/ports/sdl2_ttf.py | 2 +- tools/ports/sqlite3.py | 2 +- tools/ports/vorbis.py | 2 +- tools/ports/zlib.py | 2 +- 30 files changed, 90 insertions(+), 93 deletions(-) diff --git a/emcc.py b/emcc.py index b8c89fd55098f..9f6afb7d54109 100644 --- a/emcc.py +++ b/emcc.py @@ -287,8 +287,6 @@ def apply_user_settings(): if key == 'WASM_OBJECT_FILES': settings.LTO = 0 if value else 'full' - ports.check_ports_settings(settings) - def cxx_to_c_compiler(cxx): # Convert C++ compiler name into C compiler name @@ -1407,6 +1405,8 @@ def consume_arg_file(): options.target = consume_arg() if options.target not in ('wasm32', 'wasm64', 'wasm64-unknown-emscripten', 'wasm32-unknown-emscripten'): exit_with_error(f'unsupported target: {options.target} (emcc only supports wasm64-unknown-emscripten and wasm32-unknown-emscripten)') + elif check_arg('--use-port'): + ports.handle_use_port_arg(settings, consume_arg()) elif arg == '-mllvm': # Ignore the next argument rather than trying to parse it. This is needed # because llvm args could, for example, start with `-o` and we don't want diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index 8527aa4f3f531..010c5dcca9604 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -455,6 +455,14 @@ Options that are modified or new in *emcc* are listed below: By default this will also clear any download ports since the ports directory is usually within the cache directory. +.. _emcc-use-port: + +``--use-port=`` + [link] + Use the specified port. If you need to use more than one port you can use this + argument multiple times. For example: ``--user-port=sdl2 --user-port=bzip2``. + To get the list of available ports, use ``--show-ports``. + .. _emcc-clear-ports: ``--clear-ports`` diff --git a/site/source/docs/tools_reference/settings_reference.rst b/site/source/docs/tools_reference/settings_reference.rst index f8bad6a12cad1..2e399acfda1d6 100644 --- a/site/source/docs/tools_reference/settings_reference.rst +++ b/site/source/docs/tools_reference/settings_reference.rst @@ -1700,15 +1700,6 @@ Specify the GLFW version that is being linked against. Only relevant, if you are linking against the GLFW library. Valid options are 2 for GLFW2 and 3 for GLFW3. -.. _ports: - -PORTS -===== - -Specify which ports to use. If there is only one port to use, it can be -specified this way -sPORTS=port. If multiple ports are need, you -specify it that way: -sPORTS=[port1,port2]. - .. _wasm: WASM @@ -1858,7 +1849,7 @@ Specify the SDL version that is being linked against. 2 is a port of the SDL C code on emscripten-ports When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL is not linked in. -Alternate syntax for using the port: -sPORTS=sdl2 +Alternate syntax for using the port: --use-port=sdl2 .. note:: Applicable during both linking and compilation @@ -1904,7 +1895,7 @@ USE_ICU ======= 1 = use icu from emscripten-ports -Alternate syntax: -sPORTS=icu +Alternate syntax: --use-port=icu .. note:: Applicable during both linking and compilation @@ -1914,7 +1905,7 @@ USE_ZLIB ======== 1 = use zlib from emscripten-ports -Alternate syntax: -sPORTS=zlib +Alternate syntax: --use-port=zlib .. note:: Applicable during both linking and compilation @@ -1924,7 +1915,7 @@ USE_BZIP2 ========= 1 = use bzip2 from emscripten-ports -Alternate syntax: -sPORTS=bzip2 +Alternate syntax: --use-port=bzip2 .. note:: Applicable during both linking and compilation @@ -1934,7 +1925,7 @@ USE_GIFLIB ========== 1 = use giflib from emscripten-ports -Alternate syntax: -sPORTS=giflib +Alternate syntax: --use-port=giflib .. note:: Applicable during both linking and compilation @@ -1944,7 +1935,7 @@ USE_LIBJPEG =========== 1 = use libjpeg from emscripten-ports -Alternate syntax: -sPORTS=libjpeg +Alternate syntax: --use-port=libjpeg .. note:: Applicable during both linking and compilation @@ -1954,7 +1945,7 @@ USE_LIBPNG ========== 1 = use libpng from emscripten-ports -Alternate syntax: -sPORTS=libpng +Alternate syntax: --use-port=libpng .. note:: Applicable during both linking and compilation @@ -1964,7 +1955,7 @@ USE_REGAL ========= 1 = use Regal from emscripten-ports -Alternate syntax: -sPORTS=regal +Alternate syntax: --use-port=regal .. note:: Applicable during both linking and compilation @@ -1974,7 +1965,7 @@ USE_BOOST_HEADERS ================= 1 = use Boost headers from emscripten-ports -Alternate syntax: -sPORTS=boost_headers +Alternate syntax: --use-port=boost_headers .. note:: Applicable during both linking and compilation @@ -1984,7 +1975,7 @@ USE_BULLET ========== 1 = use bullet from emscripten-ports -Alternate syntax: -sPORTS=bullet +Alternate syntax: --use-port=bullet .. note:: Applicable during both linking and compilation @@ -1994,7 +1985,7 @@ USE_VORBIS ========== 1 = use vorbis from emscripten-ports -Alternate syntax: -sPORTS=vorbis +Alternate syntax: --use-port=vorbis .. note:: Applicable during both linking and compilation @@ -2004,7 +1995,7 @@ USE_OGG ======= 1 = use ogg from emscripten-ports -Alternate syntax: -sPORTS=ogg +Alternate syntax: --use-port=ogg .. note:: Applicable during both linking and compilation @@ -2014,7 +2005,7 @@ USE_MPG123 ========== 1 = use mpg123 from emscripten-ports -Alternate syntax: -sPORTS=mpg123 +Alternate syntax: --use-port=mpg123 .. note:: Applicable during both linking and compilation @@ -2024,7 +2015,7 @@ USE_FREETYPE ============ 1 = use freetype from emscripten-ports -Alternate syntax: -sPORTS=freetype +Alternate syntax: --use-port=freetype .. note:: Applicable during both linking and compilation @@ -2044,7 +2035,7 @@ USE_HARFBUZZ ============ 1 = use harfbuzz from harfbuzz upstream -Alternate syntax: -sPORTS=harfbuzz +Alternate syntax: --use-port=harfbuzz .. note:: Applicable during both linking and compilation @@ -2054,7 +2045,7 @@ USE_COCOS2D =========== 3 = use cocos2d v3 from emscripten-ports -Alternate syntax: -sPORTS=cocos2d +Alternate syntax: --use-port=cocos2d .. note:: Applicable during both linking and compilation @@ -2064,7 +2055,7 @@ USE_MODPLUG =========== 1 = use libmodplug from emscripten-ports -Alternate syntax: -sPORTS=libmodplug +Alternate syntax: --use-port=libmodplug .. note:: Applicable during both linking and compilation @@ -2089,7 +2080,7 @@ USE_SQLITE3 =========== 1 = use sqlite3 from emscripten-ports -Alternate syntax: -sPORTS=sqlite3 +Alternate syntax: --use-port=sqlite3 .. note:: Applicable during both linking and compilation diff --git a/src/settings.js b/src/settings.js index 503fbc5679fa7..df9e86b40e063 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1339,12 +1339,6 @@ var EMSCRIPTEN_TRACING = false; // [link] var USE_GLFW = 0; -// Specify which ports to use. If there is only one port to use, it can be -// specified this way -sPORTS=port. If multiple ports are need, you -// specify it that way: -sPORTS=[port1,port2]. -// [link] -var PORTS = []; - // Whether to use compile code to WebAssembly. Set this to 0 to compile to JS // instead of wasm. // @@ -1461,7 +1455,7 @@ var LEGALIZE_JS_FFI = true; // 2 is a port of the SDL C code on emscripten-ports // When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL // is not linked in. -// Alternate syntax for using the port: -sPORTS=sdl2 +// Alternate syntax for using the port: --use-port=sdl2 // [compile+link] var USE_SDL = 0; @@ -1482,67 +1476,67 @@ var USE_SDL_TTF = 1; var USE_SDL_NET = 1; // 1 = use icu from emscripten-ports -// Alternate syntax: -sPORTS=icu +// Alternate syntax: --use-port=icu // [compile+link] var USE_ICU = false; // 1 = use zlib from emscripten-ports -// Alternate syntax: -sPORTS=zlib +// Alternate syntax: --use-port=zlib // [compile+link] var USE_ZLIB = false; // 1 = use bzip2 from emscripten-ports -// Alternate syntax: -sPORTS=bzip2 +// Alternate syntax: --use-port=bzip2 // [compile+link] var USE_BZIP2 = false; // 1 = use giflib from emscripten-ports -// Alternate syntax: -sPORTS=giflib +// Alternate syntax: --use-port=giflib // [compile+link] var USE_GIFLIB = false; // 1 = use libjpeg from emscripten-ports -// Alternate syntax: -sPORTS=libjpeg +// Alternate syntax: --use-port=libjpeg // [compile+link] var USE_LIBJPEG = false; // 1 = use libpng from emscripten-ports -// Alternate syntax: -sPORTS=libpng +// Alternate syntax: --use-port=libpng // [compile+link] var USE_LIBPNG = false; // 1 = use Regal from emscripten-ports -// Alternate syntax: -sPORTS=regal +// Alternate syntax: --use-port=regal // [compile+link] var USE_REGAL = false; // 1 = use Boost headers from emscripten-ports -// Alternate syntax: -sPORTS=boost_headers +// Alternate syntax: --use-port=boost_headers // [compile+link] var USE_BOOST_HEADERS = false; // 1 = use bullet from emscripten-ports -// Alternate syntax: -sPORTS=bullet +// Alternate syntax: --use-port=bullet // [compile+link] var USE_BULLET = false; // 1 = use vorbis from emscripten-ports -// Alternate syntax: -sPORTS=vorbis +// Alternate syntax: --use-port=vorbis // [compile+link] var USE_VORBIS = false; // 1 = use ogg from emscripten-ports -// Alternate syntax: -sPORTS=ogg +// Alternate syntax: --use-port=ogg // [compile+link] var USE_OGG = false; // 1 = use mpg123 from emscripten-ports -// Alternate syntax: -sPORTS=mpg123 +// Alternate syntax: --use-port=mpg123 // [compile+link] var USE_MPG123 = false; // 1 = use freetype from emscripten-ports -// Alternate syntax: -sPORTS=freetype +// Alternate syntax: --use-port=freetype // [compile+link] var USE_FREETYPE = false; @@ -1552,17 +1546,17 @@ var USE_FREETYPE = false; var USE_SDL_MIXER = 1; // 1 = use harfbuzz from harfbuzz upstream -// Alternate syntax: -sPORTS=harfbuzz +// Alternate syntax: --use-port=harfbuzz // [compile+link] var USE_HARFBUZZ = false; // 3 = use cocos2d v3 from emscripten-ports -// Alternate syntax: -sPORTS=cocos2d +// Alternate syntax: --use-port=cocos2d // [compile+link] var USE_COCOS2D = 0; // 1 = use libmodplug from emscripten-ports -// Alternate syntax: -sPORTS=libmodplug +// Alternate syntax: --use-port=libmodplug // [compile+link] var USE_MODPLUG = false; @@ -1576,7 +1570,7 @@ var SDL2_IMAGE_FORMATS = []; var SDL2_MIXER_FORMATS = ["ogg"]; // 1 = use sqlite3 from emscripten-ports -// Alternate syntax: -sPORTS=sqlite3 +// Alternate syntax: --use-port=sqlite3 // [compile+link] var USE_SQLITE3 = false; diff --git a/src/settings_internal.js b/src/settings_internal.js index 36a1887540a84..678b6ee0fae72 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -273,3 +273,7 @@ var BULK_MEMORY = false; var MINIFY_WHITESPACE = true; var ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = []; + +// Specify which ports to use. This is set via the --use-port command line +// option +var PORTS = []; diff --git a/test/test_other.py b/test/test_other.py index 5dc57fd302fcd..e2da26696eb32 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2250,25 +2250,25 @@ def test_sdl_scan_code_from_key(self): def test_sdl2_mixer_wav(self): self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sUSE_SDL_MIXER=2'], output_filename='a.out.js') - self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sPORTS=sdl2_mixer'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['--use-port=sdl2_mixer'], output_filename='a.out.js') def test_sdl2_linkable(self): # Ensure that SDL2 can be built with LINKABLE. This implies there are no undefined # symbols in the library (because LINKABLE includes the entire library). self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '-sUSE_SDL=2'], output_filename='a.out.js') - self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '-sPORTS=sdl2'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '--use-port=sdl2'], output_filename='a.out.js') def test_sdl2_gfx_linkable(self): # Same as above but for sdl2_gfx library self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '-sUSE_SDL_GFX=2'], output_filename='a.out.js') - self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '-sPORTS=sdl2_gfx'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '--use-port=sdl2_gfx'], output_filename='a.out.js') def test_libpng(self): shutil.copyfile(test_file('third_party/libpng/pngtest.png'), 'pngtest.png') self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test', emcc_args=['--embed-file', 'pngtest.png', '-sUSE_LIBPNG']) self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test', - emcc_args=['--embed-file', 'pngtest.png', '-sPORTS=libpng']) + emcc_args=['--embed-file', 'pngtest.png', '--use-port=libpng']) @node_pthreads def test_libpng_with_pthreads(self): @@ -2291,7 +2291,7 @@ def test_giflib(self): args=['treescap.gif']) self.do_runf('third_party/giflib/giftext.c', 'GIF file terminated normally', - emcc_args=['--embed-file', 'treescap.gif', '-sPORTS=giflib'], + emcc_args=['--embed-file', 'treescap.gif', '--use-port=giflib'], args=['treescap.gif']) def test_libjpeg(self): @@ -2300,23 +2300,23 @@ def test_libjpeg(self): emcc_args=['--embed-file', 'screenshot.jpg', '-sUSE_LIBJPEG'], args=['screenshot.jpg']) self.do_runf('jpeg_test.c', 'Image is 600 by 450 with 3 components', - emcc_args=['--embed-file', 'screenshot.jpg', '-sPORTS=libjpeg'], + emcc_args=['--embed-file', 'screenshot.jpg', '--use-port=libjpeg'], args=['screenshot.jpg']) def test_bullet(self): self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['-sUSE_BULLET']) - self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['-sPORTS=bullet']) + self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['--use-port=bullet']) def test_vorbis(self): # This will also test if ogg compiles, because vorbis depends on ogg self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['-sUSE_VORBIS']) - self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['-sPORTS=vorbis']) + self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['--use-port=vorbis']) def test_bzip2(self): self.do_runf('bzip2_test.c', 'usage: unzcrash filename', emcc_args=['-sUSE_BZIP2', '-Wno-pointer-sign']) self.do_runf('bzip2_test.c', 'usage: unzcrash filename', - emcc_args=['-sPORTS=bzip2', '-Wno-pointer-sign']) + emcc_args=['--use-port=bzip2', '-Wno-pointer-sign']) @with_both_sjlj def test_freetype(self): @@ -2345,7 +2345,7 @@ def test_freetype(self): self.do_runf('freetype_test.c', expectedOutput, emcc_args=['-sUSE_FREETYPE', '--embed-file', 'LiberationSansBold.ttf']) self.do_runf('freetype_test.c', expectedOutput, - emcc_args=['-sPORTS=freetype', '--embed-file', 'LiberationSansBold.ttf']) + emcc_args=['--use-port=freetype', '--embed-file', 'LiberationSansBold.ttf']) def test_freetype_with_pthreads(self): # Verify that freetype supports compilation requiring pthreads @@ -2358,7 +2358,7 @@ def test_icu(self): def test_sdl2_ttf(self): # This is a compile-only to test to verify that sdl2-ttf (and freetype and harfbuzz) are buildable. self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js') - self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sPORTS=sdl2_ttf'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['--use-port=sdl2_ttf'], output_filename='a.out.js') def test_link_memcpy(self): # memcpy can show up *after* optimizations, so after our opportunity to link in libc, so it must be special-cased @@ -11430,7 +11430,7 @@ def test_em_asm_invalid(self): def test_boost_graph(self): self.do_runf('test_boost_graph.cpp', emcc_args=['-std=c++14', '-sUSE_BOOST_HEADERS']) - self.do_runf('test_boost_graph.cpp', emcc_args=['-std=c++14', '-sPORTS=boost_headers']) + self.do_runf('test_boost_graph.cpp', emcc_args=['-std=c++14', '--use-port=boost_headers']) def test_setjmp_em_asm(self): create_file('src.c', ''' diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index dbe866c4891fa..f8fd156e6f011 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -371,10 +371,10 @@ def add_deps(node): add_deps(port) -def check_ports_settings(settings): - for name in settings.PORTS: - if name not in ports_by_name: - utils.exit_with_error(f'Invalid port name: {name}') +def handle_use_port_arg(settings, name): + if name not in ports_by_name: + utils.exit_with_error(f'Invalid port name: {name} used with --user-port') + settings.PORTS.append(name) def get_needed_ports(settings): @@ -440,7 +440,7 @@ def add_cflags(args, settings): # noqa: U100 def show_ports(): print('Available ports:') - for port in ports: + for port in sorted(ports, key=lambda p: p.name): print(' ', port.show()) diff --git a/tools/ports/boost_headers.py b/tools/ports/boost_headers.py index 1bc60c2800a8e..47288838e79f4 100644 --- a/tools/ports/boost_headers.py +++ b/tools/ports/boost_headers.py @@ -44,4 +44,4 @@ def process_args(ports): def show(): - return 'Boost headers v1.70.0 (-sUSE_BOOST_HEADERS=1 or -sPORTS=boost_headers; Boost license)' + return 'boost_headers - Boost headers v1.70.0 (-sUSE_BOOST_HEADERS=1 or --use-port=boost_headers; Boost license)' diff --git a/tools/ports/bullet.py b/tools/ports/bullet.py index dfabe347ec568..a91c0b69b6285 100644 --- a/tools/ports/bullet.py +++ b/tools/ports/bullet.py @@ -56,4 +56,4 @@ def process_args(ports): def show(): - return 'bullet (-sUSE_BULLET=1 or -sPORTS=bullet; zlib license)' + return 'bullet (-sUSE_BULLET=1 or --use-port=bullet; zlib license)' diff --git a/tools/ports/bzip2.py b/tools/ports/bzip2.py index 0eee9d13947aa..a1e8c9d49d267 100644 --- a/tools/ports/bzip2.py +++ b/tools/ports/bzip2.py @@ -35,4 +35,4 @@ def clear(ports, settings, shared): def show(): - return 'bzip2 (-sUSE_BZIP2=1 or -sPORTS=bzip2; BSD license)' + return 'bzip2 (-sUSE_BZIP2=1 or --use-port=bzip2; BSD license)' diff --git a/tools/ports/cocos2d.py b/tools/ports/cocos2d.py index b9c83f9694517..685e3b50e0610 100644 --- a/tools/ports/cocos2d.py +++ b/tools/ports/cocos2d.py @@ -74,7 +74,7 @@ def process_args(ports): def show(): - return 'cocos2d (-sUSE_COCOS2D=3 or -sPORTS=cocos2d)' + return 'cocos2d (-sUSE_COCOS2D=3 or --use-port=cocos2d)' def make_source_list(cocos2d_root, cocos2dx_root): diff --git a/tools/ports/freetype.py b/tools/ports/freetype.py index 37c30eaebdc74..117fdcb7819bc 100644 --- a/tools/ports/freetype.py +++ b/tools/ports/freetype.py @@ -116,7 +116,7 @@ def process_args(ports): def show(): - return 'freetype (-sUSE_FREETYPE=1 or -sPORTS=freetype; freetype license)' + return 'freetype (-sUSE_FREETYPE=1 or --use-port=freetype; freetype license)' ftconf_h = r'''/***************************************************************************/ diff --git a/tools/ports/giflib.py b/tools/ports/giflib.py index adebcdffc531b..ecc554e3edd73 100644 --- a/tools/ports/giflib.py +++ b/tools/ports/giflib.py @@ -34,4 +34,4 @@ def clear(ports, settings, shared): def show(): - return 'giflib (-sUSE_GIFLIB=1 or -sPORTS=giflib; MIT license)' + return 'giflib (-sUSE_GIFLIB=1 or --use-port=giflib; MIT license)' diff --git a/tools/ports/harfbuzz.py b/tools/ports/harfbuzz.py index acab723a83940..e376d2743573c 100644 --- a/tools/ports/harfbuzz.py +++ b/tools/ports/harfbuzz.py @@ -152,4 +152,4 @@ def process_args(ports): def show(): - return 'harfbuzz (-sUSE_HARFBUZZ=1 or -sPORTS=harfbuzz; MIT license)' + return 'harfbuzz (-sUSE_HARFBUZZ=1 or --use-port=harfbuzz; MIT license)' diff --git a/tools/ports/icu.py b/tools/ports/icu.py index 25d9119e9f001..e2c01d3e0f200 100644 --- a/tools/ports/icu.py +++ b/tools/ports/icu.py @@ -100,4 +100,4 @@ def clear(ports, settings, shared): def show(): - return 'icu (-sUSE_ICU=1 or -sPORTS=icu; Unicode License)' + return 'icu (-sUSE_ICU=1 or --use-port=icu; Unicode License)' diff --git a/tools/ports/libjpeg.py b/tools/ports/libjpeg.py index c166ce0417323..e99776c789300 100644 --- a/tools/ports/libjpeg.py +++ b/tools/ports/libjpeg.py @@ -38,7 +38,7 @@ def clear(ports, settings, shared): def show(): - return 'libjpeg (-sUSE_LIBJPEG=1 or -sPORTS=libjpeg; BSD license)' + return 'libjpeg (-sUSE_LIBJPEG=1 or --use-port=libjpeg; BSD license)' jconfig_h = '''/* jconfig.h. Generated from jconfig.cfg by configure. */ diff --git a/tools/ports/libmodplug.py b/tools/ports/libmodplug.py index 24b363fd9c318..e6c1dc3f128e5 100644 --- a/tools/ports/libmodplug.py +++ b/tools/ports/libmodplug.py @@ -88,7 +88,7 @@ def clear(ports, settings, shared): def show(): - return 'libmodplug (-sUSE_MODPLUG=1 or -sPORTS=libmodplug; public domain)' + return 'libmodplug (-sUSE_MODPLUG=1 or --use-port=libmodplug; public domain)' config_h = '''/* src/config.h. Generated from config.h.in by configure. */ diff --git a/tools/ports/libpng.py b/tools/ports/libpng.py index df115f5571a39..1342f81a0fb54 100644 --- a/tools/ports/libpng.py +++ b/tools/ports/libpng.py @@ -58,7 +58,7 @@ def process_dependencies(settings): def show(): - return 'libpng (-sUSE_LIBPNG or -sPORTS=libpng; zlib license)' + return 'libpng (-sUSE_LIBPNG or --use-port=libpng; zlib license)' pnglibconf_h = r'''/* pnglibconf.h - library build configuration */ diff --git a/tools/ports/mpg123.py b/tools/ports/mpg123.py index 65476765d54e5..50840ec087078 100644 --- a/tools/ports/mpg123.py +++ b/tools/ports/mpg123.py @@ -81,7 +81,7 @@ def clear(ports, settings, shared): def show(): - return 'mpg123 (-sUSE_MPG123=1 or -sPORTS=mpg123; zlib license)' + return 'mpg123 (-sUSE_MPG123=1 or --use-port=mpg123; zlib license)' config_h = r'''/* src/config.h. Generated from config.h.in by configure. */ diff --git a/tools/ports/ogg.py b/tools/ports/ogg.py index 47007ba1b7e04..f56421bc9ceff 100644 --- a/tools/ports/ogg.py +++ b/tools/ports/ogg.py @@ -30,7 +30,7 @@ def clear(ports, settings, shared): def show(): - return 'ogg (-sUSE_OGG=1 or -sPORTS=ogg; zlib license)' + return 'ogg (-sUSE_OGG=1 or --use-port=ogg; zlib license)' config_types_h = '''\ diff --git a/tools/ports/regal.py b/tools/ports/regal.py index 9652cb878b265..7e04da2512818 100644 --- a/tools/ports/regal.py +++ b/tools/ports/regal.py @@ -126,4 +126,4 @@ def linker_setup(ports, settings): def show(): - return 'regal (-sUSE_REGAL=1 or -sPORTS=regal; Regal license)' + return 'regal (-sUSE_REGAL=1 or --use-port=regal; Regal license)' diff --git a/tools/ports/sdl2.py b/tools/ports/sdl2.py index ee7f3d7c1d012..5dd039b139ff2 100644 --- a/tools/ports/sdl2.py +++ b/tools/ports/sdl2.py @@ -91,4 +91,4 @@ def process_args(ports): def show(): - return 'SDL2 (-sUSE_SDL=2 or -sPORTS=sdl2; zlib license)' + return 'sdl2 (-sUSE_SDL=2 or --use-port=sdl2; zlib license)' diff --git a/tools/ports/sdl2_gfx.py b/tools/ports/sdl2_gfx.py index 14b8691866851..158ef0026c365 100644 --- a/tools/ports/sdl2_gfx.py +++ b/tools/ports/sdl2_gfx.py @@ -37,4 +37,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_gfx (-sUSE_SDL_GFX=2 or -sPORTS=sdl2_gfx; zlib license)' + return 'sdl2_gfx (-sUSE_SDL_GFX=2 or --use-port=sdl2_gfx; zlib license)' diff --git a/tools/ports/sdl2_image.py b/tools/ports/sdl2_image.py index fad9842c2bd5f..f6029de06ad67 100644 --- a/tools/ports/sdl2_image.py +++ b/tools/ports/sdl2_image.py @@ -73,4 +73,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_image (-sUSE_SDL_IMAGE=2 or -sPORTS=sdl2_image; zlib license)' + return 'sdl2_image (-sUSE_SDL_IMAGE=2 or --use-port=sdl2_image; zlib license)' diff --git a/tools/ports/sdl2_mixer.py b/tools/ports/sdl2_mixer.py index 968db1b7df27c..5906078ecf57a 100644 --- a/tools/ports/sdl2_mixer.py +++ b/tools/ports/sdl2_mixer.py @@ -115,4 +115,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_mixer (-sUSE_SDL_MIXER=2 or -sPORTS=sdl2_mixer; zlib license)' + return 'sdl2_mixer (-sUSE_SDL_MIXER=2 or --use-port=sdl2_mixer; zlib license)' diff --git a/tools/ports/sdl2_net.py b/tools/ports/sdl2_net.py index 988381ee7d68c..28b7f48ad1b84 100644 --- a/tools/ports/sdl2_net.py +++ b/tools/ports/sdl2_net.py @@ -38,4 +38,4 @@ def process_dependencies(settings): def show(): - return 'SDL2_net (-sUSE_SDL_NET=2 or -sPORTS=sdl2_net; zlib license)' + return 'sdl2_net (-sUSE_SDL_NET=2 or --use-port=sdl2_net; zlib license)' diff --git a/tools/ports/sdl2_ttf.py b/tools/ports/sdl2_ttf.py index e7cffc61778d1..5c106e9acfb56 100644 --- a/tools/ports/sdl2_ttf.py +++ b/tools/ports/sdl2_ttf.py @@ -42,4 +42,4 @@ def process_args(ports): def show(): - return 'SDL2_ttf (-sUSE_SDL_TTF=2 or -sPORTS=sdl2_ttf; zlib license)' + return 'sdl2_ttf (-sUSE_SDL_TTF=2 or --use-port=sdl2_ttf; zlib license)' diff --git a/tools/ports/sqlite3.py b/tools/ports/sqlite3.py index f22f32c1da806..efd01f319cd4c 100644 --- a/tools/ports/sqlite3.py +++ b/tools/ports/sqlite3.py @@ -78,4 +78,4 @@ def clear(ports, settings, shared): def show(): - return 'sqlite (-sUSE_SQLITE3=1 or -sPORTS=sqlite3); public domain)' + return 'sqlite3 (-sUSE_SQLITE3=1 or --use-port=sqlite3); public domain)' diff --git a/tools/ports/vorbis.py b/tools/ports/vorbis.py index d12ef97650de4..92f5b4a356fb2 100644 --- a/tools/ports/vorbis.py +++ b/tools/ports/vorbis.py @@ -37,4 +37,4 @@ def process_dependencies(settings): def show(): - return 'vorbis (-sUSE_VORBIS or -sPORTS=vorbis; zlib license)' + return 'vorbis (-sUSE_VORBIS or --use-port=vorbis; zlib license)' diff --git a/tools/ports/zlib.py b/tools/ports/zlib.py index d614541ddbc7b..4d73d023e1673 100644 --- a/tools/ports/zlib.py +++ b/tools/ports/zlib.py @@ -34,7 +34,7 @@ def clear(ports, settings, shared): def show(): - return 'zlib (-sUSE_ZLIB=1 or -sPORTS=zlib; zlib license)' + return 'zlib (-sUSE_ZLIB=1 or --use-port=zlib; zlib license)' zconf_h = r'''/* zconf.h -- configuration of the zlib compression library From 177d603803dc834e7c6a4d04f3ce7b57775d9434 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 07:28:27 -0800 Subject: [PATCH 04/27] removed PORTS from settings.py --- test/test_other.py | 2 +- tools/settings.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 5eed86adcc438..e554d5425cb13 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2367,7 +2367,7 @@ def test_icu(self): def test_sdl2_ttf(self): # This is a compile-only to test to verify that sdl2-ttf (and freetype and harfbuzz) are buildable. self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js') - self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['--use-port=sdl2_ttf'], output_filename='a.out.js') + self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['--use-port=sdl2', '--use-port=sdl2_ttf'], output_filename='a.out.js') def test_link_memcpy(self): # memcpy can show up *after* optimizations, so after our opportunity to link in libc, so it must be special-cased diff --git a/tools/settings.py b/tools/settings.py index 75668a7dd7d42..e99e020c2a6a9 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -51,8 +51,7 @@ 'USE_FREETYPE', 'SDL2_MIXER_FORMATS', 'SDL2_IMAGE_FORMATS', - 'USE_SQLITE3', - 'PORTS' + 'USE_SQLITE3' } # Subset of settings that apply only when generating JS From 7d4383119cd3714f060722cb7630c4eefa435037 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 08:02:24 -0800 Subject: [PATCH 05/27] reverted comma --- tools/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/settings.py b/tools/settings.py index e99e020c2a6a9..67d01f2b98859 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -51,7 +51,7 @@ 'USE_FREETYPE', 'SDL2_MIXER_FORMATS', 'SDL2_IMAGE_FORMATS', - 'USE_SQLITE3' + 'USE_SQLITE3', } # Subset of settings that apply only when generating JS From 5d0afbb3e4b0f261f0e25abd925f8db4b39d0d8e Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 11:31:08 -0800 Subject: [PATCH 06/27] changes from code review --- ChangeLog.md | 3 +++ site/source/docs/tools_reference/emcc.rst | 2 +- src/settings_internal.js | 4 ---- tools/ports/__init__.py | 11 +++++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 67af381c95b35..6a1a72835690c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works. 3.1.54 (in development) ----------------------- +- Added `--use-port` option to `emcc`. You can use `--show-ports` to get the + list of available ports that can be used with this new option. + 3.1.53 - 01/29/24 ----------------- diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index 010c5dcca9604..eefbcb834c712 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -460,7 +460,7 @@ Options that are modified or new in *emcc* are listed below: ``--use-port=`` [link] Use the specified port. If you need to use more than one port you can use this - argument multiple times. For example: ``--user-port=sdl2 --user-port=bzip2``. + argument multiple times. For example: ``--use-port=sdl2 --use-port=bzip2``. To get the list of available ports, use ``--show-ports``. .. _emcc-clear-ports: diff --git a/src/settings_internal.js b/src/settings_internal.js index 678b6ee0fae72..36a1887540a84 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -273,7 +273,3 @@ var BULK_MEMORY = false; var MINIFY_WHITESPACE = true; var ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = []; - -// Specify which ports to use. This is set via the --use-port command line -// option -var PORTS = []; diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index f8fd156e6f011..637ccda8bc4a4 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -22,6 +22,8 @@ ports_by_name = {} +ports_needed = set() + # Variant builds that we want to support for certain ports # {variant_name: (port_name, extra_settings)} port_variants = {} @@ -40,10 +42,10 @@ def load_port(name): for a in expected_attrs: assert hasattr(port, a), 'port %s is missing %s' % (port, a) if not hasattr(port, 'needed'): - port.needed = lambda s: name in s.PORTS + port.needed = lambda s: name in ports_needed else: needed = port.needed - port.needed = lambda s: needed(s) or name in s.PORTS + port.needed = lambda s: needed(s) or name in ports_needed if not hasattr(port, 'process_dependencies'): port.process_dependencies = lambda x: 0 if not hasattr(port, 'linker_setup'): @@ -373,8 +375,9 @@ def add_deps(node): def handle_use_port_arg(settings, name): if name not in ports_by_name: - utils.exit_with_error(f'Invalid port name: {name} used with --user-port') - settings.PORTS.append(name) + utils.exit_with_error(f'Invalid port name: {name} used with --use-port') + ports_needed.add(name) + print(f'ports_needed={ports_needed}') def get_needed_ports(settings): From ba2a1ff3e44c37b3dd65030a52a5de66f688f41f Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 11:36:25 -0800 Subject: [PATCH 07/27] removed print statement --- tools/ports/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 637ccda8bc4a4..71df3d0c2c6c4 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -377,7 +377,6 @@ def handle_use_port_arg(settings, name): if name not in ports_by_name: utils.exit_with_error(f'Invalid port name: {name} used with --use-port') ports_needed.add(name) - print(f'ports_needed={ports_needed}') def get_needed_ports(settings): From b88e332a97085af932b9d743b34f4b88b9a9fb8a Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 11:52:12 -0800 Subject: [PATCH 08/27] brute force documentation update --- docs/emcc.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/emcc.txt b/docs/emcc.txt index 25902a2453a87..60d42f930e71a 100644 --- a/docs/emcc.txt +++ b/docs/emcc.txt @@ -466,6 +466,12 @@ Options that are modified or new in *emcc* are listed below: By default this will also clear any download ports since the ports directory is usually within the cache directory. +"--use-port=" + [link] Use the specified port. If you need to use more than one + port you can use this argument multiple times. For example: "--use- + port=sdl2 --use-port=bzip2". To get the list of available ports, + use "--show-ports". + "--clear-ports" [general] Manually clears the local copies of ports from the Emscripten Ports repos (sdl2, etc.). This also clears the cache, to From aeb2d0a61583e33d5bb23a3fdcc4c1d6519f2f6d Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Wed, 31 Jan 2024 12:10:55 -0800 Subject: [PATCH 09/27] use compile+link --- docs/emcc.txt | 8 ++++---- site/source/docs/tools_reference/emcc.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/emcc.txt b/docs/emcc.txt index 60d42f930e71a..1d2c7900000fa 100644 --- a/docs/emcc.txt +++ b/docs/emcc.txt @@ -467,10 +467,10 @@ Options that are modified or new in *emcc* are listed below: directory is usually within the cache directory. "--use-port=" - [link] Use the specified port. If you need to use more than one - port you can use this argument multiple times. For example: "--use- - port=sdl2 --use-port=bzip2". To get the list of available ports, - use "--show-ports". + [compile+link] Use the specified port. If you need to use more than + one port you can use this argument multiple times. For example: "-- + use-port=sdl2 --use-port=bzip2". To get the list of available + ports, use "--show-ports". "--clear-ports" [general] Manually clears the local copies of ports from the diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index eefbcb834c712..7885ed3cbe6b0 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -458,7 +458,7 @@ Options that are modified or new in *emcc* are listed below: .. _emcc-use-port: ``--use-port=`` - [link] + [compile+link] Use the specified port. If you need to use more than one port you can use this argument multiple times. For example: ``--use-port=sdl2 --use-port=bzip2``. To get the list of available ports, use ``--show-ports``. From 9facf3879b86c08802e7d2100d0915513936b20d Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Thu, 1 Feb 2024 04:55:33 -0800 Subject: [PATCH 10/27] fixed sanity checks --- test/test_sanity.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_sanity.py b/test/test_sanity.py index 41465a59f5030..4f26ad520bb6a 100644 --- a/test/test_sanity.py +++ b/test/test_sanity.py @@ -529,9 +529,9 @@ def test_emcc_ports(self): # listing ports out = self.do([EMCC, '--show-ports']) self.assertContained('Available ports:', out) - self.assertContained('SDL2', out) - self.assertContained('SDL2_image', out) - self.assertContained('SDL2_net', out) + self.assertContained('sdl2', out) + self.assertContained('sdl2_image', out) + self.assertContained('sdl2_net', out) # using ports RETRIEVING_MESSAGE = 'retrieving port' From 0344a99f7d4a95a05b6d7520c44f4589324f0549 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Thu, 1 Feb 2024 09:34:48 -0800 Subject: [PATCH 11/27] documentation changes --- ChangeLog.md | 6 ++++-- site/source/docs/compiling/Building-Projects.rst | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 6a1a72835690c..33f14669d0149 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,8 +20,10 @@ See docs/process.md for more on how version tagging works. 3.1.54 (in development) ----------------------- -- Added `--use-port` option to `emcc`. You can use `--show-ports` to get the - list of available ports that can be used with this new option. +- Added `--use-port` option to `emcc`. This option allows ports to be enabled + by name and is designed to replace all existing `-sUSE_XXX` settings for + ports. You can use `--show-ports` to get the list of available ports that + can be used with this new option. (#21214) 3.1.53 - 01/29/24 diff --git a/site/source/docs/compiling/Building-Projects.rst b/site/source/docs/compiling/Building-Projects.rst index 18ec988297d1d..fd8b798353a70 100644 --- a/site/source/docs/compiling/Building-Projects.rst +++ b/site/source/docs/compiling/Building-Projects.rst @@ -215,17 +215,19 @@ For example, consider the case where a project "project" uses a library "libstuf Emscripten Ports ================ -Emscripten Ports is a collection of useful libraries, ported to Emscripten. They reside `on GitHub `_, and have integration support in *emcc*. When you request that a port be used, emcc will fetch it from the remote server, set it up and build it locally, then link it with your project, add necessary include to your build commands, etc. For example, SDL2 is in ports, and you can request that it be used with ``-sUSE_SDL=2``. For example, +Emscripten Ports is a collection of useful libraries, ported to Emscripten. They reside `on GitHub `_, and have integration support in *emcc*. When you request that a port be used, emcc will fetch it from the remote server, set it up and build it locally, then link it with your project, add necessary include to your build commands, etc. For example, SDL2 is in ports, and you can request that it be used with ``--use-port=sdl2``. For example, .. code-block:: bash - emcc test/sdl2glshader.c -sUSE_SDL=2 -sLEGACY_GL_EMULATION -o sdl2.html + emcc test/browser/test_sdl2_glshader.c --use-port=sdl2 -sLEGACY_GL_EMULATION -o sdl2.html You should see some notifications about SDL2 being used, and built if it wasn't previously. You can then view ``sdl2.html`` in your browser. -.. note:: *SDL_image* has also been added to ports, use it with ``-sUSE_SDL_IMAGE=2``. To see a list of all available ports, run ``emcc --show-ports``. For SDL2_image to be useful, you generally need to specify the image formats you are planning on using with e.g. ``-sSDL2_IMAGE_FORMATS='["bmp","png","xpm"]'`` (note: jpg support is not available yet as of Jun 22 2018 - libjpg needs to be added to emscripten-ports). This will also ensure that ``IMG_Init`` works properly when you specify those formats. Alternatively, you can use ``emcc --use-preload-plugins`` and ``--preload-file`` your images, so the browser codecs decode them (see :ref:`preloading-files`). A code path in the SDL2_image port will load through :c:func:`emscripten_get_preloaded_image_data`, but then your calls to ``IMG_Init`` with those image formats will fail (as while the images will work through preloading, IMG_Init reports no support for those formats, as it doesn't have support compiled in - in other words, IMG_Init does not report support for formats that only work through preloading).``` +To see a list of all available ports, run ``emcc --show-ports``. -.. note:: *SDL_net* has also been added to ports, use it with ``-sUSE_SDL_NET=2``. To see a list of all available ports, run ``emcc --show-ports``. +.. note:: *SDL_image* has also been added to ports, use it with ``--use-port=sdl2_image``. For ``sdl2_image`` to be useful, you generally need to specify the image formats you are planning on using with e.g. ``-sSDL2_IMAGE_FORMATS='["bmp","png","xpm","jpg"]'``. This will also ensure that ``IMG_Init`` works properly when you specify those formats. Alternatively, you can use ``emcc --use-preload-plugins`` and ``--preload-file`` your images, so the browser codecs decode them (see :ref:`preloading-files`). A code path in the ``sdl2_image`` port will load through :c:func:`emscripten_get_preloaded_image_data`, but then your calls to ``IMG_Init`` with those image formats will fail (as while the images will work through preloading, IMG_Init reports no support for those formats, as it doesn't have support compiled in - in other words, IMG_Init does not report support for formats that only work through preloading).``` + +.. note:: *SDL_net* has also been added to ports, use it with ``--use-port=sdl2_net``. .. note:: Emscripten also has support for older SDL1, which is built-in. If you do not specify SDL2 as in the command above, then SDL1 is linked in and the SDL1 include paths are used. SDL1 has support for *sdl-config*, which is present in `system/bin `_. Using the native *sdl-config* may result in compilation or missing-symbol errors. You will need to modify the build system to look for files in **emscripten/system** or **emscripten/system/bin** in order to use the Emscripten *sdl-config*. @@ -236,6 +238,9 @@ You should see some notifications about SDL2 being used, and built if it wasn't it's better to use the ports version as it is what is tested and known to work. +.. note:: Since emscripten 3.1.54, ``--use-port`` is the preferred syntax to use a port in your project. The legacy syntax (for example ``-sUSE_SDL2``, ``-sUSE_SDL_IMAGE=2``) remains available. + + Adding more ports ----------------- From 2be267238ce740f6a97f57e02ec8668efcb93426 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Thu, 1 Feb 2024 11:54:18 -0800 Subject: [PATCH 12/27] first pass at adding contrib ports --- embuilder.py | 3 +- test/other/test_contrib_ports.cpp | 25 +++++++++++++ test/test_other.py | 5 +++ test/test_sanity.py | 5 ++- tools/link.py | 4 +- tools/ports/__init__.py | 47 ++++++++++++++++++------ tools/ports/contrib/README.md | 20 ++++++++++ tools/ports/contrib/__init__.py | 0 tools/ports/contrib/glfw3.py | 61 +++++++++++++++++++++++++++++++ 9 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 test/other/test_contrib_ports.cpp create mode 100644 tools/ports/contrib/README.md create mode 100644 tools/ports/contrib/__init__.py create mode 100644 tools/ports/contrib/glfw3.py diff --git a/embuilder.py b/embuilder.py index 076d58a39f23f..b1501dbe1127a 100755 --- a/embuilder.py +++ b/embuilder.py @@ -125,7 +125,8 @@ def get_help(): return ''' Available targets: - build / clear %s + build / clear + %s Issuing 'embuilder build ALL' causes each task to be built. ''' % '\n '.join(all_tasks) diff --git a/test/other/test_contrib_ports.cpp b/test/other/test_contrib_ports.cpp new file mode 100644 index 0000000000000..946f9b492e149 --- /dev/null +++ b/test/other/test_contrib_ports.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2024 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. + */ + +#include +#include +#include + +// cpp otherwise it fails to link +int main() { + + assert(glfwInit() == GLFW_TRUE); + + GLFWwindow* window = glfwCreateWindow(320, 200, "test_glfw3_port", 0, 0); + assert(window != 0); + // this call ensures that it uses the right port + assert(emscripten_glfw_is_window_fullscreen(window) == EM_FALSE); + glfwTerminate(); + + + return 0; +} diff --git a/test/test_other.py b/test/test_other.py index b57daee40318b..df48213797f05 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2369,6 +2369,11 @@ def test_sdl2_ttf(self): self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js') self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['--use-port=sdl2', '--use-port=sdl2_ttf'], output_filename='a.out.js') + def test_contrib_ports(self): + # Verify that contrib ports can be used (using the only contrib port available ATM, but can be replaced + # with a different contrib port when there is another one + self.emcc(test_file('other/test_contrib_ports.cpp'), ['--use-port=contrib.glfw3'], output_filename='a.out.js') + def test_link_memcpy(self): # memcpy can show up *after* optimizations, so after our opportunity to link in libc, so it must be special-cased create_file('main.c', r''' diff --git a/test/test_sanity.py b/test/test_sanity.py index 4f26ad520bb6a..bb97cb1475ef3 100644 --- a/test/test_sanity.py +++ b/test/test_sanity.py @@ -526,9 +526,12 @@ def test_emconfig(self): def test_emcc_ports(self): restore_and_set_up() + # validating that ports are valid + ports.validate_ports() + # listing ports out = self.do([EMCC, '--show-ports']) - self.assertContained('Available ports:', out) + self.assertContained('Available official ports:', out) self.assertContained('sdl2', out) self.assertContained('sdl2_image', out) self.assertContained('sdl2_net', out) diff --git a/tools/link.py b/tools/link.py index e0dc389d4ae77..3040ba6bff6a0 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2941,6 +2941,8 @@ def run(linker_inputs, options, state, newargs): logger.debug('stopping after linking to object file') return 0 + phase_calculate_system_libraries(state, linker_arguments, newargs) + js_syms = {} if (not settings.SIDE_MODULE or settings.ASYNCIFY) and not shared.SKIP_SUBPROCS: js_info = get_js_sym_info() @@ -2963,8 +2965,6 @@ def add_js_deps(sym): settings.ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = settings.ASYNCIFY_IMPORTS[:] settings.ASYNCIFY_IMPORTS += ['*.' + x for x in js_info['asyncFuncs']] - phase_calculate_system_libraries(state, linker_arguments, newargs) - phase_link(linker_arguments, wasm_target, js_syms) # Special handling for when the user passed '-Wl,--version'. In this case the linker diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 71df3d0c2c6c4..62ed572c298a1 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -34,13 +34,11 @@ def load_port(name): - expected_attrs = ['get', 'clear', 'show'] - port = __import__(name, globals(), level=1) + port = __import__(name, globals(), level=1, fromlist=[None]) ports.append(port) + port.is_contrib = name.startswith('contrib.') port.name = name ports_by_name[port.name] = port - for a in expected_attrs: - assert hasattr(port, a), 'port %s is missing %s' % (port, a) if not hasattr(port, 'needed'): port.needed = lambda s: name in ports_needed else: @@ -57,6 +55,8 @@ def load_port(name): if not hasattr(port, 'variants'): # port variants (default: no variants) port.variants = {} + if not hasattr(port, 'show') and port.is_contrib: + port.show = lambda: f'{port.name} (--use-port={port.name}; {port.project_license()})' for variant, extra_settings in port.variants.items(): if variant in port_variants: @@ -64,6 +64,23 @@ def load_port(name): port_variants[variant] = (port.name, extra_settings) +def validate_port(port): + expected_attrs = ['get', 'clear', 'show'] + if port.is_contrib: + expected_attrs += ['project_url', 'project_description', 'project_license'] + for a in expected_attrs: + assert hasattr(port, a), 'port %s is missing %s' % (port, a) + + +# Called from test_sanity +def validate_ports(): + for port in ports: + validate_port(port) + for dep in port.deps: + if dep not in ports_by_name: + utils.exit_with_error('unknown dependency in port: %s' % dep) + + @ToolchainProfiler.profile() def read_ports(): for filename in os.listdir(ports_dir): @@ -72,10 +89,12 @@ def read_ports(): filename = os.path.splitext(filename)[0] load_port(filename) - for port in ports: - for dep in port.deps: - if dep not in ports_by_name: - utils.exit_with_error('unknown dependency in port: %s' % dep) + contrib_dir = os.path.join(ports_dir, 'contrib') + for filename in os.listdir(contrib_dir): + if not filename.endswith('.py') or filename == '__init__.py': + continue + filename = os.path.splitext(filename)[0] + load_port('contrib.' + filename) def get_all_files_under(dirname): @@ -441,9 +460,15 @@ def add_cflags(args, settings): # noqa: U100 def show_ports(): - print('Available ports:') - for port in sorted(ports, key=lambda p: p.name): - print(' ', port.show()) + sorted_ports = sorted(ports, key=lambda p: p.name) + print('Available official ports:') + for port in sorted_ports: + if not port.is_contrib: + print(' ', port.show()) + print('Available contrib ports:') + for port in sorted_ports: + if port.is_contrib: + print(' ', port.show()) read_ports() diff --git a/tools/ports/contrib/README.md b/tools/ports/contrib/README.md new file mode 100644 index 0000000000000..bc30f77716b04 --- /dev/null +++ b/tools/ports/contrib/README.md @@ -0,0 +1,20 @@ +Emscripten "Contrib" Ports +========================== + +Ports in this directory are contributed by the wider community and are +supported on a "best effort" basis. Since they are not run as part of +emscripten CI they are not always guaranteed to build or function. + +If you want to add a contrib port, please use another contrib port as +an example. In particular, each contrib port must provide 3 extra piece +of information (provided as functions in the port file): + +* `project_url`: the url where the user can find more information about + the project/port +* `project_description`: a (short) description of what the project/port + is about +* `project_license`: the license used by the project/port + +After adding (resp. modifying) a contrib port, you must run the +`./tools/maint/update_settings_docs.py` command to add (resp. update) +the new port to the documentation. \ No newline at end of file diff --git a/tools/ports/contrib/__init__.py b/tools/ports/contrib/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py new file mode 100644 index 0000000000000..56f854928b5e8 --- /dev/null +++ b/tools/ports/contrib/glfw3.py @@ -0,0 +1,61 @@ +# Copyright 2024 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. + +import os + +TAG = '1.0.4' +HASH = 'c3c96718e5d2b37df434a46c4a93ddfd9a768330d33f0d6ce2d08c139752894c2421cdd0fefb800fe41fafc2bbe58c8f22b8aa2849dc4fc6dde686037215cfad' + +# name is set when the port is read +name = '' + + +def get_lib_name(settings): + return f'lib_{name}.a' + + +def get(ports, settings, shared): + # get the port + ports.fetch_project(name, f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip', sha512hash=HASH) + + def create(final): + root_path = os.path.join(ports.get_dir(), name) + source_path = os.path.join(root_path, 'src', 'cpp') + source_include_paths = [os.path.join(root_path, 'external', 'GLFW'), os.path.join(root_path, 'include', 'GLFW')] + for source_include_path in source_include_paths: + ports.install_headers(source_include_path, target='GLFW') + + # this should be an option but better to disable for now... + flags = ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING'] + + ports.build_port(source_path, final, name, includes=source_include_paths, flags=flags) + + return [shared.cache.get_lib(get_lib_name(settings), create, what='port')] + + +def clear(ports, settings, shared): + shared.cache.erase_lib(get_lib_name(settings)) + + +def linker_setup(ports, settings): + root_path = os.path.join(ports.get_dir(), name) + source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js') + settings.JS_LIBRARIES += [source_js_path] + + +def process_args(ports): + return ['-isystem', ports.get_include_dir(name)] + + +def project_url(): + return 'https://github.com/pongasoft/emscripten-glfw' + + +def project_description(): + return 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' + + +def project_license(): + return 'Apache 2.0 license' From d7a3b4579a9c63a3afa21a2057d87168e8963acd Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Fri, 2 Feb 2024 07:11:32 -0800 Subject: [PATCH 13/27] added new documentation --- .circleci/config.yml | 1 + .../docs/compiling/Building-Projects.rst | 11 ++- site/source/docs/compiling/Contrib-Ports.rst | 26 ++++++ tools/maint/update_contrib_ports_docs.py | 82 +++++++++++++++++++ tools/ports/contrib/README.md | 2 +- 5 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 site/source/docs/compiling/Contrib-Ports.rst create mode 100755 tools/maint/update_contrib_ports_docs.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 94b81255241da..7f6fbde811b2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -418,6 +418,7 @@ jobs: - checkout - pip-install - run: tools/maint/update_settings_docs.py --check + - run: tools/maint/update_contrib_ports_docs.py --check - run: make -C site text - run: tools/maint/check_emcc_help_text.py - run: make -C site html diff --git a/site/source/docs/compiling/Building-Projects.rst b/site/source/docs/compiling/Building-Projects.rst index fd8b798353a70..210ee35397b50 100644 --- a/site/source/docs/compiling/Building-Projects.rst +++ b/site/source/docs/compiling/Building-Projects.rst @@ -241,15 +241,18 @@ To see a list of all available ports, run ``emcc --show-ports``. .. note:: Since emscripten 3.1.54, ``--use-port`` is the preferred syntax to use a port in your project. The legacy syntax (for example ``-sUSE_SDL2``, ``-sUSE_SDL_IMAGE=2``) remains available. +Contrib ports +------------- + +Contrib ports are contributed by the wider community and supported on a "best effort" basis. Since they are not run as part of emscripten CI they are not always guaranteed to build or function. See :ref:`Contrib Ports ` for more information. + Adding more ports ----------------- -Adding more ports is fairly easy. Basically, the steps are +With the introduction of contrib ports, adding a new port is fairly easy. Basically, the steps are: * Make sure the port is open source and has a suitable license. - * Add it to emscripten-ports on github. The ports maintainers can create the repo and add the relevant developers to a team for that repo, so they have write access. - * Add a script to handle it under ``tools/ports/`` (see existing code for examples) and use it in ``tools/ports/__init__.py``. - * Add testing in the test suite. + * Read the ``README.md`` file under ``tools/ports/contrib`` which contains more information. Build system issues diff --git a/site/source/docs/compiling/Contrib-Ports.rst b/site/source/docs/compiling/Contrib-Ports.rst new file mode 100644 index 0000000000000..2487164e5ba6a --- /dev/null +++ b/site/source/docs/compiling/Contrib-Ports.rst @@ -0,0 +1,26 @@ +.. _contrib_ports: + +======================== +Emscripten Contrib Ports +======================== + +Contrib ports are contributed by the wider community and +supported on a "best effort" basis. Since they are not run as part +of emscripten CI they are not always guaranteed to build or function. + +The following is the complete list of the contrib ports that are +available in emscripten. In order to use a contrib port you use the +``--use-port=`` option (:ref:`emcc `). + +.. Auto-generated by update_contrib_ports_docs.py. **DO NOT EDIT** + +.. _contrib.glfw3: + +contrib.glfw3 +============= + +This project is an emscripten port of glfw written in C++ for the web/webassembly platform + +`Project information `_ + +License: Apache 2.0 license \ No newline at end of file diff --git a/tools/maint/update_contrib_ports_docs.py b/tools/maint/update_contrib_ports_docs.py new file mode 100755 index 0000000000000..3740feb094c1c --- /dev/null +++ b/tools/maint/update_contrib_ports_docs.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# Copyright 2024 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. + +"""Generate the documentation for contrib ports. After adding/updating +a contrib port, this tool must be re-run. +""" + +import os +import sys +import subprocess + +script_dir = os.path.dirname(os.path.abspath(__file__)) +root_dir = os.path.dirname(os.path.dirname(script_dir)) + +sys.path.append(root_dir) + +from tools.utils import path_from_root, read_file, safe_ensure_dirs +from tools import ports + +header = '''\ +.. _contrib_ports: + +======================== +Emscripten Contrib Ports +======================== + +Contrib ports are contributed by the wider community and +supported on a "best effort" basis. Since they are not run as part +of emscripten CI they are not always guaranteed to build or function. + +The following is the complete list of the contrib ports that are +available in emscripten. In order to use a contrib port you use the +``--use-port=`` option (:ref:`emcc `). + +.. Auto-generated by update_contrib_ports_docs.py. **DO NOT EDIT** +''' + + +output_file = path_from_root('site/source/docs/compiling/Contrib-Ports.rst') + + +def write_contrib_port(f, port): + heading = port.name + f.write('\n.. _' + heading.lower() + ':\n') + f.write('\n' + heading + '\n') + f.write('=' * len(heading) + '\n\n') + f.write(port.project_description()) + f.write(f'\n\n`Project information <{port.project_url()}>`_') + f.write(f'\n\nLicense: {port.project_license()}') + + +def write_contrib_ports(f): + for port in sorted(ports.ports, key=lambda p: p.name): + if port.is_contrib: + write_contrib_port(f, port) + +def write_file(f): + f.write(header) + write_contrib_ports(f) + +def main(args): + if '--check' in args: + safe_ensure_dirs(path_from_root('out')) + tmp_output = path_from_root('out/Contrib-Ports.rst') + with open(tmp_output, 'w') as f: + write_file(f) + if read_file(tmp_output) != read_file(output_file): + print(f'{output_file} is out-of-date. Please run tools/maint/update_contrib_ports_docs.py') + subprocess.call(['diff', '-u', output_file, tmp_output]) + return 1 + else: + with open(output_file, 'w') as f: + write_file(f) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/tools/ports/contrib/README.md b/tools/ports/contrib/README.md index bc30f77716b04..c665b4cd27eaf 100644 --- a/tools/ports/contrib/README.md +++ b/tools/ports/contrib/README.md @@ -16,5 +16,5 @@ of information (provided as functions in the port file): * `project_license`: the license used by the project/port After adding (resp. modifying) a contrib port, you must run the -`./tools/maint/update_settings_docs.py` command to add (resp. update) +`./tools/maint/update_contrib_port_docs.py` command to add (resp. update) the new port to the documentation. \ No newline at end of file From b0285875e41575b91c4d243c09f1a94a8577e60c Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 05:49:53 -0800 Subject: [PATCH 14/27] Code review --- site/source/docs/compiling/Building-Projects.rst | 2 +- tools/maint/update_contrib_ports_docs.py | 6 +++--- tools/ports/__init__.py | 6 +++--- tools/ports/contrib/glfw3.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/site/source/docs/compiling/Building-Projects.rst b/site/source/docs/compiling/Building-Projects.rst index 210ee35397b50..f1d089f308c81 100644 --- a/site/source/docs/compiling/Building-Projects.rst +++ b/site/source/docs/compiling/Building-Projects.rst @@ -249,7 +249,7 @@ Contrib ports are contributed by the wider community and supported on a "best ef Adding more ports ----------------- -With the introduction of contrib ports, adding a new port is fairly easy. Basically, the steps are: +The simplest way to add a new port is to put it under the ``contrib`` directory. Basically, the steps are: * Make sure the port is open source and has a suitable license. * Read the ``README.md`` file under ``tools/ports/contrib`` which contains more information. diff --git a/tools/maint/update_contrib_ports_docs.py b/tools/maint/update_contrib_ports_docs.py index 3740feb094c1c..8d8c0a15d2f52 100755 --- a/tools/maint/update_contrib_ports_docs.py +++ b/tools/maint/update_contrib_ports_docs.py @@ -47,9 +47,9 @@ def write_contrib_port(f, port): f.write('\n.. _' + heading.lower() + ':\n') f.write('\n' + heading + '\n') f.write('=' * len(heading) + '\n\n') - f.write(port.project_description()) - f.write(f'\n\n`Project information <{port.project_url()}>`_') - f.write(f'\n\nLicense: {port.project_license()}') + f.write(port.description()) + f.write(f'\n\n`Project information <{port.url()}>`_') + f.write(f'\n\nLicense: {port.license()}') def write_contrib_ports(f): diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 62ed572c298a1..56c31613b292e 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -55,8 +55,8 @@ def load_port(name): if not hasattr(port, 'variants'): # port variants (default: no variants) port.variants = {} - if not hasattr(port, 'show') and port.is_contrib: - port.show = lambda: f'{port.name} (--use-port={port.name}; {port.project_license()})' + if not hasattr(port, 'show'): + port.show = lambda: f'{port.name} (--use-port={port.name}; {port.license()})' for variant, extra_settings in port.variants.items(): if variant in port_variants: @@ -67,7 +67,7 @@ def load_port(name): def validate_port(port): expected_attrs = ['get', 'clear', 'show'] if port.is_contrib: - expected_attrs += ['project_url', 'project_description', 'project_license'] + expected_attrs += ['url', 'description', 'license'] for a in expected_attrs: assert hasattr(port, a), 'port %s is missing %s' % (port, a) diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index 56f854928b5e8..a6448abb47685 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -49,13 +49,13 @@ def process_args(ports): return ['-isystem', ports.get_include_dir(name)] -def project_url(): +def url(): return 'https://github.com/pongasoft/emscripten-glfw' -def project_description(): +def description(): return 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' -def project_license(): +def license(): return 'Apache 2.0 license' From 4f9e599f23c7d8c0b8d373921f3064fabf48c7f3 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 06:10:10 -0800 Subject: [PATCH 15/27] reverting automatic documentation --- .circleci/config.yml | 1 - tools/maint/update_contrib_ports_docs.py | 82 ------------------------ tools/ports/contrib/README.md | 11 ++-- 3 files changed, 5 insertions(+), 89 deletions(-) delete mode 100755 tools/maint/update_contrib_ports_docs.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 6fba9abe95f8d..01ae69b86c286 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -418,7 +418,6 @@ jobs: - checkout - pip-install - run: tools/maint/update_settings_docs.py --check - - run: tools/maint/update_contrib_ports_docs.py --check - run: make -C site text - run: tools/maint/check_emcc_help_text.py - run: make -C site html diff --git a/tools/maint/update_contrib_ports_docs.py b/tools/maint/update_contrib_ports_docs.py deleted file mode 100755 index 8d8c0a15d2f52..0000000000000 --- a/tools/maint/update_contrib_ports_docs.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2024 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. - -"""Generate the documentation for contrib ports. After adding/updating -a contrib port, this tool must be re-run. -""" - -import os -import sys -import subprocess - -script_dir = os.path.dirname(os.path.abspath(__file__)) -root_dir = os.path.dirname(os.path.dirname(script_dir)) - -sys.path.append(root_dir) - -from tools.utils import path_from_root, read_file, safe_ensure_dirs -from tools import ports - -header = '''\ -.. _contrib_ports: - -======================== -Emscripten Contrib Ports -======================== - -Contrib ports are contributed by the wider community and -supported on a "best effort" basis. Since they are not run as part -of emscripten CI they are not always guaranteed to build or function. - -The following is the complete list of the contrib ports that are -available in emscripten. In order to use a contrib port you use the -``--use-port=`` option (:ref:`emcc `). - -.. Auto-generated by update_contrib_ports_docs.py. **DO NOT EDIT** -''' - - -output_file = path_from_root('site/source/docs/compiling/Contrib-Ports.rst') - - -def write_contrib_port(f, port): - heading = port.name - f.write('\n.. _' + heading.lower() + ':\n') - f.write('\n' + heading + '\n') - f.write('=' * len(heading) + '\n\n') - f.write(port.description()) - f.write(f'\n\n`Project information <{port.url()}>`_') - f.write(f'\n\nLicense: {port.license()}') - - -def write_contrib_ports(f): - for port in sorted(ports.ports, key=lambda p: p.name): - if port.is_contrib: - write_contrib_port(f, port) - -def write_file(f): - f.write(header) - write_contrib_ports(f) - -def main(args): - if '--check' in args: - safe_ensure_dirs(path_from_root('out')) - tmp_output = path_from_root('out/Contrib-Ports.rst') - with open(tmp_output, 'w') as f: - write_file(f) - if read_file(tmp_output) != read_file(output_file): - print(f'{output_file} is out-of-date. Please run tools/maint/update_contrib_ports_docs.py') - subprocess.call(['diff', '-u', output_file, tmp_output]) - return 1 - else: - with open(output_file, 'w') as f: - write_file(f) - - return 0 - - -if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) diff --git a/tools/ports/contrib/README.md b/tools/ports/contrib/README.md index c665b4cd27eaf..6e4a19f89e714 100644 --- a/tools/ports/contrib/README.md +++ b/tools/ports/contrib/README.md @@ -9,12 +9,11 @@ If you want to add a contrib port, please use another contrib port as an example. In particular, each contrib port must provide 3 extra piece of information (provided as functions in the port file): -* `project_url`: the url where the user can find more information about +* `url`: the url where the user can find more information about the project/port -* `project_description`: a (short) description of what the project/port +* `description`: a (short) description of what the project/port is about -* `project_license`: the license used by the project/port +* `license`: the license used by the project/port -After adding (resp. modifying) a contrib port, you must run the -`./tools/maint/update_contrib_port_docs.py` command to add (resp. update) -the new port to the documentation. \ No newline at end of file +After adding a contrib port, you should consider modifying the documentation +under `site/source/docs/compiling/Contrib-Ports.rst`. \ No newline at end of file From ec050d1318a2ec6799ccaa163013ed7231d33814 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 06:18:17 -0800 Subject: [PATCH 16/27] 80 columns --- site/source/docs/compiling/Building-Projects.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/site/source/docs/compiling/Building-Projects.rst b/site/source/docs/compiling/Building-Projects.rst index f1d089f308c81..91283f4612a23 100644 --- a/site/source/docs/compiling/Building-Projects.rst +++ b/site/source/docs/compiling/Building-Projects.rst @@ -244,7 +244,10 @@ To see a list of all available ports, run ``emcc --show-ports``. Contrib ports ------------- -Contrib ports are contributed by the wider community and supported on a "best effort" basis. Since they are not run as part of emscripten CI they are not always guaranteed to build or function. See :ref:`Contrib Ports ` for more information. +Contrib ports are contributed by the wider community and supported on a +"best effort" basis. Since they are not run as part of emscripten CI they are +not always guaranteed to build or function. +See :ref:`Contrib Ports ` for more information. Adding more ports ----------------- From 033e0baa3533fa3f1fdcad7f07c4d4b4ca45db97 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 06:19:14 -0800 Subject: [PATCH 17/27] removed comment --- site/source/docs/compiling/Contrib-Ports.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/site/source/docs/compiling/Contrib-Ports.rst b/site/source/docs/compiling/Contrib-Ports.rst index 2487164e5ba6a..271c6e70500b0 100644 --- a/site/source/docs/compiling/Contrib-Ports.rst +++ b/site/source/docs/compiling/Contrib-Ports.rst @@ -12,8 +12,6 @@ The following is the complete list of the contrib ports that are available in emscripten. In order to use a contrib port you use the ``--use-port=`` option (:ref:`emcc `). -.. Auto-generated by update_contrib_ports_docs.py. **DO NOT EDIT** - .. _contrib.glfw3: contrib.glfw3 From c5d2f991fb44656164c66df8d1359076c9b02c79 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 06:44:09 -0800 Subject: [PATCH 18/27] Fixed documentation --- site/source/docs/compiling/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/source/docs/compiling/index.rst b/site/source/docs/compiling/index.rst index f0465c626170b..1546e7d7b17de 100644 --- a/site/source/docs/compiling/index.rst +++ b/site/source/docs/compiling/index.rst @@ -12,6 +12,7 @@ This section contains topics about building projects and running the output. - :ref:`Travis` explains how to build and test projects on Travis CI. - :ref:`Deploying-Pages` covers topics related to hosting Emscripten compiled web pages on a CDN. - :ref:`GitLab` explains how to build and test projects on GitLab. +- :ref:`Contrib-Ports` contains information about contrib ports. .. toctree:: @@ -24,3 +25,4 @@ This section contains topics about building projects and running the output. Travis Deploying-Pages GitLab + Contrib-Ports From db88e521023bde66466855deef80686ca249f4c9 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 3 Feb 2024 06:51:40 -0800 Subject: [PATCH 19/27] fix documentation --- site/source/docs/compiling/Building-Projects.rst | 2 +- site/source/docs/compiling/Contrib-Ports.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/site/source/docs/compiling/Building-Projects.rst b/site/source/docs/compiling/Building-Projects.rst index 91283f4612a23..46a306f14d613 100644 --- a/site/source/docs/compiling/Building-Projects.rst +++ b/site/source/docs/compiling/Building-Projects.rst @@ -247,7 +247,7 @@ Contrib ports Contrib ports are contributed by the wider community and supported on a "best effort" basis. Since they are not run as part of emscripten CI they are not always guaranteed to build or function. -See :ref:`Contrib Ports ` for more information. +See :ref:`Contrib Ports ` for more information. Adding more ports ----------------- diff --git a/site/source/docs/compiling/Contrib-Ports.rst b/site/source/docs/compiling/Contrib-Ports.rst index 271c6e70500b0..00b649761c9c0 100644 --- a/site/source/docs/compiling/Contrib-Ports.rst +++ b/site/source/docs/compiling/Contrib-Ports.rst @@ -1,4 +1,4 @@ -.. _contrib_ports: +.. _Contrib-Ports: ======================== Emscripten Contrib Ports From 3d727b9071ae66ff1e93b5f812b29fdf1c5ca13d Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 06:13:07 -0800 Subject: [PATCH 20/27] Added changelog + tweaks --- ChangeLog.md | 5 +++++ tools/ports/__init__.py | 4 ++-- tools/ports/contrib/glfw3.py | 16 +++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index d271798abe748..caa1b73c1446c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -30,6 +30,11 @@ See docs/process.md for more on how version tagging works. the top of the JS file. This is useful as it allows things like `{{{ POINTER_SIZE }}}` and `{{{ makeGetValue(..) }}}` to be used in pre/post JS files, just like they can be in JS library files. (#21227) +- Added concept of contrib ports which are ports contributed by the wider + community and supported on a "best effort" basis. A first contrib port is + available via `--use-port=contrib.glfw3`: an emscripten port of glfw written + in C++ with many features like support for multiple windows. (#21244) + 3.1.53 - 01/29/24 ----------------- diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 56c31613b292e..1a302c733c3de 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -56,7 +56,7 @@ def load_port(name): # port variants (default: no variants) port.variants = {} if not hasattr(port, 'show'): - port.show = lambda: f'{port.name} (--use-port={port.name}; {port.license()})' + port.show = lambda: f'{port.name} (--use-port={port.name}; {port.LICENSE})' for variant, extra_settings in port.variants.items(): if variant in port_variants: @@ -67,7 +67,7 @@ def load_port(name): def validate_port(port): expected_attrs = ['get', 'clear', 'show'] if port.is_contrib: - expected_attrs += ['url', 'description', 'license'] + expected_attrs += ['URL', 'DESCRIPTION', 'LICENSE'] for a in expected_attrs: assert hasattr(port, a), 'port %s is missing %s' % (port, a) diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index a6448abb47685..82d0a0fe2c679 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -8,6 +8,11 @@ TAG = '1.0.4' HASH = 'c3c96718e5d2b37df434a46c4a93ddfd9a768330d33f0d6ce2d08c139752894c2421cdd0fefb800fe41fafc2bbe58c8f22b8aa2849dc4fc6dde686037215cfad' +# contrib port information (required) +URL = 'https://github.com/pongasoft/emscripten-glfw' +DESCRIPTION = 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' +LICENSE = 'Apache 2.0 license' + # name is set when the port is read name = '' @@ -48,14 +53,3 @@ def linker_setup(ports, settings): def process_args(ports): return ['-isystem', ports.get_include_dir(name)] - -def url(): - return 'https://github.com/pongasoft/emscripten-glfw' - - -def description(): - return 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' - - -def license(): - return 'Apache 2.0 license' From 5a0b6685580f3d4732d7a67da162608835ff73c4 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 06:16:34 -0800 Subject: [PATCH 21/27] updated readme accordingly --- tools/ports/contrib/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/ports/contrib/README.md b/tools/ports/contrib/README.md index 6e4a19f89e714..f5b3b40d3a2a3 100644 --- a/tools/ports/contrib/README.md +++ b/tools/ports/contrib/README.md @@ -7,13 +7,13 @@ emscripten CI they are not always guaranteed to build or function. If you want to add a contrib port, please use another contrib port as an example. In particular, each contrib port must provide 3 extra piece -of information (provided as functions in the port file): +of information: -* `url`: the url where the user can find more information about +* `URL`: the url where the user can find more information about the project/port -* `description`: a (short) description of what the project/port +* `DESCRIPTION`: a (short) description of what the project/port is about -* `license`: the license used by the project/port +* `LICENSE`: the license used by the project/port After adding a contrib port, you should consider modifying the documentation under `site/source/docs/compiling/Contrib-Ports.rst`. \ No newline at end of file From 124d52b80d253959c9b2877c64fc633efb683044 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 06:24:40 -0800 Subject: [PATCH 22/27] removed blank line --- tools/ports/contrib/glfw3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index 82d0a0fe2c679..05dcd1051ab7c 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -52,4 +52,3 @@ def linker_setup(ports, settings): def process_args(ports): return ['-isystem', ports.get_include_dir(name)] - From 22a392ab6a105070606a75b6b5a0e48d51364db7 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 18:48:57 -0800 Subject: [PATCH 23/27] code review --- tools/ports/__init__.py | 1 + tools/ports/contrib/glfw3.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 1a302c733c3de..a2b5001faa3fe 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -96,6 +96,7 @@ def read_ports(): filename = os.path.splitext(filename)[0] load_port('contrib.' + filename) + validate_ports() def get_all_files_under(dirname): for path, _, files in os.walk(dirname): diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index 05dcd1051ab7c..a192ea33585db 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -13,20 +13,20 @@ DESCRIPTION = 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' LICENSE = 'Apache 2.0 license' -# name is set when the port is read -name = '' +# unique key to not conflict with other ports +key = 'contrib.glfw3' def get_lib_name(settings): - return f'lib_{name}.a' + return f'lib_{key}.a' def get(ports, settings, shared): # get the port - ports.fetch_project(name, f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip', sha512hash=HASH) + ports.fetch_project(key, f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip', sha512hash=HASH) def create(final): - root_path = os.path.join(ports.get_dir(), name) + root_path = os.path.join(ports.get_dir(), key) source_path = os.path.join(root_path, 'src', 'cpp') source_include_paths = [os.path.join(root_path, 'external', 'GLFW'), os.path.join(root_path, 'include', 'GLFW')] for source_include_path in source_include_paths: @@ -35,7 +35,7 @@ def create(final): # this should be an option but better to disable for now... flags = ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING'] - ports.build_port(source_path, final, name, includes=source_include_paths, flags=flags) + ports.build_port(source_path, final, key, includes=source_include_paths, flags=flags) return [shared.cache.get_lib(get_lib_name(settings), create, what='port')] @@ -45,10 +45,10 @@ def clear(ports, settings, shared): def linker_setup(ports, settings): - root_path = os.path.join(ports.get_dir(), name) + root_path = os.path.join(ports.get_dir(), key) source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js') settings.JS_LIBRARIES += [source_js_path] def process_args(ports): - return ['-isystem', ports.get_include_dir(name)] + return ['-isystem', ports.get_include_dir(key)] From 93c5ea7f86b6c97f99f8b9ba044fcbbddd6b2027 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 18:50:24 -0800 Subject: [PATCH 24/27] removed unnecessary comment --- tools/ports/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index a2b5001faa3fe..e7adcfbffa750 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -72,7 +72,6 @@ def validate_port(port): assert hasattr(port, a), 'port %s is missing %s' % (port, a) -# Called from test_sanity def validate_ports(): for port in ports: validate_port(port) From 095395530c1a2461a8909bbedbe8009166264c2e Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 4 Feb 2024 18:59:14 -0800 Subject: [PATCH 25/27] 2 lines... --- tools/ports/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index e7adcfbffa750..9ceb3b63e37e6 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -97,6 +97,7 @@ def read_ports(): validate_ports() + def get_all_files_under(dirname): for path, _, files in os.walk(dirname): for name in files: From 21a2839e30955fe75a5ab01da9bdfba9a44bbe18 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Mon, 5 Feb 2024 10:44:42 -0800 Subject: [PATCH 26/27] removed key variable --- tools/ports/contrib/glfw3.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index a192ea33585db..6660debc9b712 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -13,20 +13,17 @@ DESCRIPTION = 'This project is an emscripten port of glfw written in C++ for the web/webassembly platform' LICENSE = 'Apache 2.0 license' -# unique key to not conflict with other ports -key = 'contrib.glfw3' - def get_lib_name(settings): - return f'lib_{key}.a' + return 'lib_contrib.glfw3.a' def get(ports, settings, shared): # get the port - ports.fetch_project(key, f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip', sha512hash=HASH) + ports.fetch_project('contrib.glfw3', f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip', sha512hash=HASH) def create(final): - root_path = os.path.join(ports.get_dir(), key) + root_path = os.path.join(ports.get_dir(), 'contrib.glfw3') source_path = os.path.join(root_path, 'src', 'cpp') source_include_paths = [os.path.join(root_path, 'external', 'GLFW'), os.path.join(root_path, 'include', 'GLFW')] for source_include_path in source_include_paths: @@ -35,7 +32,7 @@ def create(final): # this should be an option but better to disable for now... flags = ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING'] - ports.build_port(source_path, final, key, includes=source_include_paths, flags=flags) + ports.build_port(source_path, final, 'contrib.glfw3', includes=source_include_paths, flags=flags) return [shared.cache.get_lib(get_lib_name(settings), create, what='port')] @@ -45,10 +42,10 @@ def clear(ports, settings, shared): def linker_setup(ports, settings): - root_path = os.path.join(ports.get_dir(), key) + root_path = os.path.join(ports.get_dir(), 'contrib.glfw3') source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js') settings.JS_LIBRARIES += [source_js_path] def process_args(ports): - return ['-isystem', ports.get_include_dir(key)] + return ['-isystem', ports.get_include_dir('contrib.glfw3')] From 3df103f038678a11d1c3217c3d98b36d6eba64fc Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Mon, 5 Feb 2024 12:44:32 -0800 Subject: [PATCH 27/27] code review --- test/test_other.py | 2 +- test/test_sanity.py | 3 --- tools/ports/contrib/glfw3.py | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index e702e54e14d09..aba5e0e557c4a 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2372,7 +2372,7 @@ def test_sdl2_ttf(self): def test_contrib_ports(self): # Verify that contrib ports can be used (using the only contrib port available ATM, but can be replaced # with a different contrib port when there is another one - self.emcc(test_file('other/test_contrib_ports.cpp'), ['--use-port=contrib.glfw3'], output_filename='a.out.js') + self.emcc(test_file('other/test_contrib_ports.cpp'), ['--use-port=contrib.glfw3']) def test_link_memcpy(self): # memcpy can show up *after* optimizations, so after our opportunity to link in libc, so it must be special-cased diff --git a/test/test_sanity.py b/test/test_sanity.py index 8629d78fcad36..0375e28237a9d 100644 --- a/test/test_sanity.py +++ b/test/test_sanity.py @@ -527,9 +527,6 @@ def test_emconfig(self): def test_emcc_ports(self): restore_and_set_up() - # validating that ports are valid - ports.validate_ports() - # listing ports out = self.do([EMCC, '--show-ports']) self.assertContained('Available official ports:', out) diff --git a/tools/ports/contrib/glfw3.py b/tools/ports/contrib/glfw3.py index 6660debc9b712..b15cf6c38c944 100644 --- a/tools/ports/contrib/glfw3.py +++ b/tools/ports/contrib/glfw3.py @@ -47,5 +47,8 @@ def linker_setup(ports, settings): settings.JS_LIBRARIES += [source_js_path] +# Using contrib.glfw3 to avoid installing headers into top level include path +# so that we don't conflict with the builtin GLFW headers that emscripten +# includes def process_args(ports): return ['-isystem', ports.get_include_dir('contrib.glfw3')]