aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc/link-rule.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-11-05 15:52:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-11-05 15:52:13 +0200
commit8671b4dc516994b7f070a341c004aab28e525431 (patch)
treeae44903ad4960ed5ace4bcb26401be5dd592ff4f /libbuild2/cc/link-rule.cxx
parentfb4272e816ad949811f9f8b709771c5aeb646d1f (diff)
Initial Emscripten support
- Target: wasm32-emscripten (wasm32-unknown-emscripten). - Compiler id: clang-emscripten (type clang, variant emscripten, class gcc). - Ability to build executables (.js plus .wasm) and static libraries (.a). Set executable bit on the .js file (so it can be executed with a suitable binfmt interpreter). - Default config.bin.lib for wasm32-emscripten is static instead of both. - Full C++ exception support is enable unless disabled explicitly by the user with -s DISABLE_EXCEPTION_CATCHING=1|2. - The bin module registers the wasm{} target type for wasm32-emscripten.
Diffstat (limited to 'libbuild2/cc/link-rule.cxx')
-rw-r--r--libbuild2/cc/link-rule.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx
index b0457e7..6acb1c7 100644
--- a/libbuild2/cc/link-rule.cxx
+++ b/libbuild2/cc/link-rule.cxx
@@ -953,6 +953,8 @@ namespace build2
{
if (tclass == "windows")
e = "exe";
+ else if (tsys == "emscripten")
+ e = "js";
else
e = "";
@@ -998,6 +1000,18 @@ namespace build2
}
}
+ // Add Emscripten .wasm.
+ //
+ if (ot == otype::e && tsys == "emscripten")
+ {
+ const target_type& tt (*bs.find_target_type ("wasm"));
+
+ file& wasm (add_adhoc_member<file> (t, tt));
+
+ if (wasm.path ().empty ())
+ wasm.derive_path ("wasm");
+ }
+
// Add VC's .pdb. Note that we are looking for the link.exe /DEBUG
// option.
//
@@ -2438,7 +2452,22 @@ namespace build2
}
if (ldc)
+ {
+ // See the compile rule for details. Note that here we don't really
+ // know whether it's a C++ executable so we may end up with some
+ // unnecessary overhead.
+ //
+ if (ctype == compiler_type::clang && cvariant == "emscripten")
+ {
+ if (!find_option_prefix ("DISABLE_EXCEPTION_CATCHING=", args))
+ {
+ args.push_back ("-s");
+ args.push_back ("DISABLE_EXCEPTION_CATCHING=0");
+ }
+ }
+
append_options (args, cmode);
+ }
// Extra system library dirs (last).
//
@@ -3244,6 +3273,21 @@ namespace build2
try_rmfile (relt + ".lib", true /* ignore_errors */);
try_rmfile (relt + ".exp", true /* ignore_errors */);
}
+
+ // Set executable bit on the .js file so that it can be run with a
+ // suitable binfmt interpreter (e.g., nodejs). See Emscripten issue
+ // 12707 for details.
+ //
+#ifndef _WIN32
+ if (lt.executable () && tsys == "emscripten")
+ {
+ path_perms (relt,
+ (path_perms (relt) |
+ permissions::xu |
+ permissions::xg |
+ permissions::xo));
+ }
+#endif
}
if (ranlib)