Skip to content

Commit e0b29bf

Browse files
committed
Deprecate --bind in favor of just -lembind. NFC
All that the `--bind` flag does is enable the embind library (native and JS portions), so I think its more clear if we just use the normal `-l` method of including it. Historically `--bind` has sounded to some (including myself) like a verb rather than the name of a library leading to folks to believe that the linker is actually doing the binding, whereas all the binding is done either at compile time or at load time. No "binding" happens during linking.
1 parent 33c40be commit e0b29bf

File tree

8 files changed

+51
-48
lines changed

8 files changed

+51
-48
lines changed

docs/emcc.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ Options that are modified or new in *emcc* are listed below:
388388
script to be run.
389389

390390
"--bind"
391-
[link] Compiles the source code using the Embind bindings to
392-
connect C/C++ and JavaScript.
391+
[link] Links against embind library. Deprecated: Use "-lembind"
392+
instead.
393393

394394
"--ignore-dynamic-linking"
395395
[link] Tells the compiler to ignore dynamic linking (the user will

emcc.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1902,9 +1902,6 @@ def default_setting(name, new_default):
19021902
settings.FULL_ES2 = 1
19031903
settings.MAX_WEBGL_VERSION = max(2, settings.MAX_WEBGL_VERSION)
19041904

1905-
if settings.EMBIND:
1906-
state.forced_stdlibs.append('libembind')
1907-
19081905
settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore', 'stackAlloc']
19091906
if not settings.STANDALONE_WASM:
19101907
# in standalone mode, crt1 will call the constructors from inside the wasm
@@ -2120,6 +2117,9 @@ def check_memory_setting(setting):
21202117
if not settings.DECLARE_ASM_MODULE_EXPORTS or '-lexports.js' in [x for _, x in state.link_flags]:
21212118
settings.MINIFY_ASMJS_EXPORT_NAMES = 0
21222119

2120+
if '-lembind' in [x for _, x in state.link_flags]:
2121+
settings.EMBIND = 1
2122+
21232123
# Enable minification of wasm imports and exports when appropriate, if we
21242124
# are emitting an optimized JS+wasm combo (then the JS knows how to load the minified names).
21252125
# Things that process the JS after this operation would be done must disable this.
@@ -2909,6 +2909,11 @@ def parse_args(newargs):
29092909
skip = False
29102910
continue
29112911

2912+
# Support legacy '--bind' flag, by mapping to `-lembind` which now
2913+
# has the same effect
2914+
if newargs[i] == '--bind':
2915+
newargs[i] = '-lembind'
2916+
29122917
# On Windows Vista (and possibly others), excessive spaces in the command line
29132918
# leak into the items in this array, so trim e.g. 'foo.cpp ' -> 'foo.cpp'
29142919
newargs[i] = newargs[i].strip()
@@ -3058,10 +3063,6 @@ def consume_arg_file():
30583063
elif check_flag('--emit-symbol-map'):
30593064
options.emit_symbol_map = True
30603065
settings.EMIT_SYMBOL_MAP = 1
3061-
elif check_flag('--bind'):
3062-
settings.EMBIND = 1
3063-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'emval.js')))
3064-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'embind.js')))
30653066
elif check_arg('--embed-file'):
30663067
options.embed_files.append(consume_arg())
30673068
elif check_arg('--preload-file'):

site/source/docs/porting/connecting_cpp_and_javascript/embind.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ the simple C++ ``lerp()`` :cpp:func:`function` to JavaScript.
5656
To compile the above example using *embind*, we invoke *emcc* with the
5757
:ref:`bind <emcc-bind>` option::
5858

59-
emcc --bind -o quick_example.js quick_example.cpp
59+
emcc -lembind -o quick_example.js quick_example.cpp
6060

6161
The resulting **quick_example.js** file can be loaded as a node module
6262
or via a ``<script>`` tag:
@@ -107,7 +107,7 @@ the object file.
107107
For example, to generate bindings for a hypothetical **library.a** compiled
108108
with Emscripten run *emcc* with ``--whole-archive`` compiler flag::
109109

110-
emcc --bind -o library.js -Wl,--whole-archive library.a -Wl,--no-whole-archive
110+
emcc -lembind -o library.js -Wl,--whole-archive library.a -Wl,--no-whole-archive
111111

112112
Classes
113113
=======
@@ -875,7 +875,7 @@ and then play the tone.
875875

876876
The example can be compiled on the Linux/macOS terminal with::
877877

878-
emcc -O2 -Wall -Werror --bind -o oscillator.html oscillator.cpp
878+
emcc -O2 -Wall -Werror -lembind -o oscillator.html oscillator.cpp
879879

880880

881881
Built-in type conversions

site/source/docs/tools_reference/emcc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Options that are modified or new in *emcc* are listed below:
341341

342342
``--bind``
343343
[link]
344-
Compiles the source code using the :ref:`embind` bindings to connect C/C++ and JavaScript.
344+
Links against embind library. Deprecated: Use ``-lembind`` instead.
345345

346346
``--ignore-dynamic-linking``
347347
[link]

src/settings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ var EXPORT_NAME = 'Module';
12021202
// When this flag is set, the following features (linker flags) are unavailable:
12031203
// -s RELOCATABLE=1: the function Runtime.loadDynamicLibrary would need to eval().
12041204
// and some features may fall back to slower code paths when they need to:
1205-
// --bind: Embind uses eval() to jit functions for speed.
1205+
// Embind: uses eval() to jit functions for speed.
12061206
//
12071207
// Additionally, the following Emscripten runtime functions are unavailable when
12081208
// DYNAMIC_EXECUTION=0 is set, and an attempt to call them will throw an exception:

tests/test_core.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -6903,9 +6903,9 @@ def test2():
69036903
do_test(test2, level=2, prefix='hello_libcxx')
69046904

69056905
def test_embind(self):
6906-
self.emcc_args += ['--bind']
6907-
6908-
create_file('test_embind.cpp', r'''
6906+
# Very that both the old `--bind` arg and the new `-lembind` arg work
6907+
for args in [['-lembind'], ['--bind']]:
6908+
create_file('test_embind.cpp', r'''
69096909
#include <stdio.h>
69106910
#include <emscripten/val.h>
69116911
@@ -6920,11 +6920,11 @@ def test_embind(self):
69206920
69216921
return 0;
69226922
}
6923-
''')
6924-
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11')
6923+
''')
6924+
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11', emcc_args=args)
69256925

69266926
def test_embind_2(self):
6927-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6927+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69286928
create_file('post.js', '''
69296929
function printLerp() {
69306930
out('lerp ' + Module.lerp(100, 200, 66) + '.');
@@ -6949,7 +6949,7 @@ def test_embind_2(self):
69496949
self.do_runf('test_embind_2.cpp', 'lerp 166')
69506950

69516951
def test_embind_3(self):
6952-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6952+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69536953
create_file('post.js', '''
69546954
function ready() {
69556955
try {
@@ -6977,7 +6977,7 @@ def test_embind_3(self):
69776977
self.do_runf('test_embind_3.cpp', 'UnboundTypeError: Cannot call compute due to unbound types: Pi')
69786978

69796979
def test_embind_4(self):
6980-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6980+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69816981
create_file('post.js', '''
69826982
function printFirstElement() {
69836983
out(Module.getBufferView()[0]);
@@ -7009,46 +7009,46 @@ def test_embind_4(self):
70097009
self.do_runf('test_embind_4.cpp', '107')
70107010

70117011
def test_embind_5(self):
7012-
self.emcc_args += ['--bind']
7012+
self.emcc_args += ['-lembind']
70137013
self.set_setting('EXIT_RUNTIME')
70147014
self.do_core_test('test_embind_5.cpp')
70157015

70167016
def test_embind_custom_marshal(self):
7017-
self.emcc_args += ['--bind', '--pre-js', test_file('embind/test_custom_marshal.js')]
7017+
self.emcc_args += ['-lembind', '--pre-js', test_file('embind/test_custom_marshal.js')]
70187018
self.do_run_in_out_file_test('embind/test_custom_marshal.cpp', assert_identical=True)
70197019

70207020
def test_embind_float_constants(self):
7021-
self.emcc_args += ['--bind']
7021+
self.emcc_args += ['-lembind']
70227022
self.do_run_in_out_file_test('embind/test_float_constants.cpp')
70237023

70247024
def test_embind_negative_constants(self):
7025-
self.emcc_args += ['--bind']
7025+
self.emcc_args += ['-lembind']
70267026
self.do_run_in_out_file_test('embind/test_negative_constants.cpp')
70277027

70287028
@also_with_wasm_bigint
70297029
def test_embind_unsigned(self):
7030-
self.emcc_args += ['--bind']
7030+
self.emcc_args += ['-lembind']
70317031
self.do_run_in_out_file_test('embind/test_unsigned.cpp')
70327032

70337033
def test_embind_val(self):
7034-
self.emcc_args += ['--bind']
7034+
self.emcc_args += ['-lembind']
70357035
self.do_run_in_out_file_test('embind/test_val.cpp')
70367036

70377037
def test_embind_val_assignment(self):
7038-
err = self.expect_fail([EMCC, test_file('embind/test_val_assignment.cpp'), '--bind', '-c'])
7038+
err = self.expect_fail([EMCC, test_file('embind/test_val_assignment.cpp'), '-lembind', '-c'])
70397039
self.assertContained('candidate function not viable: expects an lvalue for object argument', err)
70407040

70417041
@no_wasm2js('wasm_bigint')
70427042
def test_embind_i64_val(self):
70437043
self.set_setting('WASM_BIGINT')
7044-
self.emcc_args += ['--bind']
7044+
self.emcc_args += ['-lembind']
70457045
self.node_args += ['--experimental-wasm-bigint']
70467046
self.do_run_in_out_file_test('embind/test_i64_val.cpp', assert_identical=True)
70477047

70487048
@no_wasm2js('wasm_bigint')
70497049
def test_embind_i64_binding(self):
70507050
self.set_setting('WASM_BIGINT')
7051-
self.emcc_args += ['--bind']
7051+
self.emcc_args += ['-lembind']
70527052
self.node_args += ['--experimental-wasm-bigint']
70537053
self.do_run_in_out_file_test('embind/test_i64_binding.cpp', assert_identical=True)
70547054

@@ -7077,11 +7077,11 @@ def test_embind_no_rtti(self):
70777077
emscripten::function("dotest", &test);
70787078
}
70797079
''')
7080-
self.emcc_args += ['--bind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
7080+
self.emcc_args += ['-lembind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
70817081
self.do_runf('main.cpp', '418\ndotest returned: 42\n')
70827082

70837083
def test_embind_polymorphic_class_no_rtti(self):
7084-
self.emcc_args += ['--bind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
7084+
self.emcc_args += ['-lembind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
70857085
self.do_core_test('test_embind_polymorphic_class_no_rtti.cpp')
70867086

70877087
def test_embind_no_rtti_followed_by_rtti(self):
@@ -7109,7 +7109,7 @@ def test_embind_no_rtti_followed_by_rtti(self):
71097109
emscripten::function("dotest", &test);
71107110
}
71117111
'''
7112-
self.emcc_args += ['--bind', '-fno-rtti', '-frtti']
7112+
self.emcc_args += ['-lembind', '-fno-rtti', '-frtti']
71137113
self.do_run(src, '418\ndotest returned: 42\n')
71147114

71157115
@parameterized({
@@ -8519,7 +8519,7 @@ def test_pthread_create_embind_stack_check(self):
85198519
# embind should work with stack overflow checks (see #12356)
85208520
self.set_setting('STACK_OVERFLOW_CHECK', 2)
85218521
self.set_setting('EXIT_RUNTIME')
8522-
self.emcc_args += ['--bind']
8522+
self.emcc_args += ['-lembind']
85238523
self.do_run_in_out_file_test('core/pthread/create.cpp')
85248524

85258525
@node_pthreads
@@ -8789,7 +8789,7 @@ def test_abort_on_exceptions(self):
87898789
self.set_setting('EXIT_RUNTIME', 0)
87908790
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
87918791
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
8792-
self.emcc_args += ['--bind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
8792+
self.emcc_args += ['-lembind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
87938793
self.do_core_test('test_abort_on_exception.cpp', interleaved_output=False)
87948794

87958795
@needs_dylink
@@ -8831,7 +8831,7 @@ def test_emscripten_async_call(self):
88318831
def test_embind_lib_with_asyncify(self, args):
88328832
self.uses_es6 = True
88338833
self.emcc_args += [
8834-
'--bind',
8834+
'-lembind',
88358835
'-sASYNCIFY',
88368836
'-sASYNCIFY_IMPORTS=["sleep_and_return"]',
88378837
'--post-js', test_file('core/embind_lib_with_asyncify.test.js'),

tests/test_other.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def test_incorrect_c_detection(self):
824824
# For linking you need to use `em++` or pass `-x c++`
825825
create_file('test.c', 'foo\n')
826826
for compiler in [EMCC, EMXX]:
827-
self.run_process([compiler, '-c', '--bind', '--embed-file', 'test.c', test_file('hello_world.cpp')])
827+
self.run_process([compiler, '-c', '-lembind', '--embed-file', 'test.c', test_file('hello_world.cpp')])
828828

829829
def test_odd_suffixes(self):
830830
for suffix in ['CPP', 'c++', 'C++', 'cxx', 'CXX', 'cc', 'CC']:
@@ -1081,7 +1081,7 @@ def test(compiler, main_name, lib_args, err_expected):
10811081
return 0;
10821082
}
10831083
''')
1084-
test(EMXX, 'main.cpp', ['-Wl,--start-group', lib_name, '-Wl,--end-group', '--bind'], None)
1084+
test(EMXX, 'main.cpp', ['-Wl,--start-group', lib_name, '-Wl,--end-group', '-lembind'], None)
10851085

10861086
def test_whole_archive(self):
10871087
# Verify that -Wl,--whole-archive includes the static constructor from the
@@ -2358,7 +2358,7 @@ def test_embind_asyncify(self):
23582358
function("sleep", &emscripten_sleep);
23592359
}
23602360
''')
2361-
self.run_process([EMXX, 'main.cpp', '--bind', '-sASYNCIFY', '--post-js', 'post.js'])
2361+
self.run_process([EMXX, 'main.cpp', '-lembind', '-sASYNCIFY', '--post-js', 'post.js'])
23622362
self.assertContained('done', self.run_js('a.out.js'))
23632363

23642364
def test_embind_closure_no_dynamic_execution(self):
@@ -2383,18 +2383,18 @@ def test_embind_closure_no_dynamic_execution(self):
23832383
emscripten::function("bar", &bar);
23842384
}
23852385
''')
2386-
self.run_process([EMXX, 'main.cpp', '--bind', '-O2', '--closure', '1',
2386+
self.run_process([EMXX, 'main.cpp', '-lembind', '-O2', '--closure', '1',
23872387
'-sNO_DYNAMIC_EXECUTION', '--post-js', 'post.js'])
23882388
self.assertContained('10\nok\n', self.run_js('a.out.js'))
23892389

23902390
@is_slow_test
23912391
@with_env_modify({'EMCC_CLOSURE_ARGS': '--externs ' + shlex.quote(test_file('embind/underscore-externs.js'))})
23922392
def test_embind(self):
23932393
test_cases = [
2394-
(['--bind']),
2395-
(['--bind', '-O1']),
2396-
(['--bind', '-O2']),
2397-
(['--bind', '-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')]),
2394+
(['-lembind']),
2395+
(['-lembind', '-O1']),
2396+
(['-lembind', '-O2']),
2397+
(['-lembind', '-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')]),
23982398
]
23992399
without_utf8_args = ['-sEMBIND_STD_STRING_IS_UTF8=0']
24002400
test_cases_without_utf8 = []
@@ -2403,7 +2403,7 @@ def test_embind(self):
24032403
test_cases += test_cases_without_utf8
24042404
test_cases.extend([(args[:] + ['-sDYNAMIC_EXECUTION=0']) for args in test_cases])
24052405
# closure compiler doesn't work with DYNAMIC_EXECUTION=0
2406-
test_cases.append((['--bind', '-O2', '--closure=1']))
2406+
test_cases.append((['-lembind', '-O2', '--closure=1']))
24072407
for args in test_cases:
24082408
print(args)
24092409
self.clear()
@@ -4452,7 +4452,7 @@ def test(args=[]):
44524452
self.assertContained('%d %d %d __attribute__((used))' % (shared.EMSCRIPTEN_VERSION_MAJOR, shared.EMSCRIPTEN_VERSION_MINOR, shared.EMSCRIPTEN_VERSION_TINY), out)
44534453

44544454
test()
4455-
test(['--bind'])
4455+
test(['-lembind'])
44564456

44574457
def test_dashE_respect_dashO(self):
44584458
# issue #3365
@@ -10747,7 +10747,7 @@ def test_deps_info(self):
1074710747
if 'emscripten_pc_get_function' in function:
1074810748
cmd.append('-sUSE_OFFSET_CONVERTER')
1074910749
if 'embind' in function:
10750-
cmd.append('--bind')
10750+
cmd.append('-lembind')
1075110751
if 'websocket' in function:
1075210752
cmd += ['-sPROXY_POSIX_SOCKETS', '-lwebsocket.js']
1075310753
if function == 'Mix_LoadWAV_RW':

tools/building.py

+2
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ def map_to_js_libs(library_name):
13621362
"""
13631363
# Some native libraries are implemented in Emscripten as system side JS libraries
13641364
library_map = {
1365+
'embind': ['embind/embind.js', 'embind/emval.js'],
13651366
'EGL': ['library_egl.js'],
13661367
'GL': ['library_webgl.js', 'library_html5_webgl.js'],
13671368
'webgl.js': ['library_webgl.js', 'library_html5_webgl.js'],
@@ -1390,6 +1391,7 @@ def map_to_js_libs(library_name):
13901391
}
13911392
# And some are hybrid and require JS and native libraries to be included
13921393
native_library_map = {
1394+
'embind': 'libembind',
13931395
'GL': 'libGL',
13941396
}
13951397

0 commit comments

Comments
 (0)