Skip to content

Commit 36b1791

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 a583b58 commit 36b1791

File tree

9 files changed

+54
-48
lines changed

9 files changed

+54
-48
lines changed

ChangeLog.md

+3
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

+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
@@ -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
arg = newargs[i]
29222927
arg_value = None
29232928

@@ -3064,10 +3069,6 @@ def consume_arg_file():
30643069
elif check_flag('--emit-symbol-map'):
30653070
options.emit_symbol_map = True
30663071
settings.EMIT_SYMBOL_MAP = 1
3067-
elif check_flag('--bind'):
3068-
settings.EMBIND = 1
3069-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'emval.js')))
3070-
settings.JS_LIBRARIES.append((0, os.path.join('embind', 'embind.js')))
30713072
elif check_arg('--embed-file'):
30723073
options.embed_files.append(consume_arg())
30733074
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
@@ -6928,9 +6928,9 @@ def test2():
69286928
do_test(test2, level=2, prefix='hello_libcxx')
69296929

69306930
def test_embind(self):
6931-
self.emcc_args += ['--bind']
6932-
6933-
create_file('test_embind.cpp', r'''
6931+
# Very that both the old `--bind` arg and the new `-lembind` arg work
6932+
for args in [['-lembind'], ['--bind']]:
6933+
create_file('test_embind.cpp', r'''
69346934
#include <stdio.h>
69356935
#include <emscripten/val.h>
69366936
@@ -6945,11 +6945,11 @@ def test_embind(self):
69456945
69466946
return 0;
69476947
}
6948-
''')
6949-
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11')
6948+
''')
6949+
self.do_runf('test_embind.cpp', 'abs(-10): 10\nabs(-11): 11', emcc_args=args)
69506950

69516951
def test_embind_2(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 printLerp() {
69556955
out('lerp ' + Module.lerp(100, 200, 66) + '.');
@@ -6974,7 +6974,7 @@ def test_embind_2(self):
69746974
self.do_runf('test_embind_2.cpp', 'lerp 166')
69756975

69766976
def test_embind_3(self):
6977-
self.emcc_args += ['--bind', '--post-js', 'post.js']
6977+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
69786978
create_file('post.js', '''
69796979
function ready() {
69806980
try {
@@ -7002,7 +7002,7 @@ def test_embind_3(self):
70027002
self.do_runf('test_embind_3.cpp', 'UnboundTypeError: Cannot call compute due to unbound types: Pi')
70037003

70047004
def test_embind_4(self):
7005-
self.emcc_args += ['--bind', '--post-js', 'post.js']
7005+
self.emcc_args += ['-lembind', '--post-js', 'post.js']
70067006
create_file('post.js', '''
70077007
function printFirstElement() {
70087008
out(Module.getBufferView()[0]);
@@ -7034,46 +7034,46 @@ def test_embind_4(self):
70347034
self.do_runf('test_embind_4.cpp', '107')
70357035

70367036
def test_embind_5(self):
7037-
self.emcc_args += ['--bind']
7037+
self.emcc_args += ['-lembind']
70387038
self.set_setting('EXIT_RUNTIME')
70397039
self.do_core_test('test_embind_5.cpp')
70407040

70417041
def test_embind_custom_marshal(self):
7042-
self.emcc_args += ['--bind', '--pre-js', test_file('embind/test_custom_marshal.js')]
7042+
self.emcc_args += ['-lembind', '--pre-js', test_file('embind/test_custom_marshal.js')]
70437043
self.do_run_in_out_file_test('embind/test_custom_marshal.cpp', assert_identical=True)
70447044

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

70497049
def test_embind_negative_constants(self):
7050-
self.emcc_args += ['--bind']
7050+
self.emcc_args += ['-lembind']
70517051
self.do_run_in_out_file_test('embind/test_negative_constants.cpp')
70527052

70537053
@also_with_wasm_bigint
70547054
def test_embind_unsigned(self):
7055-
self.emcc_args += ['--bind']
7055+
self.emcc_args += ['-lembind']
70567056
self.do_run_in_out_file_test('embind/test_unsigned.cpp')
70577057

70587058
def test_embind_val(self):
7059-
self.emcc_args += ['--bind']
7059+
self.emcc_args += ['-lembind']
70607060
self.do_run_in_out_file_test('embind/test_val.cpp')
70617061

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

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

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

@@ -7102,11 +7102,11 @@ def test_embind_no_rtti(self):
71027102
emscripten::function("dotest", &test);
71037103
}
71047104
''')
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_runf('main.cpp', '418\ndotest returned: 42\n')
71077107

71087108
def test_embind_polymorphic_class_no_rtti(self):
7109-
self.emcc_args += ['--bind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
7109+
self.emcc_args += ['-lembind', '-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
71107110
self.do_core_test('test_embind_polymorphic_class_no_rtti.cpp')
71117111

71127112
def test_embind_no_rtti_followed_by_rtti(self):
@@ -7134,7 +7134,7 @@ def test_embind_no_rtti_followed_by_rtti(self):
71347134
emscripten::function("dotest", &test);
71357135
}
71367136
'''
7137-
self.emcc_args += ['--bind', '-fno-rtti', '-frtti']
7137+
self.emcc_args += ['-lembind', '-fno-rtti', '-frtti']
71387138
self.do_run(src, '418\ndotest returned: 42\n')
71397139

71407140
@parameterized({
@@ -8544,7 +8544,7 @@ def test_pthread_create_embind_stack_check(self):
85448544
# embind should work with stack overflow checks (see #12356)
85458545
self.set_setting('STACK_OVERFLOW_CHECK', 2)
85468546
self.set_setting('EXIT_RUNTIME')
8547-
self.emcc_args += ['--bind']
8547+
self.emcc_args += ['-lembind']
85488548
self.do_run_in_out_file_test('core/pthread/create.cpp')
85498549

85508550
@node_pthreads
@@ -8814,7 +8814,7 @@ def test_abort_on_exceptions(self):
88148814
self.set_setting('EXIT_RUNTIME', 0)
88158815
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
88168816
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
8817-
self.emcc_args += ['--bind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
8817+
self.emcc_args += ['-lembind', '--post-js', test_file('core/test_abort_on_exception_post.js')]
88188818
self.do_core_test('test_abort_on_exception.cpp', interleaved_output=False)
88198819

88208820
@needs_dylink
@@ -8856,7 +8856,7 @@ def test_emscripten_async_call(self):
88568856
def test_embind_lib_with_asyncify(self, args):
88578857
self.uses_es6 = True
88588858
self.emcc_args += [
8859-
'--bind',
8859+
'-lembind',
88608860
'-sASYNCIFY',
88618861
'-sASYNCIFY_IMPORTS=["sleep_and_return"]',
88628862
'--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
@@ -2362,7 +2362,7 @@ def test_embind_asyncify(self):
23622362
function("sleep", &emscripten_sleep);
23632363
}
23642364
''')
2365-
self.run_process([EMXX, 'main.cpp', '--bind', '-sASYNCIFY', '--post-js', 'post.js'])
2365+
self.run_process([EMXX, 'main.cpp', '-lembind', '-sASYNCIFY', '--post-js', 'post.js'])
23662366
self.assertContained('done', self.run_js('a.out.js'))
23672367

23682368
def test_embind_closure_no_dynamic_execution(self):
@@ -2387,18 +2387,18 @@ def test_embind_closure_no_dynamic_execution(self):
23872387
emscripten::function("bar", &bar);
23882388
}
23892389
''')
2390-
self.run_process([EMXX, 'main.cpp', '--bind', '-O2', '--closure', '1',
2390+
self.run_process([EMXX, 'main.cpp', '-lembind', '-O2', '--closure', '1',
23912391
'-sNO_DYNAMIC_EXECUTION', '--post-js', 'post.js'])
23922392
self.assertContained('10\nok\n', self.run_js('a.out.js'))
23932393

23942394
@is_slow_test
23952395
@with_env_modify({'EMCC_CLOSURE_ARGS': '--externs ' + shlex.quote(test_file('embind/underscore-externs.js'))})
23962396
def test_embind(self):
23972397
test_cases = [
2398-
(['--bind']),
2399-
(['--bind', '-O1']),
2400-
(['--bind', '-O2']),
2401-
(['--bind', '-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')]),
2398+
(['-lembind']),
2399+
(['-lembind', '-O1']),
2400+
(['-lembind', '-O2']),
2401+
(['-lembind', '-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')]),
24022402
]
24032403
without_utf8_args = ['-sEMBIND_STD_STRING_IS_UTF8=0']
24042404
test_cases_without_utf8 = []
@@ -2407,7 +2407,7 @@ def test_embind(self):
24072407
test_cases += test_cases_without_utf8
24082408
test_cases.extend([(args[:] + ['-sDYNAMIC_EXECUTION=0']) for args in test_cases])
24092409
# closure compiler doesn't work with DYNAMIC_EXECUTION=0
2410-
test_cases.append((['--bind', '-O2', '--closure=1']))
2410+
test_cases.append((['-lembind', '-O2', '--closure=1']))
24112411
for args in test_cases:
24122412
print(args)
24132413
self.clear()
@@ -4460,7 +4460,7 @@ def test(args=[]):
44604460
self.assertContained('%d %d %d __attribute__((used))' % (shared.EMSCRIPTEN_VERSION_MAJOR, shared.EMSCRIPTEN_VERSION_MINOR, shared.EMSCRIPTEN_VERSION_TINY), out)
44614461

44624462
test()
4463-
test(['--bind'])
4463+
test(['-lembind'])
44644464

44654465
def test_dashE_respect_dashO(self):
44664466
# issue #3365
@@ -10754,7 +10754,7 @@ def test_deps_info(self):
1075410754
if 'emscripten_pc_get_function' in function:
1075510755
cmd.append('-sUSE_OFFSET_CONVERTER')
1075610756
if 'embind' in function:
10757-
cmd.append('--bind')
10757+
cmd.append('-lembind')
1075810758
if 'websocket' in function:
1075910759
cmd += ['-sPROXY_POSIX_SOCKETS', '-lwebsocket.js']
1076010760
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)