Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for contrib ports #21191

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
'giflib',
]

ports.read_ports()

PORTS = sorted(list(ports.ports_by_name.keys()) + list(ports.port_variants.keys()))

temp_files = shared.get_temp_files()
Expand Down
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def apply_user_settings():
if key == 'WASM_OBJECT_FILES':
settings.LTO = 0 if value else 'full'

ports.check_port_options(settings)


def cxx_to_c_compiler(cxx):
# Convert C++ compiler name into C compiler name
Expand Down
67 changes: 67 additions & 0 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,56 @@ 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].

.. note:: 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.

Available contrib ports:

.. _ports=contrib.example:

PORTS=contrib.example
---------------------

Port Contrib Example

`Project information <https://github.com/emscripten-core/emscripten>`_
License: MIT license

.. _ports=contrib.glfw3:

PORTS=contrib.glfw3
-------------------

This project is an emscripten port of glfw written in C++ for the web/webassembly platform

Available options:
- contrib.glfw3:DISABLE_WARNING : Disable all warnings
- contrib.glfw3:DISABLE_JOYSTICK : Disable support for joystick (due to polling, it can help to disable joystick support if not needed)
- contrib.glfw3:DISABLE_MULTI_WINDOW_SUPPORT : Disable support for multiple windows if not needed

`Project information <https://github.com/pongasoft/emscripten-glfw>`_
License: Apache 2.0 license


.. _port_options:

PORT_OPTIONS
============

Specify which options to use when building ports. The syntax is the following:
-sPORT_OPTIONS=port:option or -sPORT_OPTIONS=[port1:option1,port2:option2]
when multiple port/options need to be provided.

.. note:: Applicable during both linking and compilation

.. _wasm:

WASM
Expand Down Expand Up @@ -1894,6 +1944,7 @@ USE_ICU
=======

1 = use icu from emscripten-ports
Alternate syntax: -sPORTS=icu

.. note:: Applicable during both linking and compilation

Expand All @@ -1903,6 +1954,7 @@ USE_ZLIB
========

1 = use zlib from emscripten-ports
Alternate syntax: -sPORTS=zlib

.. note:: Applicable during both linking and compilation

Expand All @@ -1912,6 +1964,7 @@ USE_BZIP2
=========

1 = use bzip2 from emscripten-ports
Alternate syntax: -sPORTS=bzip2

.. note:: Applicable during both linking and compilation

Expand All @@ -1921,6 +1974,7 @@ USE_GIFLIB
==========

1 = use giflib from emscripten-ports
Alternate syntax: -sPORTS=giflib

.. note:: Applicable during both linking and compilation

Expand All @@ -1930,6 +1984,7 @@ USE_LIBJPEG
===========

1 = use libjpeg from emscripten-ports
Alternate syntax: -sPORTS=libjpeg

.. note:: Applicable during both linking and compilation

Expand All @@ -1939,6 +1994,7 @@ USE_LIBPNG
==========

1 = use libpng from emscripten-ports
Alternate syntax: -sPORTS=libpng

.. note:: Applicable during both linking and compilation

Expand All @@ -1948,6 +2004,7 @@ USE_REGAL
=========

1 = use Regal from emscripten-ports
Alternate syntax: -sPORTS=regal

.. note:: Applicable during both linking and compilation

Expand All @@ -1957,6 +2014,7 @@ USE_BOOST_HEADERS
=================

1 = use Boost headers from emscripten-ports
Alternate syntax: -sPORTS=boost_headers

.. note:: Applicable during both linking and compilation

Expand All @@ -1966,6 +2024,7 @@ USE_BULLET
==========

1 = use bullet from emscripten-ports
Alternate syntax: -sPORTS=bullet

.. note:: Applicable during both linking and compilation

Expand All @@ -1975,6 +2034,7 @@ USE_VORBIS
==========

1 = use vorbis from emscripten-ports
Alternate syntax: -sPORTS=vorbis

.. note:: Applicable during both linking and compilation

Expand All @@ -1984,6 +2044,7 @@ USE_OGG
=======

1 = use ogg from emscripten-ports
Alternate syntax: -sPORTS=ogg

.. note:: Applicable during both linking and compilation

Expand All @@ -1993,6 +2054,7 @@ USE_MPG123
==========

1 = use mpg123 from emscripten-ports
Alternate syntax: -sPORTS=mpg123

.. note:: Applicable during both linking and compilation

Expand All @@ -2002,6 +2064,7 @@ USE_FREETYPE
============

1 = use freetype from emscripten-ports
Alternate syntax: -sPORTS=freetype

.. note:: Applicable during both linking and compilation

Expand All @@ -2021,6 +2084,7 @@ USE_HARFBUZZ
============

1 = use harfbuzz from harfbuzz upstream
Alternate syntax: -sPORTS=harfbuzz

.. note:: Applicable during both linking and compilation

Expand All @@ -2030,6 +2094,7 @@ USE_COCOS2D
===========

3 = use cocos2d v3 from emscripten-ports
Alternate syntax: -sPORTS=cocos2d

.. note:: Applicable during both linking and compilation

Expand All @@ -2039,6 +2104,7 @@ USE_MODPLUG
===========

1 = use libmodplug from emscripten-ports
Alternate syntax: -sPORTS=libmodplug

.. note:: Applicable during both linking and compilation

Expand All @@ -2063,6 +2129,7 @@ USE_SQLITE3
===========

1 = use sqlite3 from emscripten-ports
Alternate syntax: -sPORTS=sqlite3

.. note:: Applicable during both linking and compilation

Expand Down
29 changes: 29 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,18 @@ 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 = [];

// Specify which options to use when building ports. The syntax is the following:
// -sPORT_OPTIONS=port:option or -sPORT_OPTIONS=[port1:option1,port2:option2]
// when multiple port/options need to be provided.
// [compile+link]
var PORT_OPTIONS = [];

// Whether to use compile code to WebAssembly. Set this to 0 to compile to JS
// instead of wasm.
//
Expand Down Expand Up @@ -1475,54 +1487,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;

Expand All @@ -1532,14 +1557,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;

Expand All @@ -1553,6 +1581,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;

Expand Down
28 changes: 28 additions & 0 deletions test/browser/test_contrib_ports.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 <GLFW/glfw3.h>
#include <GLFW/emscripten_glfw3.h>
#include <contrib_example.h>
#include <assert.h>

int main() {
// from one contrib port
assert(contrib_example() == 12);

// from another contrib port
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;
}
4 changes: 4 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,10 @@ def test_glfw_events(self):
def test_glfw3_hi_dpi_aware(self):
self.btest_exit('test_glfw3_hi_dpi_aware.c', args=['-sUSE_GLFW=3', '-lGL'])

@requires_graphics_hardware
def test_contrib_ports(self):
self.btest_exit('test_contrib_ports.c', args=['-sPORTS=[contrib.example,contrib.glfw3]', '-sPORT_OPTIONS=contrib.glfw3:DISABLE_WARNING', '-lGL'])

@requires_graphics_hardware
@no_wasm64('SDL2 + wasm64')
@parameterized({
Expand Down
4 changes: 2 additions & 2 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,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()
Expand All @@ -2953,8 +2955,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
Expand Down
Loading
Loading