Skip to content

Commit 4a98562

Browse files
authored
[contrib.glfw3] new project version 3.4.0.20240731 (#22303)
This contains 2 new versions with the following release notes for the underlying project: #### 3.4.0.20240731 - 2024-07-31 - Added `emscripten_glfw_get_clipboard_string` the C version of `emscripten::glfw3::GetClipboardString` to retrieve the clipboard asynchronously - Added a helper class `emscripten::glfw3::FutureClipboardString` to greatly simplify the more frequent use-cases - `GetClipboardString::value()` now returns the internal clipboard in case of error, instead of throwing exception - Added `optimizationLevel` option to the emscripten port #### 3.4.0.20240727 - 2024-07-27 - Introduced C++ API (namespace `emscripten::glfw3`) included with `GLFW3/emscripten_glfw3.h`: - provides a more correct API with sensible defaults (ex: `std::string_view` / `std::optional<std::string_view>` vs `char const *` which may or may not be `nullptr`) - allow for C++ only API (ex: `std::future`) - the C API is still available if you would rather stick to it - Implemented `emscripten::glfw3::GetClipboardString` which provides a way of fetching the global clipboard in a browser environment (`glfwGetClipboardString` is not the right API due to the asynchronous nature of the underlying platform API). - The cursor position is no longer clamped to the window size, and as a result, can have negative values or values greater than the window size. Note that GLFW implements a similar behavior on the macOS desktop platform. - Implemented `glfwSetWindowPosCallback` - Added support for GLFW Window Attribute `GLFW_HOVERED` - Fixed [#6](pongasoft/emscripten-glfw#6): _`emscripten_glfw_make_canvas_resizable` does not clean up properly_. - Fixed an issue with opacity: when using opacity, the handle is not working unless its z-index is higher than the canvas z-index
1 parent cf0ec7a commit 4a98562

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

tools/ports/contrib/glfw3.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,43 @@
44
# found in the LICENSE file.
55

66
import os
7-
from typing import Dict
7+
from typing import Union, Dict
88

9-
TAG = '3.4.0.20240627'
10-
HASH = '6598834deece7087fd5dda14ec6d410ae651c39b9955eb050dd736a7d3eb650075fc69cf70340f4f0514bef63723a5bbcc315397ec44ba7cab46e59fa137e27f'
9+
TAG = '3.4.0.20240731'
10+
HASH = '1d348f2a6423def537bc11ba5a67347d23696f623e0155e315711d0e23e9b4e6f623019c24c699b6dd5b727322f7093af804d58fc48488f37888ba17300c3aa8'
1111

1212
# contrib port information (required)
1313
URL = 'https://github.com/pongasoft/emscripten-glfw'
14-
DESCRIPTION = 'This project is an emscripten port of GLFW written in C++ for the web/webassembly platform'
14+
DESCRIPTION = 'This project is an emscripten port of GLFW 3.4 written in C++ for the web/webassembly platform'
1515
LICENSE = 'Apache 2.0 license'
1616

17+
VALID_OPTION_VALUES = {
18+
'disableWarning': ['true', 'false'],
19+
'disableJoystick': ['true', 'false'],
20+
'disableMultiWindow': ['true', 'false'],
21+
'optimizationLevel': ['0', '1', '2', '3', 'g', 's', 'z'] # all -OX possibilities
22+
}
23+
1724
OPTIONS = {
1825
'disableWarning': 'Boolean to disable warnings emitted by the library',
1926
'disableJoystick': 'Boolean to disable support for joystick entirely',
20-
'disableMultiWindow': 'Boolean to disable multi window support which makes the code smaller and faster'
27+
'disableMultiWindow': 'Boolean to disable multi window support which makes the code smaller and faster',
28+
'optimizationLevel': f'Optimization level: {VALID_OPTION_VALUES["optimizationLevel"]} (default to 2)',
2129
}
2230

2331
# user options (from --use-port)
24-
opts: Dict[str, bool] = {
32+
opts: Dict[str, Union[str, bool]] = {
2533
'disableWarning': False,
2634
'disableJoystick': False,
27-
'disableMultiWindow': False
35+
'disableMultiWindow': False,
36+
'optimizationLevel': '2'
2837
}
2938

39+
port_name = 'contrib.glfw3'
40+
3041

3142
def get_lib_name(settings):
32-
return ('lib_contrib.glfw3' +
43+
return (f'lib_{port_name}-O{opts["optimizationLevel"]}' +
3344
('-nw' if opts['disableWarning'] else '') +
3445
('-nj' if opts['disableJoystick'] else '') +
3546
('-sw' if opts['disableMultiWindow'] else '') +
@@ -38,18 +49,18 @@ def get_lib_name(settings):
3849

3950
def get(ports, settings, shared):
4051
# get the port
41-
ports.fetch_project('contrib.glfw3',
52+
ports.fetch_project(port_name,
4253
f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip',
4354
sha512hash=HASH)
4455

4556
def create(final):
46-
root_path = os.path.join(ports.get_dir(), 'contrib.glfw3')
57+
root_path = os.path.join(ports.get_dir(), port_name)
4758
source_path = os.path.join(root_path, 'src', 'cpp')
4859
source_include_paths = [os.path.join(root_path, 'external'), os.path.join(root_path, 'include')]
4960
for source_include_path in source_include_paths:
50-
ports.install_headers(os.path.join(source_include_path, 'GLFW'), target=os.path.join('contrib.glfw3', 'GLFW'))
61+
ports.install_headers(os.path.join(source_include_path, 'GLFW'), target=os.path.join(port_name, 'GLFW'))
5162

52-
flags = []
63+
flags = [f'-O{opts["optimizationLevel"]}']
5364

5465
if opts['disableWarning']:
5566
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING']
@@ -60,7 +71,7 @@ def create(final):
6071
if opts['disableMultiWindow']:
6172
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT']
6273

63-
ports.build_port(source_path, final, 'contrib.glfw3', includes=source_include_paths, flags=flags)
74+
ports.build_port(source_path, final, port_name, includes=source_include_paths, flags=flags)
6475

6576
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
6677

@@ -70,7 +81,7 @@ def clear(ports, settings, shared):
7081

7182

7283
def linker_setup(ports, settings):
73-
root_path = os.path.join(ports.get_dir(), 'contrib.glfw3')
84+
root_path = os.path.join(ports.get_dir(), port_name)
7485
source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js')
7586
settings.JS_LIBRARIES += [source_js_path]
7687

@@ -79,12 +90,17 @@ def linker_setup(ports, settings):
7990
# so that we don't conflict with the builtin GLFW headers that emscripten
8091
# includes
8192
def process_args(ports):
82-
return ['-isystem', ports.get_include_dir('contrib.glfw3'), '-DEMSCRIPTEN_USE_PORT_CONTRIB_GLFW3']
93+
return ['-isystem', ports.get_include_dir(port_name), '-DEMSCRIPTEN_USE_PORT_CONTRIB_GLFW3']
94+
95+
96+
def check_option(option, value, error_handler):
97+
if value not in VALID_OPTION_VALUES[option]:
98+
error_handler(f'[{option}] can be {list(VALID_OPTION_VALUES[option])}, got [{value}]')
99+
if isinstance(opts[option], bool):
100+
value = value == 'true'
101+
return value
83102

84103

85104
def handle_options(options, error_handler):
86105
for option, value in options.items():
87-
if value.lower() in {'true', 'false'}:
88-
opts[option] = value.lower() == 'true'
89-
else:
90-
error_handler(f'{option} is expecting a boolean, got {value}')
106+
opts[option] = check_option(option, value.lower(), error_handler)

0 commit comments

Comments
 (0)