aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc67
1 files changed, 53 insertions, 14 deletions
diff --git a/emcc b/emcc
index 1dc9b756..ae72039a 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
@@ -367,7 +370,7 @@ def is_minus_s_for_emcc(newargs,i):
CONFIGURE_CONFIG = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in sys.argv
CMAKE_CONFIG = 'CMakeFiles/cmTryCompileExec.dir' in ' '.join(sys.argv)# or 'CMakeCCompilerId' in ' '.join(sys.argv)
if CONFIGURE_CONFIG or CMAKE_CONFIG:
- compiler = shared.CLANG
+ compiler = os.environ.get('CONFIGURE_CC') or shared.CLANG # if CONFIGURE_CC is defined, use that. let's you use local gcc etc. if you need that
if not ('CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX')):
compiler = shared.to_cc(compiler)
def filter_emscripten_options(argv):
@@ -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)'
@@ -508,11 +514,15 @@ try:
for i in range(len(newargs)):
if newargs[i].startswith('-O'):
- try:
- opt_level = int(newargs[i][2])
- assert 0 <= opt_level <= 3
- except:
- raise Exception('Invalid optimization level: ' + newargs[i])
+ requested_level = newargs[i][2]
+ if requested_level == 's':
+ print >> sys.stderr, 'emcc: warning: -Os is ignored (use -O0, -O1, -O2)'
+ else:
+ try:
+ opt_level = int(requested_level)
+ assert 0 <= opt_level <= 3
+ except:
+ raise Exception('Invalid optimization level: ' + newargs[i])
newargs[i] = ''
elif newargs[i].startswith('--llvm-opts'):
check_bad_eq(newargs[i])
@@ -554,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])
@@ -629,7 +642,7 @@ try:
newargs = [ arg for arg in newargs if arg is not '' ]
if split_js_file:
- settings_changes.append("PRINT_SPLIT_FILE_MARKER=1")
+ settings_changes.append("PRINT_SPLIT_FILE_MARKER=1")
# Find input files
@@ -726,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)
@@ -775,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:
@@ -798,7 +815,8 @@ try:
extra_files_to_link = []
- if not LEAVE_INPUTS_RAW and not AUTODEBUG:
+ if not LEAVE_INPUTS_RAW and not AUTODEBUG and \
+ not shared.Settings.BUILD_AS_SHARED_LIB == 2: # shared lib 2 use the library in the parent
# Check if we need to include some libraries that we compile. (We implement libc ourselves in js, but
# compile a malloc implementation and stdlibc++.)
# Note that we assume a single symbol is enough to know if we have/do not have dlmalloc etc. If you
@@ -829,8 +847,13 @@ try:
# libcxx
def create_libcxx():
if DEBUG: print >> sys.stderr, 'emcc: building libcxx for cache'
- shared.Building.build_library('libcxx', shared.EMSCRIPTEN_TEMP_DIR, shared.EMSCRIPTEN_TEMP_DIR, ['libcxx.bc'], configure=None, copy_project=True, source_dir=shared.path_from_root('system', 'lib', 'libcxx'))
- return os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'libcxx', 'libcxx.bc')
+ os = []
+ for src in ['algorithm.cpp', 'condition_variable.cpp', 'future.cpp', 'iostream.cpp', 'memory.cpp', 'random.cpp', 'stdexcept.cpp', 'system_error.cpp', 'utility.cpp', 'bind.cpp', 'debug.cpp', 'hash.cpp', 'mutex.cpp', 'string.cpp', 'thread.cpp', 'valarray.cpp', 'chrono.cpp', 'exception.cpp', 'ios.cpp', 'locale.cpp', 'regex.cpp', 'strstream.cpp', 'typeinfo.cpp']:
+ o = in_temp(src + '.o')
+ execute(shared.ENV_PREFIX + ['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', src), '-o', o], stdout=stdout, stderr=stderr)
+ os.append(o)
+ shared.Building.link(os, in_temp('libcxx.bc'))
+ return in_temp('libcxx.bc')
def fix_libcxx():
assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++ with QUANTUM_SIZE == 1'
# libcxx might need corrections, so turn them all on. TODO: check which are actually needed
@@ -843,8 +866,13 @@ try:
# libcxxabi - just for dynamic_cast for now
def create_libcxxabi():
if DEBUG: print >> sys.stderr, 'emcc: building libcxxabi for cache'
- shared.Building.build_library('libcxxabi', shared.EMSCRIPTEN_TEMP_DIR, shared.EMSCRIPTEN_TEMP_DIR, ['libcxxabi.bc'], configure=None, copy_project=True, source_dir=shared.path_from_root('system', 'lib', 'libcxxabi'))
- return os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'libcxxabi', 'libcxxabi.bc')
+ os = []
+ for src in ['private_typeinfo.cpp']:
+ o = in_temp(src + '.o')
+ execute(shared.ENV_PREFIX + ['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxxabi', 'src', src), '-o', o], stdout=stdout, stderr=stderr)
+ os.append(o)
+ shared.Building.link(os, in_temp('libcxxabi.bc'))
+ return in_temp('libcxxabi.bc')
def fix_libcxxabi():
assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++abi with QUANTUM_SIZE == 1'
#print >> sys.stderr, 'emcc: info: using libcxxabi, this may need CORRECT_* options'
@@ -953,7 +981,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')
@@ -966,6 +994,17 @@ 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() +
+ open(shared.path_from_root('src', 'embind', 'emval.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')