aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-12 15:40:12 -0500
committerAlon Zakai <alonzakai@gmail.com>2012-10-12 15:40:12 -0500
commit217dbc2b3f0f5eb483790ca6836fa58a09936030 (patch)
treea11dfe0419231d97dccffa799e0908da57e26a58
parent706cca7ca24a7578e24f890e7071bbec5726ec2d (diff)
embind integration in emcc and work towards a test
-rwxr-xr-xemcc25
-rw-r--r--src/embind/embind.js1
-rwxr-xr-xtests/runner.py14
3 files changed, 38 insertions, 2 deletions
diff --git a/emcc b/emcc
index 071db703..f3ecb21e 100755
--- a/emcc
+++ b/emcc
@@ -289,6 +289,9 @@ Options that are modified or new in %s include:
The main file resides in the base directory and
has the suffix ".js".
+ --bind Compiles the source code using the "embind"
+ bindings approach, which connects C/C++ and JS.
+
--ignore-dynamic-linking Normally emcc will treat dynamic linking like
static linking, by linking in the code from
the dynamic library. This fails if the same
@@ -413,6 +416,8 @@ STATICLIB_SUFFIXES = ('.a',)
ASSEMBLY_SUFFIXES = ('.ll',)
LIB_PREFIXES = ('', 'lib')
+JS_CONTAINING_SUFFIXES = ('js', 'html')
+
seen_names = {}
def uniquename(name):
if name not in seen_names:
@@ -500,6 +505,7 @@ try:
shell_path = shared.path_from_root('src', 'shell.html')
js_libraries = []
remove_duplicates = False
+ bind = False
def check_bad_eq(arg):
assert '=' not in arg, 'Invalid parameter (do not use "=" with "--" options)'
@@ -558,6 +564,9 @@ try:
split_js_file = int(newargs[i+1])
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i] == '--bind':
+ bind = True
+ newargs[i] = '-std=c++11' # Force C++11 for embind code
elif newargs[i].startswith('--embed-file'):
check_bad_eq(newargs[i])
embed_files.append(newargs[i+1])
@@ -730,6 +739,10 @@ try:
assert not (Compression.on and final_suffix != 'html'), 'Compression only works when generating HTML'
+ # If we are using embind and generating JS, now is the time to link in bind.cpp
+ if bind and final_suffix in JS_CONTAINING_SUFFIXES:
+ input_files.append(shared.path_from_root('system', 'lib', 'embind', 'bind.cpp'))
+
# Apply optimization level settings
shared.Settings.apply_opt_level(opt_level, noisy=True)
@@ -779,7 +792,7 @@ try:
if not LEAVE_INPUTS_RAW: assert len(temp_files) == len(input_files)
# If we were just asked to generate bitcode, stop there
- if final_suffix not in ['js', 'html']:
+ if final_suffix not in JS_CONTAINING_SUFFIXES:
if llvm_opts > 0:
print >> sys.stderr, 'emcc: warning: -Ox flags ignored, since not generating JavaScript'
if not specified_target:
@@ -957,7 +970,7 @@ try:
if Compression.on:
file_args += ['--compress', Compression.encoder, Compression.decoder, Compression.js_name]
code = execute(shared.ENV_PREFIX + ['python', shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0]
- src = open(final).read().replace('// {{PRE_RUN_ADDITIONS}}', code)
+ src = open(final).read().replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\n' + code)
final += '.files.js'
open(final, 'w').write(src)
if DEBUG: save_intermediate('files')
@@ -970,6 +983,14 @@ try:
open(final, 'w').write(pre_js + src + post_js)
if DEBUG: save_intermediate('pre-post')
+ # Add bindings glue if used
+ if bind:
+ if DEBUG: print >> sys.stderr, 'emcc: adding embind glue'
+ src = open(final).read().replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\n' + open(shared.path_from_root('src', 'embind', 'embind.js')).read())
+ final += '.bd.js'
+ open(final, 'w').write(src)
+ if DEBUG: save_intermediate('bind')
+
# Apply a source code transformation, if requested
if js_transform:
shutil.copyfile(final, final + '.tr.js')
diff --git a/src/embind/embind.js b/src/embind/embind.js
index fff19d86..d40d6ca2 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -617,3 +617,4 @@ function __embind_register_interface(
},
};
}
+
diff --git a/tests/runner.py b/tests/runner.py
index 7188fd13..869aeb68 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7695,6 +7695,20 @@ f.close()
output = run_js('scons_integration.js')
assert 'If you see this - the world is all right!' in output
+ def zzztest_embind(self):
+ # TODO: test -O1 and -O2
+ for args, fail in [
+ ([], True), # without --bind, we fail
+ (['--bind'], False)
+ ]:
+ print args, fail
+ try_delete(self.in_dir('a.out.js'))
+ Popen(['python', EMCC, path_from_root('tests', 'embind', 'embind_test.cpp'), '--post-js', path_from_root('tests', 'embind', 'embind_test.js')] + args, stderr=PIPE if fail else None).communicate()
+ assert os.path.exists(self.in_dir('a.out.js')) == (not fail)
+ if not fail:
+ output = run_js(self.in_dir('a.out.js'))
+ assert 'If you see this - the world is all right!' in output
+
def test_llvm_nativizer(self):
# avoid impure_ptr problems etc.
shutil.copyfile(path_from_root('tests', 'files.cpp'), os.path.join(self.get_dir(), 'files.cpp'))