-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add suppport for external ports #21316
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
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
42e2016
first pass at external ports
ypujante cb14c71
detect name vs path
ypujante 16fbef2
minor refactoring
ypujante 9736c62
Merge remote-tracking branch 'origin/main' into external-ports
ypujante 91d0c5b
flake8 review
ypujante 1a1ed6b
fix for FROZEN_CACHE issue
ypujante 728da4f
code review
ypujante c8f3590
Merge remote-tracking branch 'origin/main' into external-ports
ypujante 85b8618
simplified code
ypujante 5d41c93
Merge remote-tracking branch 'origin/main' into external-ports
ypujante 5b2176c
more code review + docs
ypujante 086136a
Merge remote-tracking branch 'origin/main' into external-ports
ypujante 877b3b1
removed unnecessary include
ypujante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# 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 | ||
from typing import Dict, Optional | ||
|
||
URL = 'https://github.com/emscripten-core/emscripten' | ||
DESCRIPTION = 'External Ports Test' | ||
LICENSE = 'MIT license' | ||
|
||
OPTIONS = { | ||
'value1': 'Value for define TEST_VALUE_1', | ||
'value2': 'Value for define TEST_VALUE_2', | ||
'dependency': 'A dependency' | ||
} | ||
|
||
# user options (from --use-port) | ||
opts: Dict[str, Optional[str]] = { | ||
'value1': None, | ||
'value2': None, | ||
'dependency': None | ||
} | ||
|
||
EXAMPLE_H = 'int external_port_test_fn(int);' | ||
EXAMPLE_C = 'int external_port_test_fn(int value) { return value; }' | ||
ypujante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
deps = [] | ||
|
||
|
||
def get_lib_name(settings): | ||
return 'lib_external_port_test.a' | ||
|
||
|
||
def get(ports, settings, shared): | ||
source_path = os.path.join(ports.get_dir(), 'external_port_test') | ||
os.makedirs(source_path, exist_ok=True) | ||
|
||
def create(final): | ||
ports.write_file(os.path.join(source_path, 'external_port_test.h'), EXAMPLE_H) | ||
ports.write_file(os.path.join(source_path, 'external_port_test.c'), EXAMPLE_C) | ||
ports.install_headers(source_path) | ||
print(f'about to build {source_path}') | ||
ports.build_port(source_path, final, 'external_port_test') | ||
|
||
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 process_args(ports): | ||
args = ['-isystem', ports.get_include_dir('external_port_test')] | ||
if opts['value1']: | ||
args.append(f'-DTEST_VALUE_1={opts["value1"]}') | ||
if opts['value2']: | ||
args.append(f'-DTEST_VALUE_2={opts["value2"]}') | ||
if opts['dependency']: | ||
args.append(f'-DTEST_DEPENDENCY_{opts["dependency"].upper()}') | ||
return args | ||
|
||
|
||
def process_dependencies(settings): | ||
if opts['dependency']: | ||
deps.append(opts['dependency']) | ||
|
||
|
||
def handle_options(options): | ||
opts.update(options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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 <external_port_test.h> | ||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
#ifdef TEST_DEPENDENCY_SDL2 | ||
#include <SDL2/SDL.h> | ||
#endif | ||
|
||
// TEST_VALUE_1 and TEST_VALUE_2 are defined via port options | ||
#ifndef TEST_VALUE_1 | ||
#define TEST_VALUE_1 0 | ||
#endif | ||
#ifndef TEST_VALUE_2 | ||
#define TEST_VALUE_2 0 | ||
#endif | ||
|
||
int main() { | ||
assert(external_port_test_fn(99) == 99); // check that we can call a function from external_port_test.h | ||
printf("value1=%d&value2=%d\n", TEST_VALUE_1, TEST_VALUE_2); | ||
#ifdef TEST_DEPENDENCY_SDL2 | ||
SDL_version version; | ||
SDL_VERSION(&version); | ||
printf("sdl2=%d\n", version.major); | ||
#endif | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.