forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suppport for external ports (emscripten-core#21316)
- Loading branch information
1 parent
67b65be
commit c43a9a6
Showing
10 changed files
with
225 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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,62 @@ | ||
# 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 | ||
|
||
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 | ||
} | ||
|
||
deps = [] | ||
|
||
|
||
def get_lib_name(settings): | ||
return 'lib_external.a' | ||
|
||
|
||
def get(ports, settings, shared): | ||
# for simplicity in testing, the source is in the same folder as the port and not fetched as a tarball | ||
source_dir = os.path.dirname(__file__) | ||
|
||
def create(final): | ||
ports.install_headers(source_dir) | ||
print(f'about to build {source_dir}') | ||
ports.build_port(source_dir, final, 'external') | ||
|
||
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')] | ||
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 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,3 @@ | ||
int my_port_fn(int value) { | ||
return value; | ||
} |
This file contains 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 @@ | ||
int my_port_fn(int); |
This file contains 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,25 @@ | ||
# 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 | ||
|
||
|
||
def get_lib_name(settings): | ||
return 'lib_simple.a' | ||
|
||
|
||
def get(ports, settings, shared): | ||
# for simplicity in testing, the source is in the same folder as the port and not fetched as a tarball | ||
source_dir = os.path.dirname(__file__) | ||
|
||
def create(final): | ||
ports.install_headers(source_dir) | ||
ports.build_port(source_dir, final, 'simple') | ||
|
||
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)) |
This file contains 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 <my_port.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(my_port_fn(99) == 99); // check that we can call a function from my_port.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 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,14 @@ | ||
/* | ||
* 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 <my_port.h> | ||
#include <assert.h> | ||
|
||
int main() { | ||
assert(my_port_fn(99) == 99); // check that we can call a function from my_port.h | ||
return 0; | ||
} |
This file contains 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 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