about summary refs log tree commit diff
path: root/src/librustc_binaryen/lib.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-02-07 08:30:51 -0800
committerGitHub <noreply@github.com>2018-02-07 08:30:51 -0800
commitd2f7febe9330664041d8d7790aa497bd7f9b8d5c (patch)
tree6ce398e858635f23b0124c923fc70ca285c80b28 /src/librustc_binaryen/lib.rs
parent185f258801984637e508ea54ae211e6a62c02911 (diff)
parentcfe53c066646857a19046ebaf0cdc410c3d9f034 (diff)
downloadrust-d2f7febe9330664041d8d7790aa497bd7f9b8d5c.tar.gz
rust-d2f7febe9330664041d8d7790aa497bd7f9b8d5c.zip
Rollup merge of #47883 - yurydelendik:wasm-map, r=alexcrichton
Export wasm source map when debug information is enabled

We use binaryen's linker to produce a wasm file (via s2wasm). The wasm writer has capabilities to export source maps. The pilot support for source maps is added to Firefox.

The produced source map contains references to the original file, that might require additional source map file processing to include / package original files with it.

/cc @alexcrichton
Diffstat (limited to 'src/librustc_binaryen/lib.rs')
-rw-r--r--src/librustc_binaryen/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc_binaryen/lib.rs b/src/librustc_binaryen/lib.rs
index 6c7feb6a7a9..36174e11ba0 100644
--- a/src/librustc_binaryen/lib.rs
+++ b/src/librustc_binaryen/lib.rs
@@ -51,6 +51,15 @@ impl Module {
             slice::from_raw_parts(ptr, len)
         }
     }
+
+    /// Returns the data of the source map JSON.
+    pub fn source_map(&self) -> &[u8] {
+        unsafe {
+            let ptr = BinaryenRustModuleSourceMapPtr(self.ptr);
+            let len = BinaryenRustModuleSourceMapLen(self.ptr);
+            slice::from_raw_parts(ptr, len)
+        }
+    }
 }
 
 impl Drop for Module {
@@ -94,6 +103,15 @@ impl ModuleOptions {
         self
     }
 
+    /// Configures a `sourceMappingURL` custom section value for the module.
+    pub fn source_map_url(&mut self, url: &str) -> &mut Self {
+        let url = CString::new(url).unwrap();
+        unsafe {
+            BinaryenRustModuleOptionsSetSourceMapUrl(self.ptr, url.as_ptr());
+        }
+        self
+    }
+
     /// Configures how much stack is initially allocated for the module. 1MB is
     /// probably good enough for now.
     pub fn stack(&mut self, amt: u64) -> &mut Self {
@@ -130,6 +148,8 @@ extern {
         -> *mut BinaryenRustModule;
     fn BinaryenRustModulePtr(module: *const BinaryenRustModule) -> *const u8;
     fn BinaryenRustModuleLen(module: *const BinaryenRustModule) -> usize;
+    fn BinaryenRustModuleSourceMapPtr(module: *const BinaryenRustModule) -> *const u8;
+    fn BinaryenRustModuleSourceMapLen(module: *const BinaryenRustModule) -> usize;
     fn BinaryenRustModuleFree(module: *mut BinaryenRustModule);
 
     fn BinaryenRustModuleOptionsCreate()
@@ -138,6 +158,8 @@ extern {
                                              debuginfo: bool);
     fn BinaryenRustModuleOptionsSetStart(module: *mut BinaryenRustModuleOptions,
                                          start: *const libc::c_char);
+    fn BinaryenRustModuleOptionsSetSourceMapUrl(module: *mut BinaryenRustModuleOptions,
+                                                sourceMapUrl: *const libc::c_char);
     fn BinaryenRustModuleOptionsSetStackAllocation(
         module: *mut BinaryenRustModuleOptions,
         stack: u64,