diff options
98 files changed, 22670 insertions, 1850 deletions
@@ -76,4 +76,13 @@ a license to everyone to use it as detailed in LICENSE.) * John Allwine <jallwine86@gmail.com> * Martin Gerhardy <martin.gerhardy@gmail.com> * James Gregory <jgregory@zynga.com> (copyright owned by Zynga, Inc) +* Dan Gohman <sunfish@google.com> (copyright owned by Google, Inc.) +* Jeff Gilbert <jgilbert@mozilla.com> (copyright owned by Mozilla Foundation) +* Frits Talbot <frits@metapathy.com> +* Onno Jongbloed <hey@onnoj.net> +* Jez Ng <me@jezng.com> +* Marc Feeley <mfeeley@mozilla.com> (copyright owned by Mozilla Foundation) * Ludovic Perrine <jazzzz@gmail.com> + + + diff --git a/demos/scons-embind/SConstruct b/demos/scons-embind/SConstruct new file mode 100644 index 00000000..8afc3e27 --- /dev/null +++ b/demos/scons-embind/SConstruct @@ -0,0 +1,23 @@ +env = Environment( + toolpath=['../../scons-tools'], + tools=['cc', 'c++', 'ar', 'emscripten', 'llvm', 'closure'], + LLVM_ROOT='/opt/local/bin', + CLANG='clang-mp-3.2', + CLANGXX='clang++-mp-3.2', + LLVM_LINK='llvm-link-mp-3.2', + LLVM_OPT='opt-mp-3.2', + LLVM_DIS='llvm-dis-mp-3.2', + EMSCRIPTEN_VERSION_FILE=File('build/version_file'), + EMSCRIPTEN_SETTINGS={ + 'ASM_JS': 0, + }) +env['BUILDERS']['WrapInModule'] = Builder( + action='cp $SOURCE $TARGET', +) + +env.Append() +a1 = env.Object('build/foo.bc', 'foo.cpp') +a2 = env.Object('build/bar.bc', 'bar.cpp') +total = env.LLVMLink('build/thelibrary.bc', [a1, a2]) + +env.emscripten('build/thelibrary.js', total) diff --git a/demos/scons-embind/bar.cpp b/demos/scons-embind/bar.cpp new file mode 100644 index 00000000..a3908014 --- /dev/null +++ b/demos/scons-embind/bar.cpp @@ -0,0 +1,2 @@ +void foo() { +} diff --git a/demos/scons-embind/foo.cpp b/demos/scons-embind/foo.cpp new file mode 100644 index 00000000..61be501a --- /dev/null +++ b/demos/scons-embind/foo.cpp @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <emscripten/bind.h> + +void print_some_stuff(int a, float b, const std::string& s) { + printf("print_some_stuff: %d, %f, %s\n", a, b, s.c_str()); +} + +EMSCRIPTEN_BINDINGS(foo) { + emscripten::function("print_some_stuff", &print_some_stuff); +} + diff --git a/demos/scons-embind/test.js b/demos/scons-embind/test.js new file mode 100644 index 00000000..a6252fd8 --- /dev/null +++ b/demos/scons-embind/test.js @@ -0,0 +1,2 @@ +var thelibrary = require('./build/thelibrary.js'); +thelibrary.Module.print_some_stuff(1, 2, 'hello world'); diff --git a/docs/splashpres.pdf b/docs/splashpres.pdf Binary files differnew file mode 100644 index 00000000..02fa4ea0 --- /dev/null +++ b/docs/splashpres.pdf @@ -28,34 +28,6 @@ Example uses: so it should relay everything to gcc/g++. You should not define that when running make, of course. - * With CMake, the same command will work (with cmake instead of ./configure). You may also be - able to do the following in your CMakeLists.txt: - - SET(CMAKE_C_COMPILER "PATH/emcc") - SET(CMAKE_CXX_COMPILER "PATH/em++") - SET(CMAKE_LINKER "PATH/emcc") - SET(CMAKE_CXX_LINKER "PATH/emcc") - SET(CMAKE_C_LINK_EXECUTABLE "PATH/emcc") - SET(CMAKE_CXX_LINK_EXECUTABLE "PATH/emcc") - SET(CMAKE_AR "PATH/emar") - SET(CMAKE_RANLIB "PATH/emranlib") - - * For SCons the shared.py can be imported like so: - __file__ = str(Dir('#/project_path_to_emscripten/dummy/dummy')) - __rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - def path_from_root(*pathelems): - return os.path.join(__rootpath__, *pathelems) - sys.path += [path_from_root('')] - from tools.shared import * - - For using the Emscripten compilers/linkers/etc. you can do: - env = Environment() - ... - env.Append(CCFLAGS = COMPILER_OPTS) - env.Replace(LINK = LLVM_LD) - env.Replace(LD = LLVM_LD) - TODO: Document all relevant setup changes - After setting that up, run your build system normally. Note the appearance of em++ instead of emcc @@ -138,7 +110,7 @@ while response_file: sys.argv[index:index+1] = extra_args break -if len(sys.argv) == 1 or sys.argv[1] == '--help': +if len(sys.argv) == 1 or '--help' in sys.argv: this = os.path.basename('em++' if os.environ.get('EMMAKEN_CXX') else 'emcc') print '''%s [options] file... @@ -567,7 +539,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG: skip_next = False idx += 1 continue - if el == '-s' and is_minus_s_for_emcc(argv, idx): + if not use_js and el == '-s' and is_minus_s_for_emcc(argv, idx): # skip -s X=Y if not using js for configure skip_next = True else: yield el @@ -629,7 +601,7 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += shlex.split(EMMAKEN_CFLAGS) # ---------------- Utilities --------------- -SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc') +SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc', '.m', '.mm') BITCODE_SUFFIXES = ('.bc', '.o', '.obj') DYNAMICLIB_SUFFIXES = ('.dylib', '.so', '.dll') STATICLIB_SUFFIXES = ('.a',) @@ -657,7 +629,7 @@ header = False # pre-compiled headers. We fake that by just copying the file for i in range(1, len(sys.argv)): arg = sys.argv[i] if not arg.startswith('-'): - if arg.endswith('.c'): + if arg.endswith(('.c','.m')): use_cxx = False if arg.endswith('.h') and sys.argv[i-1] != '-include': header = True @@ -932,6 +904,9 @@ try: prev = newargs[i-1] if prev in ['-MT', '-install_name', '-I', '-L']: continue # ignore this gcc-style argument + if (os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES)): + arg = os.path.realpath(arg) + if not arg.startswith('-') and (arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg)): # we already removed -o <target>, so all these should be inputs newargs[i] = '' if os.path.exists(arg): @@ -1019,7 +994,8 @@ try: for change in settings_changes: key, value = change.split('=') if value[0] == '@': - value = '"' + value + '"' + value = '"@' + os.path.abspath(value[1:]) + '"' + value = value.replace('\\\\', '/').replace('\\', '/') # Convert backslash paths to forward slashes on Windows as well, since the JS compiler otherwise needs the backslashes escaped (alternative is to escape all input paths passing to JS, which feels clumsier to read) exec('shared.Settings.' + key + ' = ' + value) # Apply effects from settings @@ -1027,8 +1003,7 @@ try: assert opt_level >= 1, 'asm.js requires -O1 or above' if bind: - shared.Settings.ASM_JS = 0 - logging.warning('disabling asm.js because it is not compatible with embind yet') + shared.Settings.RESERVED_FUNCTION_POINTERS = max(shared.Settings.RESERVED_FUNCTION_POINTERS, 10) if shared.Settings.CORRECT_SIGNS != 1: logging.warning('setting CORRECT_SIGNS to 1 for asm.js code generation') shared.Settings.CORRECT_SIGNS = 1 @@ -1047,8 +1022,6 @@ try: logging.warning('disabling closure because debug info was requested') closure = False - if jcache and not keep_js_debug: print >> sys.stderr, 'emcc: warning: it is recommended to run jcache with -g when compiling bitcode to JS' - if minify_whitespace is None: minify_whitespace = opt_level >= 2 and not keep_js_debug diff --git a/emscons b/emscons new file mode 100755 index 00000000..2666f18c --- /dev/null +++ b/emscons @@ -0,0 +1,20 @@ +#!/usr/bin/env python2 + +''' +Wrapping the scons invocation, EMSCRIPTEN_TOOL_PATH is set in the process +environment, and can be used to locate the emscripten SCons Tool. +Example: +# Load emscripten Tool +my_env = Environment(tools=['emscripten'], toolpath=[os.environ['EMSCRIPTEN_TOOL_PATH']]) +''' + +import os, subprocess, sys +from tools import shared + +tool_path = os.path.join(shared.path_from_root('tools'), 'scons', 'site_scons', 'site_tools', 'emscripten') + +env = os.environ.copy() +env[ 'EMSCRIPTEN_TOOL_PATH' ] = tool_path + +exit(subprocess.call(sys.argv[1:], env=env)) + diff --git a/sco |