@@ -289,6 +289,9 @@ Options that are modified or new in %s include:
289
289
The main file resides in the base directory and
290
290
has the suffix ".js".
291
291
292
+ --bind Compiles the source code using the "embind"
293
+ bindings approach, which connects C/C++ and JS.
294
+
292
295
--ignore-dynamic-linking Normally emcc will treat dynamic linking like
293
296
static linking, by linking in the code from
294
297
the dynamic library. This fails if the same
@@ -413,6 +416,8 @@ STATICLIB_SUFFIXES = ('.a',)
413
416
ASSEMBLY_SUFFIXES = ('.ll' ,)
414
417
LIB_PREFIXES = ('' , 'lib' )
415
418
419
+ JS_CONTAINING_SUFFIXES = ('js' , 'html' )
420
+
416
421
seen_names = {}
417
422
def uniquename (name ):
418
423
if name not in seen_names :
500
505
shell_path = shared .path_from_root ('src' , 'shell.html' )
501
506
js_libraries = []
502
507
remove_duplicates = False
508
+ bind = False
503
509
504
510
def check_bad_eq (arg ):
505
511
assert '=' not in arg , 'Invalid parameter (do not use "=" with "--" options)'
558
564
split_js_file = int (newargs [i + 1 ])
559
565
newargs [i ] = ''
560
566
newargs [i + 1 ] = ''
567
+ elif newargs [i ] == '--bind' :
568
+ bind = True
569
+ newargs [i ] = '-std=c++11' # Force C++11 for embind code
561
570
elif newargs [i ].startswith ('--embed-file' ):
562
571
check_bad_eq (newargs [i ])
563
572
embed_files .append (newargs [i + 1 ])
@@ -730,6 +739,10 @@ try:
730
739
731
740
assert not (Compression .on and final_suffix != 'html' ), 'Compression only works when generating HTML'
732
741
742
+ # If we are using embind and generating JS, now is the time to link in bind.cpp
743
+ if bind and final_suffix in JS_CONTAINING_SUFFIXES :
744
+ input_files .append (shared .path_from_root ('system' , 'lib' , 'embind' , 'bind.cpp' ))
745
+
733
746
# Apply optimization level settings
734
747
shared .Settings .apply_opt_level (opt_level , noisy = True )
735
748
779
792
if not LEAVE_INPUTS_RAW : assert len (temp_files ) == len (input_files )
780
793
781
794
# If we were just asked to generate bitcode, stop there
782
- if final_suffix not in [ 'js' , 'html' ] :
795
+ if final_suffix not in JS_CONTAINING_SUFFIXES :
783
796
if llvm_opts > 0 :
784
797
print >> sys .stderr , 'emcc: warning: -Ox flags ignored, since not generating JavaScript'
785
798
if not specified_target :
957
970
if Compression .on :
958
971
file_args += ['--compress' , Compression .encoder , Compression .decoder , Compression .js_name ]
959
972
code = execute (shared .ENV_PREFIX + ['python' , shared .FILE_PACKAGER , unsuffixed (target ) + '.data' ] + file_args , stdout = PIPE )[0 ]
960
- src = open (final ).read ().replace ('// {{PRE_RUN_ADDITIONS}}' , code )
973
+ src = open (final ).read ().replace ('// {{PRE_RUN_ADDITIONS}}' , '// {{PRE_RUN_ADDITIONS}} \n ' + code )
961
974
final += '.files.js'
962
975
open (final , 'w' ).write (src )
963
976
if DEBUG : save_intermediate ('files' )
@@ -970,6 +983,14 @@ try:
970
983
open (final , 'w' ).write (pre_js + src + post_js )
971
984
if DEBUG : save_intermediate ('pre-post' )
972
985
986
+ # Add bindings glue if used
987
+ if bind :
988
+ if DEBUG : print >> sys .stderr , 'emcc: adding embind glue'
989
+ src = open (final ).read ().replace ('// {{PRE_RUN_ADDITIONS}}' , '// {{PRE_RUN_ADDITIONS}}\n ' + open (shared .path_from_root ('src' , 'embind' , 'embind.js' )).read ())
990
+ final += '.bd.js'
991
+ open (final , 'w' ).write (src )
992
+ if DEBUG : save_intermediate ('bind' )
993
+
973
994
# Apply a source code transformation, if requested
974
995
if js_transform :
975
996
shutil .copyfile (final , final + '.tr.js' )
0 commit comments