Skip to content

Commit 71d452a

Browse files
authored
Add --use-port option (#21214)
1 parent 013f742 commit 71d452a

33 files changed

+158
-58
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.54 (in development)
2222
-----------------------
23+
- Added `--use-port` option to `emcc`. This option allows ports to be enabled
24+
by name and is designed to replace all existing `-sUSE_XXX` settings for
25+
ports. You can use `--show-ports` to get the list of available ports that
26+
can be used with this new option. (#21214)
27+
2328

2429
3.1.53 - 01/29/24
2530
-----------------

docs/emcc.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ Options that are modified or new in *emcc* are listed below:
466466
By default this will also clear any download ports since the ports
467467
directory is usually within the cache directory.
468468

469+
"--use-port=<port>"
470+
[compile+link] Use the specified port. If you need to use more than
471+
one port you can use this argument multiple times. For example: "--
472+
use-port=sdl2 --use-port=bzip2". To get the list of available
473+
ports, use "--show-ports".
474+
469475
"--clear-ports"
470476
[general] Manually clears the local copies of ports from the
471477
Emscripten Ports repos (sdl2, etc.). This also clears the cache, to

emcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,8 @@ def consume_arg_file():
14051405
options.target = consume_arg()
14061406
if options.target not in ('wasm32', 'wasm64', 'wasm64-unknown-emscripten', 'wasm32-unknown-emscripten'):
14071407
exit_with_error(f'unsupported target: {options.target} (emcc only supports wasm64-unknown-emscripten and wasm32-unknown-emscripten)')
1408+
elif check_arg('--use-port'):
1409+
ports.handle_use_port_arg(settings, consume_arg())
14081410
elif arg == '-mllvm':
14091411
# Ignore the next argument rather than trying to parse it. This is needed
14101412
# because llvm args could, for example, start with `-o` and we don't want

site/source/docs/compiling/Building-Projects.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,19 @@ For example, consider the case where a project "project" uses a library "libstuf
215215
Emscripten Ports
216216
================
217217

218-
Emscripten Ports is a collection of useful libraries, ported to Emscripten. They reside `on GitHub <https://github.com/emscripten-ports>`_, 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,
218+
Emscripten Ports is a collection of useful libraries, ported to Emscripten. They reside `on GitHub <https://github.com/emscripten-ports>`_, 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,
219219

220220
.. code-block:: bash
221221
222-
emcc test/sdl2glshader.c -sUSE_SDL=2 -sLEGACY_GL_EMULATION -o sdl2.html
222+
emcc test/browser/test_sdl2_glshader.c --use-port=sdl2 -sLEGACY_GL_EMULATION -o sdl2.html
223223
224224
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.
225225

226-
.. 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).```
226+
To see a list of all available ports, run ``emcc --show-ports``.
227227

228-
.. 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``.
228+
.. 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).```
229+
230+
.. note:: *SDL_net* has also been added to ports, use it with ``--use-port=sdl2_net``.
229231

230232
.. 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 <https://github.com/emscripten-core/emscripten/blob/main/system/bin/sdl-config>`_. 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*.
231233

@@ -236,6 +238,9 @@ You should see some notifications about SDL2 being used, and built if it wasn't
236238
it's better to use the ports version as it is what is tested and known to
237239
work.
238240

241+
.. 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.
242+
243+
239244
Adding more ports
240245
-----------------
241246

site/source/docs/tools_reference/emcc.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@ Options that are modified or new in *emcc* are listed below:
455455
By default this will also clear any download ports since the ports directory
456456
is usually within the cache directory.
457457

458+
.. _emcc-use-port:
459+
460+
``--use-port=<port>``
461+
[compile+link]
462+
Use the specified port. If you need to use more than one port you can use this
463+
argument multiple times. For example: ``--use-port=sdl2 --use-port=bzip2``.
464+
To get the list of available ports, use ``--show-ports``.
465+
458466
.. _emcc-clear-ports:
459467

460468
``--clear-ports``

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,7 @@ Specify the SDL version that is being linked against.
18491849
2 is a port of the SDL C code on emscripten-ports
18501850
When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL
18511851
is not linked in.
1852+
Alternate syntax for using the port: --use-port=sdl2
18521853

18531854
.. note:: Applicable during both linking and compilation
18541855

@@ -1894,6 +1895,7 @@ USE_ICU
18941895
=======
18951896

18961897
1 = use icu from emscripten-ports
1898+
Alternate syntax: --use-port=icu
18971899

18981900
.. note:: Applicable during both linking and compilation
18991901

@@ -1903,6 +1905,7 @@ USE_ZLIB
19031905
========
19041906

19051907
1 = use zlib from emscripten-ports
1908+
Alternate syntax: --use-port=zlib
19061909

19071910
.. note:: Applicable during both linking and compilation
19081911

@@ -1912,6 +1915,7 @@ USE_BZIP2
19121915
=========
19131916

19141917
1 = use bzip2 from emscripten-ports
1918+
Alternate syntax: --use-port=bzip2
19151919

19161920
.. note:: Applicable during both linking and compilation
19171921

@@ -1921,6 +1925,7 @@ USE_GIFLIB
19211925
==========
19221926

19231927
1 = use giflib from emscripten-ports
1928+
Alternate syntax: --use-port=giflib
19241929

19251930
.. note:: Applicable during both linking and compilation
19261931

@@ -1930,6 +1935,7 @@ USE_LIBJPEG
19301935
===========
19311936

19321937
1 = use libjpeg from emscripten-ports
1938+
Alternate syntax: --use-port=libjpeg
19331939

19341940
.. note:: Applicable during both linking and compilation
19351941

@@ -1939,6 +1945,7 @@ USE_LIBPNG
19391945
==========
19401946

19411947
1 = use libpng from emscripten-ports
1948+
Alternate syntax: --use-port=libpng
19421949

19431950
.. note:: Applicable during both linking and compilation
19441951

@@ -1948,6 +1955,7 @@ USE_REGAL
19481955
=========
19491956

19501957
1 = use Regal from emscripten-ports
1958+
Alternate syntax: --use-port=regal
19511959

19521960
.. note:: Applicable during both linking and compilation
19531961

@@ -1957,6 +1965,7 @@ USE_BOOST_HEADERS
19571965
=================
19581966

19591967
1 = use Boost headers from emscripten-ports
1968+
Alternate syntax: --use-port=boost_headers
19601969

19611970
.. note:: Applicable during both linking and compilation
19621971

@@ -1966,6 +1975,7 @@ USE_BULLET
19661975
==========
19671976

19681977
1 = use bullet from emscripten-ports
1978+
Alternate syntax: --use-port=bullet
19691979

19701980
.. note:: Applicable during both linking and compilation
19711981

@@ -1975,6 +1985,7 @@ USE_VORBIS
19751985
==========
19761986

19771987
1 = use vorbis from emscripten-ports
1988+
Alternate syntax: --use-port=vorbis
19781989

19791990
.. note:: Applicable during both linking and compilation
19801991

@@ -1984,6 +1995,7 @@ USE_OGG
19841995
=======
19851996

19861997
1 = use ogg from emscripten-ports
1998+
Alternate syntax: --use-port=ogg
19871999

19882000
.. note:: Applicable during both linking and compilation
19892001

@@ -1993,6 +2005,7 @@ USE_MPG123
19932005
==========
19942006

19952007
1 = use mpg123 from emscripten-ports
2008+
Alternate syntax: --use-port=mpg123
19962009

19972010
.. note:: Applicable during both linking and compilation
19982011

@@ -2002,6 +2015,7 @@ USE_FREETYPE
20022015
============
20032016

20042017
1 = use freetype from emscripten-ports
2018+
Alternate syntax: --use-port=freetype
20052019

20062020
.. note:: Applicable during both linking and compilation
20072021

@@ -2021,6 +2035,7 @@ USE_HARFBUZZ
20212035
============
20222036

20232037
1 = use harfbuzz from harfbuzz upstream
2038+
Alternate syntax: --use-port=harfbuzz
20242039

20252040
.. note:: Applicable during both linking and compilation
20262041

@@ -2030,6 +2045,7 @@ USE_COCOS2D
20302045
===========
20312046

20322047
3 = use cocos2d v3 from emscripten-ports
2048+
Alternate syntax: --use-port=cocos2d
20332049

20342050
.. note:: Applicable during both linking and compilation
20352051

@@ -2039,6 +2055,7 @@ USE_MODPLUG
20392055
===========
20402056

20412057
1 = use libmodplug from emscripten-ports
2058+
Alternate syntax: --use-port=libmodplug
20422059

20432060
.. note:: Applicable during both linking and compilation
20442061

@@ -2063,6 +2080,7 @@ USE_SQLITE3
20632080
===========
20642081

20652082
1 = use sqlite3 from emscripten-ports
2083+
Alternate syntax: --use-port=sqlite3
20662084

20672085
.. note:: Applicable during both linking and compilation
20682086

src/settings.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ var LEGALIZE_JS_FFI = true;
14551455
// 2 is a port of the SDL C code on emscripten-ports
14561456
// When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL
14571457
// is not linked in.
1458+
// Alternate syntax for using the port: --use-port=sdl2
14581459
// [compile+link]
14591460
var USE_SDL = 0;
14601461

@@ -1475,54 +1476,67 @@ var USE_SDL_TTF = 1;
14751476
var USE_SDL_NET = 1;
14761477

14771478
// 1 = use icu from emscripten-ports
1479+
// Alternate syntax: --use-port=icu
14781480
// [compile+link]
14791481
var USE_ICU = false;
14801482

14811483
// 1 = use zlib from emscripten-ports
1484+
// Alternate syntax: --use-port=zlib
14821485
// [compile+link]
14831486
var USE_ZLIB = false;
14841487

14851488
// 1 = use bzip2 from emscripten-ports
1489+
// Alternate syntax: --use-port=bzip2
14861490
// [compile+link]
14871491
var USE_BZIP2 = false;
14881492

14891493
// 1 = use giflib from emscripten-ports
1494+
// Alternate syntax: --use-port=giflib
14901495
// [compile+link]
14911496
var USE_GIFLIB = false;
14921497

14931498
// 1 = use libjpeg from emscripten-ports
1499+
// Alternate syntax: --use-port=libjpeg
14941500
// [compile+link]
14951501
var USE_LIBJPEG = false;
14961502

14971503
// 1 = use libpng from emscripten-ports
1504+
// Alternate syntax: --use-port=libpng
14981505
// [compile+link]
14991506
var USE_LIBPNG = false;
15001507

15011508
// 1 = use Regal from emscripten-ports
1509+
// Alternate syntax: --use-port=regal
15021510
// [compile+link]
15031511
var USE_REGAL = false;
15041512

15051513
// 1 = use Boost headers from emscripten-ports
1514+
// Alternate syntax: --use-port=boost_headers
15061515
// [compile+link]
15071516
var USE_BOOST_HEADERS = false;
15081517

15091518
// 1 = use bullet from emscripten-ports
1519+
// Alternate syntax: --use-port=bullet
15101520
// [compile+link]
15111521
var USE_BULLET = false;
15121522

15131523
// 1 = use vorbis from emscripten-ports
1524+
// Alternate syntax: --use-port=vorbis
15141525
// [compile+link]
15151526
var USE_VORBIS = false;
15161527

15171528
// 1 = use ogg from emscripten-ports
1529+
// Alternate syntax: --use-port=ogg
15181530
// [compile+link]
15191531
var USE_OGG = false;
15201532

15211533
// 1 = use mpg123 from emscripten-ports
1534+
// Alternate syntax: --use-port=mpg123
15221535
// [compile+link]
15231536
var USE_MPG123 = false;
15241537

15251538
// 1 = use freetype from emscripten-ports
1539+
// Alternate syntax: --use-port=freetype
15261540
// [compile+link]
15271541
var USE_FREETYPE = false;
15281542

@@ -1532,14 +1546,17 @@ var USE_FREETYPE = false;
15321546
var USE_SDL_MIXER = 1;
15331547

15341548
// 1 = use harfbuzz from harfbuzz upstream
1549+
// Alternate syntax: --use-port=harfbuzz
15351550
// [compile+link]
15361551
var USE_HARFBUZZ = false;
15371552

15381553
// 3 = use cocos2d v3 from emscripten-ports
1554+
// Alternate syntax: --use-port=cocos2d
15391555
// [compile+link]
15401556
var USE_COCOS2D = 0;
15411557

15421558
// 1 = use libmodplug from emscripten-ports
1559+
// Alternate syntax: --use-port=libmodplug
15431560
// [compile+link]
15441561
var USE_MODPLUG = false;
15451562

@@ -1553,6 +1570,7 @@ var SDL2_IMAGE_FORMATS = [];
15531570
var SDL2_MIXER_FORMATS = ["ogg"];
15541571

15551572
// 1 = use sqlite3 from emscripten-ports
1573+
// Alternate syntax: --use-port=sqlite3
15561574
// [compile+link]
15571575
var USE_SQLITE3 = false;
15581576

0 commit comments

Comments
 (0)