diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000000..bfaea1c711ba8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = false diff --git a/AUTHORS b/AUTHORS index 1732e2e50dcfa..43633784d06eb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -293,3 +293,4 @@ a license to everyone to use it as detailed in LICENSE.) * Fumiya Chiba * Ryan C. Gordon * Inseok Lee +* Thomas Heck diff --git a/emcc.py b/emcc.py index 586f8b711c36b..5bf6349830178 100755 --- a/emcc.py +++ b/emcc.py @@ -47,6 +47,7 @@ BITCODE_ENDINGS = ('.bc', '.o', '.obj', '.lo') DYNAMICLIB_ENDINGS = ('.dylib', '.so') # Windows .dll suffix is not included in this list, since those are never linked to directly on the command line. STATICLIB_ENDINGS = ('.a',) +JSLIB_ENDINGS = ('.emlib.js',) ASSEMBLY_ENDINGS = ('.ll',) HEADER_ENDINGS = ('.h', '.hxx', '.hpp', '.hh', '.H', '.HXX', '.HPP', '.HH') WASM_ENDINGS = ('.wasm', '.wast') @@ -965,13 +966,16 @@ def get_last_setting_change(setting): logging.debug('looking for library "%s"', lib) found = False for prefix in LIB_PREFIXES: - for suff in STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS: + for suff in STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS + JSLIB_ENDINGS: name = prefix + lib + suff for lib_dir in lib_dirs: path = os.path.join(lib_dir, name) if os.path.exists(path): logging.debug('found library "%s" at %s', lib, path) - input_files.append((i, path)) + if suff in JSLIB_ENDINGS: + js_libraries.append(path) + else: + input_files.append((i, path)) found = True break if found: break @@ -996,7 +1000,7 @@ def check(input_file): input_files = [(i, input_file) for (i, input_file) in input_files if check(input_file)] if len(input_files) == 0: - logging.error('no input files\nnote that input files without a known suffix are ignored, make sure your input files end with one of: ' + str(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + STATICLIB_ENDINGS + ASSEMBLY_ENDINGS + HEADER_ENDINGS)) + logging.error('no input files\nnote that input files without a known suffix are ignored, make sure your input files end with one of: ' + str(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + STATICLIB_ENDINGS + JSLIB_ENDINGS + ASSEMBLY_ENDINGS + HEADER_ENDINGS)) exit(1) newargs = CC_ADDITIONAL_ARGS + newargs diff --git a/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst b/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst index 160ac96666b2f..05bdf6dab66ce 100644 --- a/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst +++ b/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst @@ -327,10 +327,10 @@ libraries for relevant external symbols. By default, the implementation is added to **library.js** (and this is where you'll find parts of Emscripten's *libc*). You can put the JavaScript implementation in your own library file and add it using -the :ref:`emcc option ` ``--js-library``. See -`test_js_libraries`_ in **tests/test_other.py** for a complete working -example, including the syntax you should use inside the JavaScript library -file. +the :ref:`emcc option ` ``--js-library`` or linking to +it by using the ``-L`` and `-l`` arguments. See `test_js_libraries`_ in +**tests/test_other.py** for a complete working example, including the +syntax you should use inside the JavaScript library file. As a simple example, consider the case where you have some C code like this: diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index cda2ab112c867..47e7e65e534eb 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -331,6 +331,7 @@ Options that are modified or new in *emcc* are listed below: ``--js-library `` A JavaScript library to use in addition to those in Emscripten's core libraries (src/library_*). + This can be also achieved by using the linking arguments ``-L`` and ``-l``. .. _emcc-verbose: diff --git a/tests/link_jslib/link_jslib.emlib.js b/tests/link_jslib/link_jslib.emlib.js new file mode 100644 index 0000000000000..3317b48c03e9f --- /dev/null +++ b/tests/link_jslib/link_jslib.emlib.js @@ -0,0 +1,3 @@ +LibraryManager.library.test_link_jslib = function test_link_jslib(a, b) { + return a + b; +}; diff --git a/tests/link_jslib/main.c b/tests/link_jslib/main.c new file mode 100644 index 0000000000000..e001fd6f7bff9 --- /dev/null +++ b/tests/link_jslib/main.c @@ -0,0 +1,11 @@ +#include + +extern "C" { + extern int test_link_jslib(int a, int b); +} + +int main() { + int temp = test_link_jslib(11, 31); + printf("res: %d\n", temp); + return 0; +} diff --git a/tests/test_core.py b/tests/test_core.py index 8bb094b9b2f2d..a0f2d1952eb00 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -7293,6 +7293,10 @@ def test_mallinfo(self): def test_wrap_malloc(self): self.do_run(open(path_from_root('tests', 'wrap_malloc.cpp')).read(), 'OK.') + + def test_link_jslib(self): + self.emcc_args += ['-L', path_from_root('tests', 'link_jslib'), '-l', 'link_jslib'] + self.do_run(open(path_from_root('tests', 'link_jslib', 'main.c')).read(), 'res: 42') # Generate tests for everything def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0,