Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,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.

.. _use_glfw_port:

USE_GLFW_PORT
=============

Specify the version of the GLFW port to use. The port is located at
https://github.com/pongasoft/emscripten-glfw (includes demo, documentation
and usage). Valid option is 3 at the moment (GLFW 3.3.8+).

.. _wasm:

WASM
Expand Down
6 changes: 6 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,12 @@ var EMSCRIPTEN_TRACING = false;
// [link]
var USE_GLFW = 0;

// Specify the version of the GLFW port to use. The port is located at
// https://github.com/pongasoft/emscripten-glfw (includes demo, documentation
// and usage). Valid option is 3 at the moment (GLFW 3.3.8+).
// [link]
var USE_GLFW_PORT = 0;

// Whether to use compile code to WebAssembly. Set this to 0 to compile to JS
// instead of wasm.
//
Expand Down
34 changes: 34 additions & 0 deletions test/browser/test_glfw3_port.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 <assert.h>
#include <stdio.h>
#include <string.h>

void consoleErrorHandler(int iErrorCode, char const *iErrorMessage) {
printf("glfwError: %d | %s\n", iErrorCode, iErrorMessage);
}

int main() {

glfwSetErrorCallback(consoleErrorHandler);

assert(!strcmp(glfwGetVersionString(), "Emscripten/WebAssembly GLFW 3.3.8"));

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_glfw3_port(self):
self.btest_exit('test_glfw3_port.c', args=['-sUSE_GLFW_PORT=3', '-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 @@ -2942,6 +2942,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 @@ -2964,8 +2966,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
54 changes: 54 additions & 0 deletions tools/ports/glfw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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'


def needed(settings):
return settings.USE_GLFW_PORT == 3


lib_name = 'libglfw3.a'


def get(ports, settings, shared):
# get the port
ports.fetch_project('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(), '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:
ports.install_headers(source_include_path, target='GLFW')

# It would be great if the user could configure the build of the port, but I am
# not sure if it is possible, so removing warnings
flags = ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING']

ports.build_port(source_path, final, 'glfw3', includes=source_include_paths, flags=flags)

return [shared.cache.get_lib(lib_name, create, what='port')]


def clear(ports, settings, shared):
shared.cache.erase_lib(lib_name)


def linker_setup(ports, settings):
root_path = os.path.join(ports.get_dir(), '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('glfw3')]


def show():
return 'GLFW3 (USE_GLFW=3X; Apache 2.0 license)'
1 change: 1 addition & 0 deletions tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'SDL2_MIXER_FORMATS',
'SDL2_IMAGE_FORMATS',
'USE_SQLITE3',
'USE_GLFW_PORT',
}

# Subset of settings that apply only when generating JS
Expand Down