Skip to content

[contrib.glfw3] Use new external port feature #24518

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged
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
108 changes: 4 additions & 104 deletions tools/ports/contrib/glfw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,113 +3,13 @@
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

import os
from typing import Union, Dict
TAG = '3.4.0.20250607'

TAG = '3.4.0.20250305'
HASH = 'd5d1496cf1e05a640c182584a09ed0b43c8d6c42386513e5c2b1e05a2289854a0a0abe085e0a8b64c3a484836a8e63dc5ddb683ce4d2899fccbbf89536d58ee1'
EXTERNAL_PORT = f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip'
SHA512 = '1b264ac8891ffff51b899ca5853d4f945294dde9a9191eb5df9dd4cb26a4b27c5e7dac99cad42466833e9aae76d450de8a4b84381a63214321dc0427fd054f1b'
PORT_FILE = 'port/glfw3.py'

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

VALID_OPTION_VALUES = {
'disableWarning': ['true', 'false'],
'disableJoystick': ['true', 'false'],
'disableMultiWindow': ['true', 'false'],
'disableWebGL2': ['true', 'false'],
'optimizationLevel': ['0', '1', '2', '3', 'g', 's', 'z'], # all -OX possibilities
}

OPTIONS = {
'disableWarning': 'Boolean to disable warnings emitted by the library',
'disableJoystick': 'Boolean to disable support for joystick entirely',
'disableMultiWindow': 'Boolean to disable multi window support',
'disableWebGL2': 'Boolean to disable WebGL2 support',
'optimizationLevel': f'Optimization level: {VALID_OPTION_VALUES["optimizationLevel"]} (default to 2)',
}

# user options (from --use-port)
opts: Dict[str, Union[str, bool]] = {
'disableWarning': False,
'disableJoystick': False,
'disableMultiWindow': False,
'disableWebGL2': False,
'optimizationLevel': '2',
}

port_name = 'contrib.glfw3'


def get_lib_name(settings):
return (f'lib_{port_name}-O{opts["optimizationLevel"]}' +
('-nw' if opts['disableWarning'] else '') +
('-nj' if opts['disableJoystick'] else '') +
('-sw' if opts['disableMultiWindow'] else '') +
('-mt' if settings.PTHREADS else '') +
'.a')


def get(ports, settings, shared):
# get the port
ports.fetch_project(port_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(), port_name)
source_path = os.path.join(root_path, 'src', 'cpp')
source_include_paths = [os.path.join(root_path, 'external'), os.path.join(root_path, 'include')]
for source_include_path in source_include_paths:
ports.install_headers(os.path.join(source_include_path, 'GLFW'), target=os.path.join(port_name, 'GLFW'))

flags = [f'-O{opts["optimizationLevel"]}']

if opts['disableWarning']:
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING']

if opts['disableJoystick']:
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_JOYSTICK']

if opts['disableMultiWindow']:
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT']

if settings.PTHREADS:
flags += ['-pthread']

ports.build_port(source_path, final, port_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(), port_name)
source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js')
settings.JS_LIBRARIES += [source_js_path]
if not opts['disableWebGL2']:
settings.MAX_WEBGL_VERSION = 2


# 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(port_name), f'-DEMSCRIPTEN_USE_PORT_CONTRIB_GLFW3={TAG.replace(".", "")}']


def check_option(option, value, error_handler):
if value not in VALID_OPTION_VALUES[option]:
error_handler(f'[{option}] can be {list(VALID_OPTION_VALUES[option])}, got [{value}]')
if isinstance(opts[option], bool):
value = value == 'true'
return value


def handle_options(options, error_handler):
for option, value in options.items():
opts[option] = check_option(option, value.lower(), error_handler)