diff options
-rw-r--r-- | demos/scons-embind/SConstruct | 23 | ||||
-rw-r--r-- | demos/scons-embind/bar.cpp | 2 | ||||
-rw-r--r-- | demos/scons-embind/foo.cpp | 11 | ||||
-rw-r--r-- | demos/scons-embind/test.js | 2 | ||||
-rwxr-xr-x | scons-tools/emscripten.py | 15 | ||||
-rwxr-xr-x | scons-tools/llvm.py | 13 |
6 files changed, 53 insertions, 13 deletions
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/scons-tools/emscripten.py b/scons-tools/emscripten.py index cdf960ac..473c51ad 100755 --- a/scons-tools/emscripten.py +++ b/scons-tools/emscripten.py @@ -41,6 +41,7 @@ def build_version_file(env): '$EMSCRIPTEN_VERSION_FILE',
EMSCRIPTEN_DEPENDENCIES,
touch_file)
+
env.AddPostAction(
emscripten_version_file,
Delete(env.Dir('$EMSCRIPTEN_TEMP_DIR').abspath))
@@ -260,24 +261,18 @@ def generate(env): JS_OPTIMIZER_PASSES=[],
LLVM_OPT_PASSES=['-std-compile-opts', '-std-link-opts'],
- # todo: calculate from __file__
- EMSCRIPTEN_HOME=env.Dir('#/third-party/emscripten'),
+ EMSCRIPTEN_HOME=env.Dir(os.path.join(os.path.dirname(__file__), '..')),
)
env.Replace(
- CC='${LLVM_ROOT}/clang',
- CXX='${LLVM_ROOT}/clang++',
- AR='${LLVM_ROOT}/llvm-link',
+ CC='${LLVM_ROOT}/${CLANG}',
+ CXX='${LLVM_ROOT}/${CLANGXX}',
+ AR='${LLVM_ROOT}/${LLVM_LINK}',
ARCOM='$AR -o $TARGET $SOURCES',
OBJSUFFIX='.bc',
LIBPREFIX='',
LIBSUFFIX='.bc',
RANLIBCOM='',
- # todo: remove
- _LIBFLAGS='',
- _LIBDIRFLAGS='',
- # comment this out:
- LINK=os.path.join('${LLVM_ROOT}', 'llvm-link'),
CCFLAGS=[
'-U__STRICT_ANSI__',
'-target', 'le32-unknown-nacl',
diff --git a/scons-tools/llvm.py b/scons-tools/llvm.py index 2e03caa3..f272bd16 100755 --- a/scons-tools/llvm.py +++ b/scons-tools/llvm.py @@ -15,12 +15,19 @@ def add_libraries(target, source, env): return (target, source + unique) def generate(env): + env.SetDefault( + CLANG='clang', + CLANGXX='clang++', + LLVM_DIS='llvm-dis', + LLVM_OPT='opt', + LLVM_LINK='llvm-link') + env['BUILDERS']['LLVMDis'] = Builder( - action='${LLVM_ROOT}/llvm-dis -o=$TARGET $SOURCE') + action='${LLVM_ROOT}/$LLVM_DIS -o=$TARGET $SOURCE') env['BUILDERS']['LLVMOpt'] = Builder( - action='${LLVM_ROOT}/opt $LLVM_OPT_FLAGS $LLVM_OPT_PASSES -o=$TARGET $SOURCE') + action='${LLVM_ROOT}/$LLVM_OPT $LLVM_OPT_FLAGS $LLVM_OPT_PASSES -o=$TARGET $SOURCE') env['BUILDERS']['LLVMLink'] = Builder( - action='${LLVM_ROOT}/llvm-link -o=$TARGET $SOURCES', + action='${LLVM_ROOT}/$LLVM_LINK -o=$TARGET $SOURCES', emitter=add_libraries) |