Skip to content

Commit 7281aa0

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 fb0d9ab commit 7281aa0

File tree

9 files changed

+54
-48
lines changed

9 files changed

+54
-48
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ See docs/process.md for more on how version tagging works.
2424
`emcc` now uses this mode when the `--embed-file` option is used. If you
2525
use `file_packager` directly it is recommended that you switch to the new mode
2626
by adding `--obj-output` to the command line. (#16050)
27+
- The `--bind` flag used to enable embind has been deprecated in favor of
28+
`-lembind`. The semantics have not changed and the old flag continues to
29+
work. (#16087)
2730

2831
3.1.2 - 20/01/2022
2932
------------------

docs/emcc.txt

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,9 +1935,6 @@ def default_setting(name, new_default):
19351935
settings.FULL_ES2 = 1
19361936
settings.MAX_WEBGL_VERSION = max(2, settings.MAX_WEBGL_VERSION)
19371937

1938-
if settings.EMBIND:
1939-
state.forced_stdlibs.append('libembind')
1940-
19411938
settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore', 'stackAlloc']
19421939
if not settings.STANDALONE_WASM:
19431940
# in standalone mode, crt1 will call the constructors from inside the wasm
@@ -2153,6 +2150,9 @@ def check_memory_setting(setting):
21532150
if not settings.DECLARE_ASM_MODULE_EXPORTS or '-lexports.js' in [x for _, x in state.link_flags]:
21542151
settings.MINIFY_ASMJS_EXPORT_NAMES = 0
21552152

2153+
if '-lembind' in [x for _, x in state.link_flags]:
2154+
settings.EMBIND = 1
2155+
21562156
# Enable minification of wasm imports and exports when appropriate, if we
21572157
# are emitting an optimized JS+wasm combo (then the JS knows how to load the minified names).
21582158
# Things that process the JS after this operation would be done must disable this.
@@ -2918,6 +2918,11 @@ def parse_args(newargs):
29182918
skip = False
29192919
continue
29202920

2921+
# Support legacy '--bind' flag, by mapping to `-lembind` which now
2922+
# has the same effect
2923+
if newargs[i] == '--bind':
2924+
newargs[i] = '-lembind'
2925+
29212926
# On Windows Vista (and possibly others), excessive spaces in the command line
29222927
# leak into the items in this array, so trim e.g. 'foo.cpp ' -> 'foo.cpp'
29232928
newargs[i] = newargs[i].strip()
@@ -3067,10 +3072,6 @@ def consume_arg_file():
30673072
elif check_flag('--emit-symbol-map'):
30683073
options.emit_symbol_map = True
30693074
settings.EMIT_SYMBOL_MAP = 1
3070-
elif check_flag('--bind'):
3071-
settings.EMBIND = 1
3072-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'emval.js')))
3073-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'embind.js')))
30743075
elif check_arg('--embed-file'):
30753076
options.embed_files.append(consume_arg())
30763077
elif check_arg('--preload-file'):

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6924,9 +6924,9 @@ def test2():
69246924
do_test(test2, level=2, prefix='hello_libcxx')
69256925

69266926
def test_embind(self):
6927-
self.emcc_args += ['--bind']
6928-
6929-
create_file('test_embind.cpp', r'''
6927+
# Very that both the old `--bind` arg and the new `-lembind` arg work
6928+
for args in [['-lembind'], ['--bind']]:
6929+
create_file('test_embind.cpp', r'''
69306930
#include <stdio.h>
69316931
#include <emscripten/val.h>
69326932
@@ -6941,11 +6941,11 @@ def test_embind(self):
69416941
69426942
return 0;
69436943
}
6944-
''')
6945-
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11')
6944+
''')
6945+
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11', emcc_args=args)
69466946

69476947
def test_embind_2(self):
6948-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6948+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69496949
create_file('post.js', '''
69506950
function printLerp() {
69516951
out('lerp ' + Module.lerp(100, 200, 66) + '.');
@@ -6970,7 +6970,7 @@ def test_embind_2(self):
69706970
self.do_runf('test_embind_2.cpp', 'lerp 166')
69716971

69726972
def test_embind_3(self):
6973-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6973+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69746974
create_file('post.js', '''
69756975
function ready() {
69766976
try {
@@ -6998,7 +6998,7 @@ def test_embind_3(self):
69986998
self.do_runf('test_embind_3.cpp', 'UnboundTypeError: Cannot call compute due to unbound types: Pi')
69996999

70007000
def test_embind_4(self):
7001-
self.emcc_args += ['--bind', '--post-js', 'post.js']
7001+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
70027002
create_file('post.js', '''
70037003
function printFirstElement() {
70047004
out(Module.getBufferView()[0]);
@@ -7030,46 +7030,46 @@ def test_embind_4(self):
70307030
self.do_runf('test_embind_4.cpp', '107')
70317031

70327032
def test_embind_5(self):
7033-
self.emcc_args += ['--bind']
7033+
self.emcc_args += ['-lembind']
70347034
self.set_setting('EXIT_RUNTIME')
70357035
self.do_core_test('test_embind_5.cpp')
70367036

70377037
def test_embind_custom_marshal(self):
7038-
self.emcc_args += ['--bind', '--pre-js', test_file('embind/test_custom_marshal.js')]
7038+
self.emcc_args += ['-lembind', '--pre-js', test_file('embind/test_custom_marshal.js')]
70397039
self.do_run_in_out_file_test('embind/test_custom_marshal.cpp', assert_identical=True)
70407040

70417041
def test_embind_float_constants(self):
7042-
self.emcc_args += ['--bind']
7042+
self.emcc_args += ['-lembind']
70437043
self.do_run_in_out_file_test('embind/test_float_constants.cpp')
70447044

70457045
def test_embind_negative_constants(self):
7046-
self.emcc_args += ['--bind']
7046+
self.emcc_args += ['-lembind']
70477047
self.do_run_in_out_file_test('embind/test_negative_constants.cpp')
70487048

70497049
@also_with_wasm_bigint
70507050
def test_embind_unsigned(self):
7051-
self.emcc_args += ['--bind']
7051+
self.emcc_args += ['-lembind']
70527052
self.do_run_in_out_file_test('embind/test_unsigned.cpp')
70537053

70547054
def test_embind_val(self):
7055-
self.emcc_args += ['--bind']
7055+
self.emcc_args += ['-lembind']
70567056
self.do_run_in_out_file_test('embind/test_val.cpp')
70577057

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

70627062
@no_wasm2js('wasm_bigint')
70637063
def test_embind_i64_val(self):
70647064
self.set_setting('WASM_BIGINT')
7065-
self.emcc_args += ['--bind']
7065+
self.emcc_args += ['-lembind']
70667066
self.node_args += ['--experimental-wasm-bigint']
70677067
self.do_run_in_out_file_test('embind/test_i64_val.cpp', assert_identical=True)
70687068

70697069
@no_wasm2js('wasm_bigint')
70707070
def test_embind_i64_binding(self):
70717071
self.set_setting('WASM_BIGINT')
7072-
self.emcc_args += ['--bind']
7072+
self.emcc_args += ['-lembind']
70737073
self.node_args += ['--experimental-wasm-bigint']
70747074
self.do_run_in_out_file_test('embind/test_i64_binding.cpp', assert_identical=True)
70757075

@@ -7098,11 +7098,11 @@ def test_embind_no_rtti(self):
70987098
emscripten::function("dotest", &test);
70997099
}
71007100
''')
7101-
self.emcc_args += ['--bind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
7101+
self.emcc_args += ['-lembind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
71027102
self.do_runf('main.cpp', '418\ndotest returned: 42\n')
71037103

71047104
def test_embind_polymorphic_class_no_rtti(self):
7105-
self.emcc_args += ['--bind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
7105+
self.emcc_args += ['-lembind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
71067106
self.do_core_test('test_embind_polymorphic_class_no_rtti.cpp')
71077107

71087108
def test_embind_no_rtti_followed_by_rtti(self):
@@ -7130,7 +7130,7 @@ def test_embind_no_rtti_followed_by_rtti(self):
71307130
emscripten::function("dotest", &test);
71317131
}
71327132
'''
7133-
self.emcc_args += ['--bind', '-fno-rtti', '-frtti']
7133+
self.emcc_args += ['-lembind', '-fno-rtti', '-frtti']
71347134
self.do_run(src, '418\ndotest returned: 42\n')
71357135

71367136
@parameterized({
@@ -8540,7 +8540,7 @@ def test_pthread_create_embind_stack_check(self):
85408540
# embind should work with stack overflow checks (see #12356)
85418541
self.set_setting('STACK_OVERFLOW_CHECK', 2)
85428542
self.set_setting('EXIT_RUNTIME')
8543-
self.emcc_args += ['--bind']
8543+
self.emcc_args += ['-lembind']
85448544
self.do_run_in_out_file_test('core/pthread/create.cpp')
85458545

85468546
@node_pthreads
@@ -8810,7 +8810,7 @@ def test_abort_on_exceptions(self):
88108810
self.set_setting('EXIT_RUNTIME', 0)
88118811
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
88128812
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
8813-
self.emcc_args += ['--bind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
8813+
self.emcc_args += ['-lembind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
88148814
self.do_core_test('test_abort_on_exception.cpp', interleaved_output=False)
88158815

88168816
@needs_dylink
@@ -8852,7 +8852,7 @@ def test_emscripten_async_call(self):
88528852
def test_embind_lib_with_asyncify(self, args):
88538853
self.uses_es6 = True
88548854
self.emcc_args += [
8855-
'--bind',
8855+
'-lembind',
88568856
'-sASYNCIFY',
88578857
'-sASYNCIFY_IMPORTS=["sleep_and_return"]',
88588858
'--post-js', test_file('core/embind_lib_with_asyncify.test.js'),

tests/test_other.py

Lines changed: 11 additions & 11 deletions
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()
@@ -4456,7 +4456,7 @@ def test(args=[]):
44564456
self.assertContained('%d %d %d __attribute__((used))' % (shared.EMSCRIPTEN_VERSION_MAJOR, shared.EMSCRIPTEN_VERSION_MINOR, shared.EMSCRIPTEN_VERSION_TINY), out)
44574457

44584458
test()
4459-
test(['--bind'])
4459+
test(['-lembind'])
44604460

44614461
def test_dashE_respect_dashO(self):
44624462
# issue #3365
@@ -10751,7 +10751,7 @@ def test_deps_info(self):
1075110751
if 'emscripten_pc_get_function' in function:
1075210752
cmd.append('-sUSE_OFFSET_CONVERTER')
1075310753
if 'embind' in function:
10754-
cmd.append('--bind')
10754+
cmd.append('-lembind')
1075510755
if 'websocket' in function:
1075610756
cmd += ['-sPROXY_POSIX_SOCKETS', '-lwebsocket.js']
1075710757
if function == 'Mix_LoadWAV_RW':

tools/building.py

Lines changed: 2 additions & 0 deletions
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)